summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Bedford <guybedford@gmail.com>2017-10-26 21:52:00 +0200
committerMichaël Zasso <targos@protonmail.com>2017-10-28 13:25:40 +0200
commitcadc47fe076caa91bda6aa148e0b37be609781d7 (patch)
treef0ab70fe27d203b6f937333724a11a1ee2fdf033
parentd853758a227066ce4cf58d3d7577b9c513ff8c7c (diff)
downloadandroid-node-v8-cadc47fe076caa91bda6aa148e0b37be609781d7.tar.gz
android-node-v8-cadc47fe076caa91bda6aa148e0b37be609781d7.tar.bz2
android-node-v8-cadc47fe076caa91bda6aa148e0b37be609781d7.zip
module: fix extension lookups for top-level main
The reason is that absolute URLs do not go through extension and index checks. By switching to an absolute path, the resolver still applies extensions properly to the top-level main. PR-URL: https://github.com/nodejs/node/pull/16526 Fixes: https://github.com/nodejs/node/issues/16476 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
-rw-r--r--lib/module.js2
-rw-r--r--test/parallel/test-module-main-extension-lookup.js7
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/module.js b/lib/module.js
index 4c567ec2b9..921a57a814 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -436,7 +436,7 @@ Module._load = function(request, parent, isMain) {
ESMLoader.hook(hooks);
}
}
- await ESMLoader.import(getURLFromFilePath(request).href);
+ await ESMLoader.import(getURLFromFilePath(request).pathname);
})()
.catch((e) => {
console.error(e);
diff --git a/test/parallel/test-module-main-extension-lookup.js b/test/parallel/test-module-main-extension-lookup.js
new file mode 100644
index 0000000000..0a8cc47c77
--- /dev/null
+++ b/test/parallel/test-module-main-extension-lookup.js
@@ -0,0 +1,7 @@
+'use strict';
+require('../common');
+const { execFileSync } = require('child_process');
+
+const node = process.argv[0];
+
+execFileSync(node, ['--experimental-modules', 'test/es-module/test-esm-ok']);