summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Bedford <guybedford@gmail.com>2020-04-26 21:40:01 -0700
committerMichaƫl Zasso <targos@protonmail.com>2020-05-04 14:23:27 +0200
commit5eccf1e9adb60da962d43daacc4cd9311bb64aeb (patch)
treebe10f11dc97a27bfca05f20edfd6f0378f32f94d
parenta87d3710148c0d1128e5372a1a8b90edd174a65d (diff)
downloadnode-new-5eccf1e9adb60da962d43daacc4cd9311bb64aeb.tar.gz
module: no type module resolver side effects
PR-URL: https://github.com/nodejs/node/pull/33086 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
-rw-r--r--doc/api/esm.md7
-rw-r--r--lib/internal/modules/esm/resolve.js9
-rw-r--r--test/es-module/test-esm-type-main.mjs9
-rw-r--r--test/fixtures/node_modules/type-main/index.js1
-rw-r--r--test/fixtures/node_modules/type-main/package.json4
5 files changed, 15 insertions, 15 deletions
diff --git a/doc/api/esm.md b/doc/api/esm.md
index 49c467effb..5047600f98 100644
--- a/doc/api/esm.md
+++ b/doc/api/esm.md
@@ -1601,13 +1601,6 @@ The resolver can throw the following errors:
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
> _mainExport_, _""_).
> 1. Throw a _Package Path Not Exported_ error.
-> 1. If _pjson.main_ is a String, then
-> 1. Let _resolvedMain_ be the URL resolution of _packageURL_, "/", and
-> _pjson.main_.
-> 1. If the file at _resolvedMain_ exists, then
-> 1. Return _resolvedMain_.
-> 1. If _pjson.type_ is equal to _"module"_, then
-> 1. Throw a _Module Not Found_ error.
> 1. Let _legacyMainURL_ be the result applying the legacy
> **LOAD_AS_DIRECTORY** CommonJS resolver to _packageURL_, throwing a
> _Module Not Found_ error for no resolution.
diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js
index 5bb2f37e53..8b85825444 100644
--- a/lib/internal/modules/esm/resolve.js
+++ b/lib/internal/modules/esm/resolve.js
@@ -439,11 +439,6 @@ function packageMainResolve(packageJSONUrl, packageConfig, base, conditions) {
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(packageJSONUrl, '.');
}
- if (packageConfig.main !== undefined) {
- const resolved = new URL(packageConfig.main, packageJSONUrl);
- const path = fileURLToPath(resolved);
- if (tryStatSync(path).isFile()) return resolved;
- }
if (getOptionValue('--experimental-specifier-resolution') === 'node') {
if (packageConfig.main !== undefined) {
return finalizeResolution(
@@ -453,9 +448,7 @@ function packageMainResolve(packageJSONUrl, packageConfig, base, conditions) {
new URL('index', packageJSONUrl), base);
}
}
- if (packageConfig.type !== 'module') {
- return legacyMainResolve(packageJSONUrl, packageConfig);
- }
+ return legacyMainResolve(packageJSONUrl, packageConfig);
}
throw new ERR_MODULE_NOT_FOUND(
diff --git a/test/es-module/test-esm-type-main.mjs b/test/es-module/test-esm-type-main.mjs
new file mode 100644
index 0000000000..012cf4f35f
--- /dev/null
+++ b/test/es-module/test-esm-type-main.mjs
@@ -0,0 +1,9 @@
+import { mustNotCall } from '../common/index.mjs';
+import assert from 'assert';
+import { importFixture } from '../fixtures/pkgexports.mjs';
+
+(async () => {
+ const m = await importFixture('type-main');
+ assert.strictEqual(m.default, 'asdf');
+})()
+.catch(mustNotCall);
diff --git a/test/fixtures/node_modules/type-main/index.js b/test/fixtures/node_modules/type-main/index.js
new file mode 100644
index 0000000000..a4cb539643
--- /dev/null
+++ b/test/fixtures/node_modules/type-main/index.js
@@ -0,0 +1 @@
+export default 'asdf';
diff --git a/test/fixtures/node_modules/type-main/package.json b/test/fixtures/node_modules/type-main/package.json
new file mode 100644
index 0000000000..7665d7a803
--- /dev/null
+++ b/test/fixtures/node_modules/type-main/package.json
@@ -0,0 +1,4 @@
+{
+ "main": "index",
+ "type": "module"
+}