From 04f9db5b2217fe06f88e76146aac6362ff0b0b86 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Mon, 15 Jul 2024 12:11:09 -0700 Subject: fix(node): Fix `--allow-scripts` with no `deno.json` (#24533) We would resolve the wrong package.json, resulting in an inability to run CJS (or other node-mode) scripts --- cli/npm/managed/mod.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'cli/npm/managed/mod.rs') diff --git a/cli/npm/managed/mod.rs b/cli/npm/managed/mod.rs index 1020a57e9..a18ad4d7f 100644 --- a/cli/npm/managed/mod.rs +++ b/cli/npm/managed/mod.rs @@ -518,22 +518,25 @@ impl ManagedCliNpmResolver { } } +fn npm_process_state( + snapshot: ValidSerializedNpmResolutionSnapshot, + node_modules_path: Option<&Path>, +) -> String { + serde_json::to_string(&NpmProcessState { + kind: NpmProcessStateKind::Snapshot(snapshot.into_serialized()), + local_node_modules_path: node_modules_path + .map(|p| p.to_string_lossy().to_string()), + }) + .unwrap() +} + impl NpmResolver for ManagedCliNpmResolver { /// Gets the state of npm for the process. fn get_npm_process_state(&self) -> String { - serde_json::to_string(&NpmProcessState { - kind: NpmProcessStateKind::Snapshot( - self - .resolution - .serialized_valid_snapshot() - .into_serialized(), - ), - local_node_modules_path: self - .fs_resolver - .node_modules_path() - .map(|p| p.to_string_lossy().to_string()), - }) - .unwrap() + npm_process_state( + self.resolution.serialized_valid_snapshot(), + self.fs_resolver.node_modules_path().map(|p| p.as_path()), + ) } fn resolve_package_folder_from_package( -- cgit v1.2.3