Skip to content

Commit 2cf8a7f

Browse files
pd4d10addaleax
authored andcommitted
module: fix specifier resolution algorithm
Fixes: #30520 PR-URL: #30574 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Myles Borins <[email protected]>
1 parent 6c249c0 commit 2cf8a7f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

‎lib/internal/modules/run_main.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ function shouldUseESMLoader(mainPath){
2424
constuserLoader=getOptionValue('--experimental-loader');
2525
if(userLoader)
2626
returntrue;
27+
constesModuleSpecifierResolution=
28+
getOptionValue('--es-module-specifier-resolution');
29+
if(esModuleSpecifierResolution==='node')
30+
returntrue;
2731
// Determine the module format of the main
2832
if(mainPath&&mainPath.endsWith('.mjs'))
2933
returntrue;

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Flags: --es-module-specifier-resolution=node
22
import{mustNotCall}from'../common/index.mjs';
33
importassertfrom'assert';
4+
importpathfrom'path';
5+
import{spawn}from'child_process';
6+
import{fileURLToPath}from'url';
47

58
// commonJS index.js
69
importcommonjsfrom'../fixtures/es-module-specifiers/package-type-commonjs';
@@ -33,3 +36,22 @@ 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+
constmodulePath=path.join(
48+
fileURLToPath(import.meta.url),
49+
'../../fixtures/es-module-specifiers',
50+
item,
51+
);
52+
spawn(process.execPath,
53+
['--es-module-specifier-resolution=node',modulePath],
54+
{stdio: 'inherit'}).on('exit',(code)=>{
55+
assert.strictEqual(code,0);
56+
});
57+
});

0 commit comments

Comments
(0)