Skip to content

feat(x): add --package/-p flag for specifying package separately from binary - #32855

Merged
bartlomieju merged 3 commits into
mainfrom
feat/deno-x-package-flag
Apr 30, 2026
Merged

bartlomieju merged 3 commits into
mainfrom
feat/deno-x-package-flag

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

Summary

Closes #31667

Adds --package/-p flag to deno x that allows specifying the package to install separately from the binary to execute, matching the npx -p <package> <binary> convention.

This is useful when a package exposes multiple binaries (e.g. typescript has tsc and tsserver):

deno x -p typescript tsc
deno x -p typescript@5 tsc

Previously, the only way was deno x typescript/tsc.

The implementation combines --package and the binary name into {package}/{binary} before feeding it to the existing npm resolution flow, so all existing behavior is preserved.

Test plan

  • Added spec tests for -p (short) and --package (long) forms
  • All 19 existing deno x spec tests still pass
  • clippy clean

🤖 Generated with Claude Code

bartlomieju and others added 2 commits March 20, 2026 10:52
… binary

Add `--package`/`-p` flag to `deno x` that allows specifying the
package to install separately from the binary to execute, matching
the `npx -p <package> <binary>` convention.

This is useful when a package exposes multiple binaries (e.g.
`typescript` has `tsc` and `tsserver`):

  deno x -p typescript tsc
  deno x -p typescript@5 tsc

Previously, the only way to do this was:

  deno x typescript/tsc

Closes #31667

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@bartlomieju bartlomieju added this to the 2.8.0 milestone Apr 9, 2026
@bartlomieju
bartlomieju enabled auto-merge (squash) April 30, 2026 18:16

@fibibot fibibot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Substance is right and minimally scoped — --package/-p is parsed into XCommandFlags::package, then combined as {package}/{command} and threaded through the existing resolution flow as effective_command. Walked the version-specifier path (-p typescript@5 tsc → npm:typescript@5/tsc): URL::parse fails on the @, falls through to the npm: prefix branch, NpmPackageReqReference::from_str handles the version+subpath split correctly. --package correctly conflicts_with("install-alias"). The error message at the binary-not-found path now reports effective_command (with the package context), which is more informative.

One test-coverage gap inline. CI 97 pass / 17 pending / 0 fail; @nathanwhit already approved. Holding COMMENT until the remaining shards settle, but I'd flip to APPROVE on green CI.

"args": "x -y --package @denotest/bin cli-esm hello world",
"output": "run.out"
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coverage is happy-path only — both tests use the same plain @denotest/bin cli-esm shape. The version-specifier case is the canonical npx -p typescript@5 tsc pattern that motivates this flag, and exercises the URL::parse failure → npm: fallback path with a different surface than the bare-package case.

A third entry like:

"package_flag_with_version": {
  "tempDir": true,
  "args": "x -y -p @denotest/[email protected] cli-esm hello world",
  "output": "run.out"
}

would pin that path. Same run.out works (output doesn't depend on the version). Non-blocking, but since this is the case the PR description leads with, a regression test for it would be worth more than the long-vs-short-form duplication.

@bartlomieju
bartlomieju merged commit 7ef6d8c into main Apr 30, 2026
136 checks passed
@bartlomieju
bartlomieju deleted the feat/deno-x-package-flag branch April 30, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"deno x" command does not work with packages exposing multiple binaries

3 participants