mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix(task): always use npm
for npm run
with flags (#24028)
This commit is contained in:
parent
814ac9a75d
commit
3c3076a84c
4 changed files with 32 additions and 19 deletions
|
@ -344,24 +344,27 @@ impl ShellCommand for NpmCommand {
|
||||||
mut context: ShellCommandContext,
|
mut context: ShellCommandContext,
|
||||||
) -> LocalBoxFuture<'static, ExecuteResult> {
|
) -> LocalBoxFuture<'static, ExecuteResult> {
|
||||||
if context.args.first().map(|s| s.as_str()) == Some("run")
|
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
|
||||||
// run with deno task instead
|
let mut args = Vec::with_capacity(context.args.len());
|
||||||
let mut args = vec!["task".to_string(), task_name.to_string()];
|
args.push("task".to_string());
|
||||||
args.extend(context.args.iter().skip(2).cloned());
|
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");
|
let mut state = context.state;
|
||||||
return ExecutableCommand::new(
|
state.apply_env_var(USE_PKG_JSON_HIDDEN_ENV_VAR_NAME, "1");
|
||||||
"deno".to_string(),
|
return ExecutableCommand::new(
|
||||||
std::env::current_exe().unwrap(),
|
"deno".to_string(),
|
||||||
)
|
std::env::current_exe().unwrap(),
|
||||||
.execute(ShellCommandContext {
|
)
|
||||||
args,
|
.execute(ShellCommandContext {
|
||||||
state,
|
args,
|
||||||
..context
|
state,
|
||||||
});
|
..context
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// fallback to running the real npm command
|
// fallback to running the real npm command
|
||||||
|
@ -647,7 +650,7 @@ esac
|
||||||
|
|
||||||
if [ -x "$basedir/node" ]; then
|
if [ -x "$basedir/node" ]; then
|
||||||
exec "$basedir/node" "$basedir/../example/bin/example" "$@"
|
exec "$basedir/node" "$basedir/../example/bin/example" "$@"
|
||||||
else
|
else
|
||||||
exec node "$basedir/../example/bin/example" "$@"
|
exec node "$basedir/../example/bin/example" "$@"
|
||||||
fi"#;
|
fi"#;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
"npm_run": {
|
"npm_run": {
|
||||||
"args": "task npm_run",
|
"args": "task npm_run",
|
||||||
"output": "task_npm_run.out"
|
"output": "task_npm_run.out"
|
||||||
|
},
|
||||||
|
"npm_run_args": {
|
||||||
|
"args": "task npm_run_args",
|
||||||
|
"output": "task_npm_run_args.out"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
// currently this will execute using the actual `npm run` because we
|
// currently this will execute using the actual `npm run` because we
|
||||||
// haven't implemented the flags for `npm run` yet
|
// haven't implemented the flags for `npm run` yet
|
||||||
"test_using_npm": "npm run non_existent -- --ignore-scripts",
|
"test_using_npm": "npm run non_existent -- --ignore-scripts",
|
||||||
"npm_run": "npm run"
|
"npm_run": "npm run",
|
||||||
|
"npm_run_args": "npm run -d echo"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
5
tests/specs/task/npm_run/task_npm_run_args.out
Normal file
5
tests/specs/task/npm_run/task_npm_run_args.out
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
Task npm_run_args npm run -d echo
|
||||||
|
npm info using[WILDCARD]
|
||||||
|
|
||||||
|
> echo
|
||||||
|
[WILDCARD]
|
Loading…
Reference in a new issue