1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(npm): disable npm specifiers in import.meta.resolve() (#16599)

This commit is contained in:
Bartek Iwańczuk 2022-11-11 18:20:13 +01:00 committed by GitHub
parent 8dc242f789
commit 06bd9e9e16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View file

@ -7,3 +7,5 @@ Resolving without a value from import map https://example.com/PASS-undefined
Resolving 1 from import map https://example.com/PASS-1
Resolving null from import map https://example.com/PASS-null
Resolving object from import map https://example.com/PASS-object
TypeError: "npm:" specifiers are currently not supported in import.meta.resolve()
at file:///[WILDCARD]testdata/run/import_meta/main.ts:36:15

View file

@ -32,3 +32,8 @@ assertThrows(() => {
assertThrows(() => {
import.meta.resolve("://malformed/url?asdf");
}, TypeError);
try {
import.meta.resolve("npm:cowsay");
} catch (e) {
console.log(e);
}

View file

@ -363,8 +363,14 @@ fn import_meta_resolve(
let module_map = module_map_rc.borrow();
module_map.loader.clone()
};
match loader.resolve(&specifier.to_rust_string_lossy(scope), &referrer, false)
{
let specifier_str = specifier.to_rust_string_lossy(scope);
if specifier_str.starts_with("npm:") {
throw_type_error(scope, "\"npm:\" specifiers are currently not supported in import.meta.resolve()");
return;
}
match loader.resolve(&specifier_str, &referrer, false) {
Ok(resolved) => {
let resolved_val = serde_v8::to_v8(scope, resolved.as_str()).unwrap();
rv.set(resolved_val);