diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-04-17 23:21:25 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-04-22 17:30:09 +0800 |
commit | 7c816b7588f0e2910bcef5db48f71296cd3b67c2 (patch) | |
tree | 3790a650c6b582fb6be11946e1c63d538351b1ff /lib/internal/main/check_syntax.js | |
parent | 528d100394ab45dd62141e010e53722accd5826d (diff) | |
download | android-node-v8-7c816b7588f0e2910bcef5db48f71296cd3b67c2.tar.gz android-node-v8-7c816b7588f0e2910bcef5db48f71296cd3b67c2.tar.bz2 android-node-v8-7c816b7588f0e2910bcef5db48f71296cd3b67c2.zip |
module: explicitly initialize CJS loader
Explicitly initialize the CJS loader with `module._initPaths()`
instead of making it a side-effect of requiring
`internal/modules/cjs/loader` - that makes it harder to reason about
when it's safe to load `internal/modules/cjs/loader`.
PR-URL: https://github.com/nodejs/node/pull/27313
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/internal/main/check_syntax.js')
-rw-r--r-- | lib/internal/main/check_syntax.js | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/lib/internal/main/check_syntax.js b/lib/internal/main/check_syntax.js index 6d335565ab..8b7a85e29d 100644 --- a/lib/internal/main/check_syntax.js +++ b/lib/internal/main/check_syntax.js @@ -18,6 +18,11 @@ const { stripShebang, stripBOM } = require('internal/modules/cjs/helpers'); +const { + _resolveFilename: resolveCJSModuleName, + wrap: wrapCJSModule +} = require('internal/modules/cjs/loader'); + // TODO(joyeecheung): not every one of these are necessary prepareMainThreadExecution(true); @@ -26,12 +31,8 @@ if (process.argv[1] && process.argv[1] !== '-') { const path = require('path'); process.argv[1] = path.resolve(process.argv[1]); - // This has to be done after prepareMainThreadExecution because it - // relies on process.execPath - const CJSModule = require('internal/modules/cjs/loader'); - // Read the source. - const filename = CJSModule._resolveFilename(process.argv[1]); + const filename = resolveCJSModuleName(process.argv[1]); const fs = require('fs'); const source = fs.readFileSync(filename, 'utf-8'); @@ -51,10 +52,6 @@ function checkSyntax(source, filename) { // Remove Shebang. source = stripShebang(source); - // This has to be done after prepareMainThreadExecution because it - // relies on process.execPath - const CJSModule = require('internal/modules/cjs/loader'); - const { getOptionValue } = require('internal/options'); const experimentalModules = getOptionValue('--experimental-modules'); if (experimentalModules) { @@ -76,7 +73,7 @@ function checkSyntax(source, filename) { // Remove BOM. source = stripBOM(source); // Wrap it. - source = CJSModule.wrap(source); + source = wrapCJSModule(source); // Compile the script, this will throw if it fails. new vm.Script(source, { displayErrors: true, filename }); } |