esm: modify resolution order for specifier flag
Currently `--es-module-specifier-resolution=node` has an alternative resolution order than the default in common.js, this causes inconsistencies. As discussed in @nodejs/modules we want to preserve resolution order between implementations. PR-URL: https://github.com/nodejs/node/pull/29974 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
a6b030d5ac
commit
1e5ed9a5db
@ -9,6 +9,8 @@ const { getOptionValue } = require('internal/options');
|
||||
const preserveSymlinks = getOptionValue('--preserve-symlinks');
|
||||
const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main');
|
||||
const experimentalJsonModules = getOptionValue('--experimental-json-modules');
|
||||
const esModuleSpecifierResolution =
|
||||
getOptionValue('--es-module-specifier-resolution');
|
||||
const typeFlag = getOptionValue('--input-type');
|
||||
const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
|
||||
const { resolve: moduleWrapResolve,
|
||||
@ -110,6 +112,8 @@ function resolve(specifier, parentURL) {
|
||||
if (!format) {
|
||||
if (isMain)
|
||||
format = type === TYPE_MODULE ? 'module' : 'commonjs';
|
||||
else if (esModuleSpecifierResolution === 'node')
|
||||
format = 'commonjs';
|
||||
else
|
||||
throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url));
|
||||
}
|
||||
|
@ -48,11 +48,10 @@ using v8::Undefined;
|
||||
using v8::Value;
|
||||
|
||||
static const char* const EXTENSIONS[] = {
|
||||
".mjs",
|
||||
".cjs",
|
||||
".js",
|
||||
".json",
|
||||
".node"
|
||||
".node",
|
||||
".mjs"
|
||||
};
|
||||
|
||||
ModuleWrap::ModuleWrap(Environment* env,
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Flags: --experimental-modules --es-module-specifier-resolution=node
|
||||
import { mustNotCall } from '../common';
|
||||
import { mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'assert';
|
||||
|
||||
// commonJS index.js
|
||||
@ -14,8 +14,8 @@ assert.strictEqual(commonjs, 'commonjs');
|
||||
assert.strictEqual(module, 'module');
|
||||
assert.strictEqual(success, 'success');
|
||||
assert.strictEqual(explicit, 'esm');
|
||||
assert.strictEqual(implicit, 'esm');
|
||||
assert.strictEqual(implicitModule, 'esm');
|
||||
assert.strictEqual(implicit, 'cjs');
|
||||
assert.strictEqual(implicitModule, 'cjs');
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
|
2
test/fixtures/es-module-specifiers/node_modules/implicit-main-type-module/entry.js
generated
vendored
2
test/fixtures/es-module-specifiers/node_modules/implicit-main-type-module/entry.js
generated
vendored
@ -1 +1 @@
|
||||
export default 'nope';
|
||||
export default 'cjs';
|
||||
|
Loading…
x
Reference in New Issue
Block a user