summaryrefslogtreecommitdiff
path: root/src/module_wrap.cc
diff options
context:
space:
mode:
authorGuy Bedford <guybedford@gmail.com>2017-10-11 15:45:21 +0200
committerMichaël Zasso <targos@protonmail.com>2017-10-21 10:45:40 -0700
commitfe4675b301f0e3e26dcb88ef9f68fe35403330a0 (patch)
tree5857d5b4f56dc297dc5865fd311c5307ac80695a /src/module_wrap.cc
parentc4c63812822fc973cb3d4bb4040729213dcaa620 (diff)
downloadandroid-node-v8-fe4675b301f0e3e26dcb88ef9f68fe35403330a0.tar.gz
android-node-v8-fe4675b301f0e3e26dcb88ef9f68fe35403330a0.tar.bz2
android-node-v8-fe4675b301f0e3e26dcb88ef9f68fe35403330a0.zip
module: fix main resolution and not found updates
This simplifies the top-level load when ES modules are enabled as we can entirely delegate the module resolver, which will hand over to CommonJS where appropriate. All not found errors are made consistent to throw during resolve and have the MODULE_NOT_FOUND code. Includes the test case from https://github.com/nodejs/node/pull/15736. Fixes: https://github.com/nodejs/node/issues/15732 PR-URL: https://github.com/nodejs/node/pull/16147 Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/module_wrap.cc')
-rw-r--r--src/module_wrap.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/module_wrap.cc b/src/module_wrap.cc
index 829248b681..bda760369e 100644
--- a/src/module_wrap.cc
+++ b/src/module_wrap.cc
@@ -442,6 +442,11 @@ URL resolve_directory(const URL& search, bool read_pkg_json) {
URL Resolve(std::string specifier, const URL* base, bool read_pkg_json) {
URL pure_url(specifier);
if (!(pure_url.flags() & URL_FLAGS_FAILED)) {
+ // just check existence, without altering
+ auto check = check_file(pure_url, true);
+ if (check.failed) {
+ return URL("");
+ }
return pure_url;
}
if (specifier.length() == 0) {
@@ -493,9 +498,8 @@ void ModuleWrap::Resolve(const FunctionCallbackInfo<Value>& args) {
URL result = node::loader::Resolve(*specifier_utf, &url, true);
if (result.flags() & URL_FLAGS_FAILED) {
- std::string msg = "module ";
+ std::string msg = "Cannot find module ";
msg += *specifier_utf;
- msg += " not found";
env->ThrowError(msg.c_str());
return;
}