summaryrefslogtreecommitdiff
path: root/cli/tools/task.rs
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2024-05-29 22:16:35 +0200
committerGitHub <noreply@github.com>2024-05-29 20:16:35 +0000
commit3c3076a84ce84f7f9b5db5f476db8ee878eb603b (patch)
tree5838815d86ba728fd1a53d1737148b6124a3a559 /cli/tools/task.rs
parent814ac9a75d343435ac7c8c2ff6dad8ab89eb8a4c (diff)
fix(task): always use `npm` for `npm run` with flags (#24028)
Diffstat (limited to 'cli/tools/task.rs')
-rw-r--r--cli/tools/task.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/cli/tools/task.rs b/cli/tools/task.rs
index 5cb6cc112..2429e5600 100644
--- a/cli/tools/task.rs
+++ b/cli/tools/task.rs
@@ -344,24 +344,27 @@ impl ShellCommand for NpmCommand {
mut context: ShellCommandContext,
) -> LocalBoxFuture<'static, ExecuteResult> {
if context.args.first().map(|s| s.as_str()) == Some("run")
- && !context.args.iter().any(|s| s == "--")
+ && context.args.len() > 2
+ // for now, don't run any npm scripts that have a flag because
+ // we don't handle stuff like `--workspaces` properly
+ && !context.args.iter().any(|s| s.starts_with('-'))
{
- if let Some(task_name) = context.args.get(1) {
- // run with deno task instead
- let mut args = vec!["task".to_string(), task_name.to_string()];
- args.extend(context.args.iter().skip(2).cloned());
- let mut state = context.state;
- state.apply_env_var(USE_PKG_JSON_HIDDEN_ENV_VAR_NAME, "1");
- return ExecutableCommand::new(
- "deno".to_string(),
- std::env::current_exe().unwrap(),
- )
- .execute(ShellCommandContext {
- args,
- state,
- ..context
- });
- }
+ // run with deno task instead
+ let mut args = Vec::with_capacity(context.args.len());
+ args.push("task".to_string());
+ args.extend(context.args.iter().skip(1).cloned());
+
+ let mut state = context.state;
+ state.apply_env_var(USE_PKG_JSON_HIDDEN_ENV_VAR_NAME, "1");
+ return ExecutableCommand::new(
+ "deno".to_string(),
+ std::env::current_exe().unwrap(),
+ )
+ .execute(ShellCommandContext {
+ args,
+ state,
+ ..context
+ });
}
// fallback to running the real npm command
@@ -647,7 +650,7 @@ esac
if [ -x "$basedir/node" ]; then
exec "$basedir/node" "$basedir/../example/bin/example" "$@"
-else
+else
exec node "$basedir/../example/bin/example" "$@"
fi"#;
assert_eq!(