Skip to content

Commit 5d07f00

Browse files
committed
Test more node versions
1 parent c64510f commit 5d07f00

21 files changed

Lines changed: 108 additions & 86 deletions

.github/workflows/nodejs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
node-version: [12.x, 14.x, 16.x]
16+
node-version: ["12.10", "12.16", "12.x", "14.x", "16.x", "17.x"]
1717

1818
steps:
1919
- uses: actions/checkout@v2
@@ -29,7 +29,7 @@ jobs:
2929

3030
strategy:
3131
matrix:
32-
node-version: [12.x, 14.x, 16.x]
32+
node-version: ["12.10", "12.16", "12.x", "14.x", "16.x", "17.x"]
3333

3434
steps:
3535
- uses: actions/checkout@v2

lib/index.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { fork } = require('child_process');
22
const filewatcher = require('filewatcher');
3+
const { join } = require('path');
34
const semver = require('semver');
45
const { pathToFileURL } = require('url');
56

@@ -94,18 +95,24 @@ module.exports = function (
9495
const args = nodeArgs.slice();
9596

9697
args.push(`--require=${resolveMain(localPath('wrap'))}`);
97-
const loaderPath = semver.satisfies(process.version, '<16.12.0')
98-
? 'loader-legacy.mjs'
99-
: 'loader.mjs';
100-
const loader = pathToFileURL(resolveMain(localPath(loaderPath)));
98+
10199
if (semver.satisfies(process.version, '<12.17.0')) {
102100
args.push('--experimental-modules');
103101
}
104-
if (semver.satisfies(process.version, '<12.11.1')) {
105-
args.push(`--loader=${loader.href}`);
106-
} else {
107-
args.push(`--experimental-loader=${loader.href}`);
108-
}
102+
103+
const loaderName = semver.satisfies(process.version, '>=16.12.0')
104+
? 'load'
105+
: semver.satisfies(process.version, '>=12.11.1')
106+
? 'get-format'
107+
: 'resolve';
108+
109+
const loaderURL = pathToFileURL(resolveMain(localPath(join('loaders', `${loaderName}.mjs`))));
110+
111+
const experimentalPrefix = semver.satisfies(process.version, '>=12.11.1')
112+
? 'experimental-'
113+
: '';
114+
115+
args.push(`--${experimentalPrefix}loader=${loaderURL.href}`);
109116

110117
child = fork(script, scriptArgs, {
111118
cwd: process.cwd(),

lib/ipc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
const cmd = 'NODE_DEV';
22

3-
exports.send = m => {
4-
if (process.connected) process.send({ ...m, cmd });
5-
};
6-
73
exports.on = (src, prop, cb) => {
84
src.on('internalMessage', m => {
95
if (m.cmd === cmd && prop in m) cb(m);
@@ -15,3 +11,7 @@ exports.relay = src => {
1511
if (process.connected && m.cmd === cmd) process.send(m);
1612
});
1713
};
14+
15+
exports.send = m => {
16+
if (process.connected) process.send({ ...m, cmd });
17+
};

lib/ipc.mjs

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ import { send } from './ipc.mjs';
55
const require = createRequire(import.meta.url);
66

77
export async function getFormat(url, context, defaultGetFormat) {
8-
const getPackageType = require('get-package-type');
98
const filePath = fileURLToPath(url);
109

1110
send({ required: filePath });
11+
1212
try {
1313
return await defaultGetFormat(url, context, defaultGetFormat);
14-
} catch (err) {
15-
if (err.code === 'ERR_UNKNOWN_FILE_EXTENSION') {
16-
return { format: await getPackageType(filePath) };
17-
}
18-
throw err;
14+
} catch (error) {
15+
if (error.code !== 'ERR_UNKNOWN_FILE_EXTENSION') throw error;
16+
return require('get-package-type')(filePath).then(format => ({ format }));
1917
}
2018
}

lib/loaders/ipc.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const cmd = 'NODE_DEV';
2+
3+
export const send = m => {
4+
if (process.connected) process.send({ ...m, cmd });
5+
};

lib/loader.mjs renamed to lib/loaders/load.mjs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ import { send } from './ipc.mjs';
55
const require = createRequire(import.meta.url);
66

77
export async function load(url, context, defaultLoad) {
8-
const getPackageType = require('get-package-type');
98
const filePath = fileURLToPath(url);
109

1110
send({ required: filePath });
11+
1212
try {
1313
return await defaultLoad(url, context, defaultLoad);
14-
} catch (err) {
15-
if (err.code === 'ERR_UNKNOWN_FILE_EXTENSION') {
16-
return { format: await getPackageType(filePath), source: null };
17-
}
18-
throw err;
14+
} catch (error) {
15+
if (error.code !== 'ERR_UNKNOWN_FILE_EXTENSION') throw error;
16+
return require('get-package-type')(filePath).then(format => ({ format, source: null }));
1917
}
2018
}

lib/loaders/resolve.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { fileURLToPath } from 'url';
2+
import { send } from './ipc.mjs';
3+
4+
export function resolve(specifier, parentModule, defaultResolve) {
5+
const resolved = defaultResolve(specifier, parentModule);
6+
7+
if (parentModule) {
8+
send({ required: fileURLToPath(resolved.url) });
9+
}
10+
11+
return resolved;
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Source: https://github.com/nodejs/node/issues/30810#issue-533506790
2+
3+
module.exports = p => {
4+
const { emitWarning } = p;
5+
6+
p.emitWarning = (warning, ...args) => {
7+
if (args[0] === 'ExperimentalWarning') {
8+
return;
9+
}
10+
11+
if (args[0] && typeof args[0] === 'object' && args[0].type === 'ExperimentalWarning') {
12+
return;
13+
}
14+
15+
return emitWarning(warning, ...args);
16+
};
17+
};

lib/suppress-experimental.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)