Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Respect implied BYONM from DENO_FUTURE in deno task #24652

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions cli/npm/managed/resolvers/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,8 @@ fn resolve_baseline_custom_commands(
custom_commands
.insert("npm".to_string(), Rc::new(crate::task_runner::NpmCommand));

custom_commands.insert(
"node".to_string(),
Rc::new(crate::task_runner::NodeCommand {
force_node_modules_dir: true,
}),
);
custom_commands
.insert("node".to_string(), Rc::new(crate::task_runner::NodeCommand));

custom_commands.insert(
"node-gyp".to_string(),
Expand Down
8 changes: 1 addition & 7 deletions cli/task_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ impl ShellCommand for NpmCommand {
}
}

pub struct NodeCommand {
pub force_node_modules_dir: bool,
}
pub struct NodeCommand;

impl ShellCommand for NodeCommand {
fn execute(
Expand All @@ -193,9 +191,6 @@ 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;
Expand Down Expand Up @@ -308,7 +303,6 @@ impl ShellCommand for NodeModulesFileRunCommand {
let mut args = vec![
"run".to_string(),
"--ext=js".to_string(),
"--node-modules-dir=true".to_string(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug

"-A".to_string(),
self.path.to_string_lossy().to_string(),
];
Expand Down
13 changes: 13 additions & 0 deletions tests/specs/npm/lifecycle_scripts/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@
"output": "no_deno_json.out"
}
]
},
"lifecycle_scripts_no_deno_json_conflicting_bin": {
"tempDir": true,
"steps": [
{
"args": ["eval", "Deno.removeSync('deno.json')"],
"output": ""
},
{
"args": "cache --allow-scripts --node-modules-dir=true conflicting_bin.js",
"output": "conflicting_bin.out"
}
]
}
}
}
68 changes: 51 additions & 17 deletions tests/specs/task/byonm/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -1,20 +1,54 @@
{
"tempDir": true,
"steps": [{
"commandName": "npm",
"args": "install",
"output": "[WILDCARD]"
}, {
"args": "task say",
"output": "package_json_say.out"
}, {
"args": "task think",
"output": "package_json_think.out"
}, {
"args": "task deno-say",
"output": "deno_json_say.out"
}, {
"args": "task deno-think",
"output": "deno_json_think.out"
}]
"tests": {
"deno_json": {
"steps": [{
"commandName": "npm",
"args": "install",
"output": "[WILDCARD]"
}, {
"args": "task say",
"output": "package_json_say.out"
}, {
"args": "task think",
"output": "package_json_think.out"
}, {
"args": "task deno-say",
"output": "deno_json_say.out"
}, {
"args": "task deno-think",
"output": "deno_json_think.out"
}]
},
"no_deno_json": {
"steps": [{
"args": [
"eval",
"Deno.removeSync('deno.json')"
],
"output": ""
}, {
"commandName": "npm",
"args": "install",
"output": "[WILDCARD]"
}, {
// implied byonm from DENO_FUTURE
"envs": {
"DENO_FUTURE": "1"
},
"args": "task say",
"output": "package_json_say.out"
}, {
// byonm flag
"args": "task --unstable-byonm say",
"output": "package_json_say.out"
}, {
"args": [
"eval",
"try { Deno.statSync('node_modules/.deno'); } catch (e) { if (e instanceof Deno.errors.NotFound) { console.log('good'); } else { throw new Error('bad'); } }"
],
"output": "good\n"
}]
}
}
}