GeezerVison is showing github.com — module: experimental modules runMain separation · nodejs/node@5cd78ba
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js +13-14Lines changed: 13 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -504,19 +504,6 @@ Module._load = function(request, parent, isMain) { | 504 | 504 | debug('Module._load REQUEST %s parent: %s', request, parent.id); | 505 | 505 | } | 506 | 506 |
| 507 | | - if (experimentalModules && isMain) { | 508 | | - if (asyncESM === undefined) lazyLoadESM(); | 509 | | - asyncESM.loaderPromise.then((loader) => { | 510 | | - return loader.import(getURLFromFilePath(request).pathname); | 511 | | - }) | 512 | | - .catch((e) => { | 513 | | - decorateErrorStack(e); | 514 | | - console.error(e); | 515 | | - process.exit(1); | 516 | | - }); | 517 | | - return; | 518 | | - } | 519 | | - | 520 | 507 | var filename = Module._resolveFilename(request, parent, isMain); | 521 | 508 |
| 522 | 509 | var cachedModule = Module._cache[filename]; | @@ -741,7 +728,19 @@ if (experimentalModules) { | 741 | 728 | // bootstrap main module. | 742 | 729 | Module.runMain = function() { | 743 | 730 | // Load the main module--the command line argument. | 744 | | - Module._load(process.argv[1], null, true); | | 731 | + if (experimentalModules) { | | 732 | + if (asyncESM === undefined) lazyLoadESM(); | | 733 | + asyncESM.loaderPromise.then((loader) => { | | 734 | + return loader.import(getURLFromFilePath(process.argv[1]).pathname); | | 735 | + }) | | 736 | + .catch((e) => { | | 737 | + decorateErrorStack(e); | | 738 | + console.error(e); | | 739 | + process.exit(1); | | 740 | + }); | | 741 | + } else { | | 742 | + Module._load(process.argv[1], null, true); | | 743 | + } | 745 | 744 | // Handle any nextTicks added in the first tick of the program | 746 | 745 | process._tickCallback(); | 747 | 746 | }; | |
Collapse file Copy file name to clipboard +25-4Lines changed: 25 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -// Flags: --experimental-modules | 2 | 1 | 'use strict'; | 3 | | -require('../common'); | | 2 | + | | 3 | +const common = require('../common'); | | 4 | +const fixtures = require('../common/fixtures'); | | 5 | +const { spawn } = require('child_process'); | 4 | 6 | const assert = require('assert'); | 5 | | -exports.asdf = 'asdf'; | 6 | | -assert.strictEqual(require.main.exports.asdf, 'asdf'); | | 7 | + | | 8 | +const entry = fixtures.path('/es-modules/cjs.js'); | | 9 | + | | 10 | +const child = spawn(process.execPath, ['--experimental-modules', entry]); | | 11 | +let experimentalWarning = false; | | 12 | +let validatedExecution = false; | | 13 | +child.stderr.on('data', (data) => { | | 14 | + if (!experimentalWarning) { | | 15 | + experimentalWarning = true; | | 16 | + return; | | 17 | + } | | 18 | + throw new Error(data.toString()); | | 19 | +}); | | 20 | +child.stdout.on('data', (data) => { | | 21 | + assert.strictEqual(data.toString(), 'executed\n'); | | 22 | + validatedExecution = true; | | 23 | +}); | | 24 | +child.on('close', common.mustCall((code, stdout) => { | | 25 | + assert.strictEqual(validatedExecution, true); | | 26 | + assert.strictEqual(code, 0); | | 27 | +})); |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-esm-error-cache.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,7 @@ const assert = require('assert'); | 7 | 7 |
| 8 | 8 | common.crashOnUnhandledRejection(); | 9 | 9 |
| 10 | | -const file = '../../fixtures/syntax/bad_syntax.js'; | | 10 | +const file = '../fixtures/syntax/bad_syntax.js'; | 11 | 11 |
| 12 | 12 | let error; | 13 | 13 | (async () => { | |
Collapse file Copy file name to clipboard +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +// test we can use commonjs require | | 4 | +require('path'); | | 5 | +console.log('executed'); |
|