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
This commit is contained in:
Nathan Whitaker 2024-07-15 12:11:09 -07:00 committed by GitHub
parent 29186d7e59
commit 04f9db5b22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 82 additions and 20 deletions

View file

@ -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(