mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
module: fix specifier resolution algorithm
Fixes: https://github.com/nodejs/node/issues/30520 PR-URL: https://github.com/nodejs/node/pull/30574 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
This commit is contained in:
committed by
Rich Trott
parent
4d73fd3948
commit
f5ef7cd222
@@ -24,6 +24,10 @@ function shouldUseESMLoader(mainPath) {
|
||||
const userLoader = getOptionValue('--experimental-loader');
|
||||
if (userLoader)
|
||||
return true;
|
||||
const esModuleSpecifierResolution =
|
||||
getOptionValue('--es-module-specifier-resolution');
|
||||
if (esModuleSpecifierResolution === 'node')
|
||||
return true;
|
||||
// Determine the module format of the main
|
||||
if (mainPath && mainPath.endsWith('.mjs'))
|
||||
return true;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
// Flags: --es-module-specifier-resolution=node
|
||||
import { mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'assert';
|
||||
import path from 'path';
|
||||
import { spawn } from 'child_process';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
// commonJS index.js
|
||||
import commonjs from '../fixtures/es-module-specifiers/package-type-commonjs';
|
||||
@@ -33,3 +36,22 @@ async function main() {
|
||||
}
|
||||
|
||||
main().catch(mustNotCall);
|
||||
|
||||
// Test path from command line arguments
|
||||
[
|
||||
'package-type-commonjs',
|
||||
'package-type-module',
|
||||
'/',
|
||||
'/index',
|
||||
].forEach((item) => {
|
||||
const modulePath = path.join(
|
||||
fileURLToPath(import.meta.url),
|
||||
'../../fixtures/es-module-specifiers',
|
||||
item,
|
||||
);
|
||||
spawn(process.execPath,
|
||||
['--es-module-specifier-resolution=node', modulePath],
|
||||
{ stdio: 'inherit' }).on('exit', (code) => {
|
||||
assert.strictEqual(code, 0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user