diff options
author | Guy Bedford <guybedford@gmail.com> | 2019-12-20 00:25:52 +0300 |
---|---|---|
committer | Guy Bedford <guybedford@gmail.com> | 2020-02-03 19:31:02 +0300 |
commit | 0f96dc266fd0cd8c1baa82ce7eb951c11b29a331 (patch) | |
tree | 3d6e098f15c59f924e5a4b645683ec340accbef9 /src/module_wrap.cc | |
parent | 875a4d1a58d6dec80518c9d2a05ae6107c70b066 (diff) |
esm: import.meta.resolve with nodejs: builtins
PR-URL: https://github.com/nodejs/node/pull/31032
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'src/module_wrap.cc')
-rw-r--r-- | src/module_wrap.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 2368279d8e6..30a2bf96366 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -836,6 +836,10 @@ Maybe<URL> FinalizeResolution(Environment* env, return Nothing<URL>(); } + if (resolved.path().back() == '/') { + return Just(resolved); + } + const std::string& path = resolved.ToFilePath(); if (CheckDescriptorAtPath(path) != FILE) { std::string msg = "Cannot find module " + @@ -1221,7 +1225,9 @@ Maybe<URL> ResolveSelf(Environment* env, } if (!found_pjson || pcfg->name != pkg_name) return Nothing<URL>(); if (pcfg->exports.IsEmpty()) return Nothing<URL>(); - if (!pkg_subpath.length()) { + if (pkg_subpath == "./") { + return Just(URL("./", pjson_url)); + } else if (!pkg_subpath.length()) { return PackageMainResolve(env, pjson_url, *pcfg, base); } else { return PackageExportsResolve(env, pjson_url, pkg_subpath, *pcfg, base); @@ -1265,8 +1271,7 @@ Maybe<URL> PackageResolve(Environment* env, return Nothing<URL>(); } std::string pkg_subpath; - if ((sep_index == std::string::npos || - sep_index == specifier.length() - 1)) { + if (sep_index == std::string::npos) { pkg_subpath = ""; } else { pkg_subpath = "." + specifier.substr(sep_index); @@ -1297,7 +1302,9 @@ Maybe<URL> PackageResolve(Environment* env, Maybe<const PackageConfig*> pcfg = GetPackageConfig(env, pjson_path, base); // Invalid package configuration error. if (pcfg.IsNothing()) return Nothing<URL>(); - if (!pkg_subpath.length()) { + if (pkg_subpath == "./") { + return Just(URL("./", pjson_url)); + } else if (!pkg_subpath.length()) { return PackageMainResolve(env, pjson_url, *pcfg.FromJust(), base); } else { if (!pcfg.FromJust()->exports.IsEmpty()) { |