Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9696e9e

Browse filesBrowse files
pd4d10MylesBorins
authored andcommitted
module: fix specifier resolution algorithm
Fixes: #30520 PR-URL: #30574 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
1 parent c6b6e3f commit 9696e9e
Copy full SHA for 9696e9e

File tree

Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-0
lines changed
Open diff view settings
Collapse file

‎lib/internal/bootstrap/pre_execution.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/pre_execution.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ function shouldUseESMLoader(mainPath) {
462462
const userLoader = getOptionValue('--experimental-loader');
463463
if (userLoader)
464464
return true;
465+
const experimentalSpecifierResolution =
466+
getOptionValue('--experimental-specifier-resolution');
467+
if (experimentalSpecifierResolution === 'node')
468+
return true;
465469
// Determine the module format of the main
466470
if (mainPath && mainPath.endsWith('.mjs'))
467471
return true;
Collapse file

‎test/es-module/test-esm-specifiers.mjs‎

Copy file name to clipboardExpand all lines: test/es-module/test-esm-specifiers.mjs
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Flags: --experimental-modules --experimental-specifier-resolution=node
22
import { mustNotCall } from '../common/index.mjs';
33
import assert from 'assert';
4+
import path from 'path';
5+
import { spawn } from 'child_process';
6+
import { fileURLToPath } from 'url';
47

58
// commonJS index.js
69
import commonjs from '../fixtures/es-module-specifiers/package-type-commonjs';
@@ -33,3 +36,24 @@ async function main() {
3336
}
3437

3538
main().catch(mustNotCall);
39+
40+
// Test path from command line arguments
41+
[
42+
'package-type-commonjs',
43+
'package-type-module',
44+
'/',
45+
'/index',
46+
].forEach((item) => {
47+
const modulePath = path.join(
48+
fileURLToPath(import.meta.url),
49+
'../../fixtures/es-module-specifiers',
50+
item,
51+
);
52+
spawn(process.execPath, [
53+
'--experimental-modules',
54+
'--es-module-specifier-resolution=node',
55+
modulePath
56+
], { stdio: 'inherit' }).on('exit', (code) => {
57+
assert.strictEqual(code, 0);
58+
});
59+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.