From 998aeff3d428ab28351f03129023850abb0b5bbe Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 23 Feb 2023 09:48:29 -0500 Subject: [PATCH] feat(npm): support npm specifiers in remote modules without `--unstable` (#17889) Closes #17455 --- cli/proc_state.rs | 44 +++++++------------ cli/tests/integration/npm_tests.rs | 4 +- .../npm/remote_npm_specifier/main.out | 2 +- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 2070b14c67..3f360fd9c0 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -497,39 +497,27 @@ impl ProcState { let graph_data = self.graph_data.read(); let graph = &graph_data.graph; let maybe_resolved = match graph.get(&referrer) { - Some(Module::Esm(module)) => module - .dependencies - .get(specifier) - .map(|d| (&module.specifier, &d.maybe_code)), + Some(Module::Esm(module)) => { + module.dependencies.get(specifier).map(|d| &d.maybe_code) + } _ => None, }; match maybe_resolved { - Some((found_referrer, Resolution::Ok(resolved))) => { + Some(Resolution::Ok(resolved)) => { let specifier = &resolved.specifier; return match graph.get(specifier) { - Some(Module::Npm(module)) => { - if !self.options.unstable() - && matches!(found_referrer.scheme(), "http" | "https") - { - return Err(custom_error( - "NotSupported", - format!("importing npm specifiers in remote modules requires the --unstable flag (referrer: {found_referrer})"), - )); - } - - self - .handle_node_resolve_result(node::node_resolve_npm_reference( - &module.nv_reference, - NodeResolutionMode::Execution, - &self.npm_resolver, - permissions, - )) - .with_context(|| { - format!("Could not resolve '{}'.", module.nv_reference) - }) - } + Some(Module::Npm(module)) => self + .handle_node_resolve_result(node::node_resolve_npm_reference( + &module.nv_reference, + NodeResolutionMode::Execution, + &self.npm_resolver, + permissions, + )) + .with_context(|| { + format!("Could not resolve '{}'.", module.nv_reference) + }), Some(Module::Node(module)) => { node::resolve_builtin_node_module(&module.module_name) } @@ -539,13 +527,13 @@ impl ProcState { None => Ok(specifier.clone()), }; } - Some((_, Resolution::Err(err))) => { + Some(Resolution::Err(err)) => { return Err(custom_error( "TypeError", format!("{}\n", err.to_string_with_range()), )) } - Some((_, Resolution::None)) | None => {} + Some(Resolution::None) | None => {} } } diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index 2ece84c5db..54053710e9 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -217,11 +217,11 @@ itest!(sub_paths { }); itest!(remote_npm_specifier { - args: "run --quiet npm/remote_npm_specifier/main.ts", + args: "run --quiet -A npm/remote_npm_specifier/main.ts", output: "npm/remote_npm_specifier/main.out", envs: env_vars_for_npm_tests(), http_server: true, - exit_code: 1, + exit_code: 0, }); itest!(tarball_with_global_header { diff --git a/cli/tests/testdata/npm/remote_npm_specifier/main.out b/cli/tests/testdata/npm/remote_npm_specifier/main.out index 0cb08b7bc3..9daeafb986 100644 --- a/cli/tests/testdata/npm/remote_npm_specifier/main.out +++ b/cli/tests/testdata/npm/remote_npm_specifier/main.out @@ -1 +1 @@ -error: importing npm specifiers in remote modules requires the --unstable flag (referrer: http://localhost:4545/npm/remote_npm_specifier/remote.ts) +test