Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Node 20 #303

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build: off

environment:
matrix:
- nodejs_version: '20'
- nodejs_version: '18'
- nodejs_version: '16'
- nodejs_version: '14'
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: ["14.x", "16.x", "18.x"]
node-version: ["14.x", "16.x", "18.x", "20.x"]

steps:
- uses: actions/checkout@v2
Expand All @@ -29,13 +29,15 @@ jobs:

strategy:
matrix:
node-version: ["14.x", "16.x", "18.x"]
node-version: ["14.x", "16.x", "18.x", "20.x"]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- if: matrix.node-version == '14.x'
run: npm install -g npm@9 # node 14 comes with npm 6, which has some known bugs with dependency resolution
- run: npm i
- run: npm test
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jobs:
script: npm run lint
language: node_js
node_js:
- 20
- 18
- 16
- 14
Expand Down
4 changes: 4 additions & 0 deletions lib/loaders/ipc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ const cmd = 'NODE_DEV';
export const send = m => {
if (process.connected) process.send({ ...m, cmd });
};

export const sendPort = (port, m) => {
if (port) port.postMessage({ ...m, cmd });
};
20 changes: 18 additions & 2 deletions lib/loaders/load.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { createRequire } from 'module';
import { fileURLToPath } from 'url';
import { send } from './ipc.mjs';
import { sendPort } from './ipc.mjs';

const require = createRequire(import.meta.url);

// Port used for communication between the loader and ESM modules
// https://nodejs.org/api/esm.html#globalpreload
let port;

export async function load(url, context, defaultLoad) {
const required = url.startsWith('file://') ? fileURLToPath(url) : url;

send({ required });
sendPort(port, { required });

try {
return await defaultLoad(url, context, defaultLoad);
Expand All @@ -19,3 +23,15 @@ export async function load(url, context, defaultLoad) {
});
}
}

export const globalPreload = (context) => {
// Store port
port = context.port;

// Inject code to forward loader events to the parent
return `
port.on('message', (m) => {
if (process.connected) process.send(m);
}).unref();
`;
};
1 change: 0 additions & 1 deletion test/fixture/experimental-specifier-resolution/index.mjs

This file was deleted.

7 changes: 0 additions & 7 deletions test/fixture/resolution.mjs

This file was deleted.

14 changes: 0 additions & 14 deletions test/spawn/esmodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@ const tap = require('tap');

const { spawn, touchFile } = require('../utils');

tap.test('Supports ECMAScript modules with experimental-specifier-resolution', t => {
spawn('--experimental-specifier-resolution=node resolution.mjs', out => {
if (out.match(/touch message.js/)) {
touchFile('message.js');
return out2 => {
if (out2.match(/Restarting/)) {
t.match(out2, /\[INFO\] \d{2}:\d{2}:\d{2} Restarting/);
return { exit: t.end.bind(t) };
}
};
}
});
});

tap.test('Supports ECMAScript modules', t => {
spawn('ecma-script-modules.mjs', out => {
if (out.match(/touch message.mjs/)) {
Expand Down