mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
lib: ensure --check flag works with --require
PR-URL: https://github.com/nodejs/node/pull/19600 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
parent
ae2b5bcb7c
commit
0876a0314d
@ -75,6 +75,10 @@ Identical to `-e` but prints the result.
|
||||
added:
|
||||
- v5.0.0
|
||||
- v4.2.0
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/19600
|
||||
description: The `--require` option is now supported when checking a file.
|
||||
-->
|
||||
|
||||
Syntax check the script without executing.
|
||||
|
@ -210,6 +210,12 @@
|
||||
|
||||
const CJSModule = NativeModule.require('internal/modules/cjs/loader');
|
||||
|
||||
perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END);
|
||||
perf.markMilestone(
|
||||
NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START);
|
||||
preloadModules();
|
||||
perf.markMilestone(
|
||||
NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END);
|
||||
// check if user passed `-c` or `--check` arguments to Node.
|
||||
if (process._syntax_check_only != null) {
|
||||
const fs = NativeModule.require('fs');
|
||||
@ -219,12 +225,6 @@
|
||||
checkScriptSyntax(source, filename);
|
||||
process.exit(0);
|
||||
}
|
||||
perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END);
|
||||
perf.markMilestone(
|
||||
NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START);
|
||||
preloadModules();
|
||||
perf.markMilestone(
|
||||
NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END);
|
||||
CJSModule.runMain();
|
||||
} else {
|
||||
perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START);
|
||||
|
1
test/fixtures/no-wrapper.js
vendored
Normal file
1
test/fixtures/no-wrapper.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
require('module').wrapper = ['', ''];
|
@ -140,3 +140,26 @@ syntaxArgs.forEach(function(args) {
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
// should work with -r flags
|
||||
['-c', '--check'].forEach(function(checkFlag) {
|
||||
['-r', '--require'].forEach(function(requireFlag) {
|
||||
const preloadFile = fixtures.path('no-wrapper.js');
|
||||
const file = fixtures.path('syntax', 'illegal_if_not_wrapped.js');
|
||||
const args = [requireFlag, preloadFile, checkFlag, file];
|
||||
const cmd = [node, ...args].join(' ');
|
||||
exec(cmd, common.mustCall((err, stdout, stderr) => {
|
||||
assert.strictEqual(err instanceof Error, true);
|
||||
assert.strictEqual(err.code, 1);
|
||||
|
||||
// no stdout should be produced
|
||||
assert.strictEqual(stdout, '');
|
||||
|
||||
// stderr should have a syntax error message
|
||||
assert(syntaxErrorRE.test(stderr), `${syntaxErrorRE} === ${stderr}`);
|
||||
|
||||
// stderr should include the filename
|
||||
assert(stderr.startsWith(file), `${stderr} starts with ${file}`);
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user