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

@ -164,7 +164,9 @@ impl ShellCommand for NpmCommand {
}
}
pub struct NodeCommand;
pub struct NodeCommand {
pub force_node_modules_dir: bool,
}
impl ShellCommand for NodeCommand {
fn execute(
@ -191,6 +193,9 @@ impl ShellCommand for NodeCommand {
.execute(context);
}
args.extend(["run", "-A"].into_iter().map(|s| s.to_string()));
if self.force_node_modules_dir {
args.push("--node-modules-dir=true".to_string());
}
args.extend(context.args.iter().cloned());
let mut state = context.state;
@ -303,6 +308,7 @@ impl ShellCommand for NodeModulesFileRunCommand {
let mut args = vec![
"run".to_string(),
"--ext=js".to_string(),
"--node-modules-dir=true".to_string(),
"-A".to_string(),
self.path.to_string_lossy().to_string(),
];