Skip to content

Commit 93e1948

Browse files
committed
Handle --no-warnings
1 parent 6d58dd1 commit 93e1948

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

lib/cli.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const resolvePath = p => resolve(process.cwd(), p);
1111

1212
const nodeAlias = { require: 'r' };
1313
const nodeBoolean = ['expose_gc', 'preserve-symlinks'];
14-
const nodeOptional = ['inspect', 'inspect-brk'];
14+
const nodeCustom = ['inspect', 'inspect-brk', 'no-warnings'];
1515
const nodeString = ['require'];
1616

1717
const nodeDevBoolean = ['clear', 'dedupe', 'fork', 'notify', 'poll', 'respawn', 'vm'];
@@ -44,10 +44,10 @@ const nodeArgsReducer =
4444
return out;
4545
};
4646

47-
const nodeOptionalFactory = args => arg => {
48-
const isNodeOptional = nodeOptional.includes(arg.substring(2));
49-
if (isNodeOptional) args.push(arg);
50-
return !isNodeOptional;
47+
const nodeCustomFactory = args => arg => {
48+
const isNodeCustom = nodeCustom.includes(arg.substring(2));
49+
if (isNodeCustom) args.push(arg);
50+
return !isNodeCustom;
5151
};
5252

5353
const unknownFactory = args => arg => {
@@ -56,8 +56,8 @@ const unknownFactory = args => arg => {
5656
};
5757

5858
module.exports = argv => {
59-
const nodeOptionalArgs = [];
60-
const args = argv.slice(2).filter(nodeOptionalFactory(nodeOptionalArgs));
59+
const nodeCustomArgs = [];
60+
const args = argv.slice(2).filter(nodeCustomFactory(nodeCustomArgs));
6161

6262
const unknownArgs = [];
6363
const unknown = unknownFactory(unknownArgs);
@@ -71,7 +71,7 @@ module.exports = argv => {
7171
const opts = minimist(args, { alias, boolean, default: getConfig(script) });
7272
const nodeArgs = [...nodeBoolean.map(argify), ...nodeString.map(argify), ...unknownArgs]
7373
.sort((a, b) => a.key - b.key)
74-
.reduce(nodeArgsReducer(opts), [...nodeOptionalArgs]);
74+
.reduce(nodeArgsReducer(opts), [...nodeCustomArgs]);
7575

7676
opts.ignore = arrayify(opts.ignore).map(resolvePath);
7777

lib/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,24 @@ module.exports = function (
9393
*/
9494
function start() {
9595
isPaused = false;
96-
const cmd = nodeArgs.concat(wrapper, script, scriptArgs);
96+
97+
const args = nodeArgs.slice();
9798

9899
if (extname(script) === '.mjs' || getPackageType.sync(script) === 'module') {
99100
if (semver.satisfies(process.version, '>=10 <12.11.1')) {
100101
const resolveLoader = resolveMain(localPath('resolve-loader.mjs'));
101-
cmd.unshift('--experimental-modules', `--loader=${resolveLoader}`);
102+
args.push('--experimental-modules', `--loader=${resolveLoader}`);
102103
} else if (semver.satisfies(process.version, '>=12.11.1')) {
103104
const loaderPath = semver.satisfies(process.version, '>=16.12.0')
104105
? 'load-loader.mjs'
105106
: 'get-source-loader.mjs';
106107
const experimentalLoader = resolveMain(localPath(loaderPath));
107-
cmd.unshift(`--experimental-loader=${experimentalLoader}`);
108+
args.push(`--experimental-loader=${experimentalLoader}`);
108109
}
109110
}
110111

112+
const cmd = args.concat(wrapper, script, scriptArgs);
113+
111114
child = fork(cmd[0], cmd.slice(1), {
112115
cwd: process.cwd(),
113116
env: process.env

test/cli.js

+7
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ tap.test('--inspect', t => {
200200
t.end();
201201
});
202202

203+
tap.test('--no-warnings', t => {
204+
const { nodeArgs } = cli(['node', 'bin/node-dev', '--no-warnings', 'test']);
205+
206+
t.same(nodeArgs, ['--no-warnings']);
207+
t.end();
208+
});
209+
203210
tap.test('--require source-map-support/register --require ts-node/register', t => {
204211
const { nodeArgs } = cli([
205212
'node',

test/spawn/esmodule.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const tap = require('tap');
44
const { spawn, touchFile } = require('../utils');
55

66
tap.test('Supports ECMAScript modules with experimental-specifier-resolution', t => {
7-
if (semver.satisfies(process.version, '<12.17')) return t.skip();
7+
if (semver.satisfies(process.version, '<12.17'))
8+
return t.skip('experimental-specifier-resolution requires node >= 12.17');
89
if (process.platform === 'win32') return t.skip('ESM support on windows is broken');
910

1011
spawn('--experimental-specifier-resolution=node resolution.mjs', out => {
@@ -51,3 +52,21 @@ tap.test('Supports ECMAScript module packages', t => {
5152
}
5253
});
5354
});
55+
56+
tap.test('We can hide the experimental warning by passing --no-warnings', t => {
57+
if (process.platform === 'win32') return t.skip('ESM support on windows is broken');
58+
59+
spawn('--no-warnings ecma-script-modules.mjs', out => {
60+
if (out.match(/ExperimentalWarning/)) return t.fail('Should not log an ExperimentalWarning');
61+
62+
if (out.match(/touch message.mjs/)) {
63+
touchFile('message.mjs');
64+
return out2 => {
65+
if (out2.match(/Restarting/)) {
66+
t.match(out2, /\[INFO\] \d{2}:\d{2}:\d{2} Restarting/);
67+
return { exit: t.end.bind(t) };
68+
}
69+
};
70+
}
71+
});
72+
});

0 commit comments

Comments
 (0)