Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ steps = [
{ argv = ["vp", "dlx", "--help"], comment = "should show help message", continue-on-failure = true },
{ argv = ["vp", "dlx", "-s", "vp-test-echo", "hello"], comment = "should run vp-test-echo with npm exec", continue-on-failure = true },
{ argv = ["vp", "dlx", "-s", "vp-test-echo@1.0.0", "hello"], comment = "should run specific version", continue-on-failure = true },
{ argv = ["vp", "dlx", "-s", "@vp-test/cli@npm:vp-test-echo@1.0.0", "hello"], comment = "npm selects the binary rather than using the scoped alias name" },
{ argv = ["vp", "dlx", "-s", "-p", "vp-test-echo", "-p", "vp-test-upper", "vp-test-echo", "hello"], comment = "should run with multiple packages", continue-on-failure = true },
{ argv = ["vp", "dlx", "-s", "-p", "vp-test-echo", "-p", "vp-test-upper", "-c", "echo hello-from-shell | vp-test-echo | vp-test-upper"], comment = "should run shell mode command (vp's own shell handles the pipe)", continue-on-failure = true },
]
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ should run specific version
hello
```

## `vp dlx -s @vp-test/cli@npm:vp-test-echo@1.0.0 hello`

npm selects the binary rather than using the scoped alias name

```
hello
```

## `vp dlx -s -p vp-test-echo -p vp-test-upper vp-test-echo hello`

should run with multiple packages
Expand Down
49 changes: 10 additions & 39 deletions crates/vp_pm_cli/src/resolution/commands/dlx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Resolve<DlxArgs> for Npm {
for package in &args.package {
cmd.arg(vt_str::format!("--package={package}"));
}
if !args.shell_mode && (!args.package.is_empty() || package_spec.contains('@')) {
if !args.shell_mode && !args.package.is_empty() {
cmd.arg(vt_str::format!("--package={package_spec}"));
}
cmd.arg("--yes");
Expand All @@ -62,7 +62,7 @@ impl Resolve<DlxArgs> for Npm {
if args.shell_mode {
cmd.arg("-c").arg(build_shell_command(package_spec, command_args));
} else {
let command = if args.package.is_empty() && !package_spec.contains('@') {
let command = if args.package.is_empty() {
package_spec.to_string()
} else {
extract_command_from_spec(package_spec)
Expand Down Expand Up @@ -256,23 +256,11 @@ mod tests {

#[test]
fn test_npm_exec_with_version() {
let command = expect_run(
resolve(&npm("11.0.0"), dlx_args("typescript@5.5.4", &["tsc", "--version"])).outcome,
);
let command =
expect_run(resolve(&npm("11.0.0"), dlx_args("create-vue@3.10.0", &["my-app"])).outcome);

assert_eq!(command.program, "npm");
assert_eq!(
command.args,
vec![
"exec",
"--package=typescript@5.5.4",
"--yes",
"--",
"typescript",
"tsc",
"--version"
]
);
assert_eq!(command.args, vec!["exec", "--yes", "--", "create-vue@3.10.0", "my-app"]);
}

#[test]
Expand Down Expand Up @@ -345,37 +333,20 @@ mod tests {
#[test]
fn test_npm_exec_scoped_package_with_version() {
let command = expect_run(
resolve(&npm("11.0.0"), dlx_args("@vue/cli@5.0.0", &["create", "my-app"])).outcome,
resolve(&npm("11.0.0"), dlx_args("@angular/cli@19.2.15", &["--version"])).outcome,
);

assert_eq!(command.program, "npm");
assert_eq!(
command.args,
vec!["exec", "--package=@vue/cli@5.0.0", "--yes", "--", "cli", "create", "my-app"]
);
assert_eq!(command.args, vec!["exec", "--yes", "--", "@angular/cli@19.2.15", "--version"]);
}

#[test]
fn test_npm_exec_scoped_package_without_version() {
let command = expect_run(
resolve(&npm("11.0.0"), dlx_args("@vue/cli", &["create", "my-app"])).outcome,
);

assert_eq!(command.program, "npm");
assert_eq!(
command.args,
vec!["exec", "--package=@vue/cli", "--yes", "--", "cli", "create", "my-app"]
);
}

#[test]
fn test_npm_exec_version_requires_package_flag_and_extracted_command() {
let command =
expect_run(resolve(&npm("11.0.0"), dlx_args("create-vue@3.10.0", &["my-app"])).outcome);
expect_run(resolve(&npm("11.0.0"), dlx_args("@angular/cli", &["--version"])).outcome);

assert!(command.args.contains(&"--package=create-vue@3.10.0".to_string()));
let separator_pos = command.args.iter().position(|arg| arg == "--").unwrap();
assert_eq!(command.args[separator_pos + 1], "create-vue");
assert_eq!(command.program, "npm");
assert_eq!(command.args, vec!["exec", "--yes", "--", "@angular/cli", "--version"]);
}

#[test]
Expand Down
Loading