diff options
author | Guy Bedford <guybedford@gmail.com> | 2019-12-20 00:25:52 +0300 |
---|---|---|
committer | Shelley Vohr <shelley.vohr@gmail.com> | 2020-02-17 23:04:35 +0300 |
commit | f6392e9fde507db0b9cbb5dc00e5939135a22d64 (patch) | |
tree | 5cd07e906b8c7a4e4841fc8a9574c0fec5e83e86 /src/module_wrap.cc | |
parent | 8d3ffbeb55146633fee367820c39949b4e854c36 (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()) { |