diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-11-11 18:20:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-11 18:20:13 +0100 |
commit | 06bd9e9e1640150f98857a74fea0cc1a3b3386a7 (patch) | |
tree | 057b73df17d53ff26ca2d4333afce619dfcb7419 | |
parent | 8dc242f7891492886827a350b7736c11df7aa419 (diff) |
fix(npm): disable npm specifiers in import.meta.resolve() (#16599)
-rw-r--r-- | cli/tests/testdata/run/import_meta/main.out | 2 | ||||
-rw-r--r-- | cli/tests/testdata/run/import_meta/main.ts | 5 | ||||
-rw-r--r-- | core/bindings.rs | 10 |
3 files changed, 15 insertions, 2 deletions
diff --git a/cli/tests/testdata/run/import_meta/main.out b/cli/tests/testdata/run/import_meta/main.out index 89aeddaf3..1b51f1cdf 100644 --- a/cli/tests/testdata/run/import_meta/main.out +++ b/cli/tests/testdata/run/import_meta/main.out @@ -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 diff --git a/cli/tests/testdata/run/import_meta/main.ts b/cli/tests/testdata/run/import_meta/main.ts index 02f0a1c58..0d7cb96da 100644 --- a/cli/tests/testdata/run/import_meta/main.ts +++ b/cli/tests/testdata/run/import_meta/main.ts @@ -32,3 +32,8 @@ assertThrows(() => { assertThrows(() => { import.meta.resolve("://malformed/url?asdf"); }, TypeError); +try { + import.meta.resolve("npm:cowsay"); +} catch (e) { + console.log(e); +} diff --git a/core/bindings.rs b/core/bindings.rs index 82cce7102..a28618571 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -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); |