Repository navigation
feat(add/install): default to npm registry for unprefixed packages - #33246
Conversation
…33156) Before: ``` $ deno install npm:express npm:react $ deno install --npm express react $ deno install jsr:@std/async ``` After: ``` $ deno install express react jsr:@std/async ``` --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
lunadogbot
left a comment
There was a problem hiding this comment.
LGTM -- traced through AddRmPackageReq::parse for the cases I cared about (my-alias@npm:foo, my-alias@jsr:foo, chalk, chalk@5, @scope/pkg) and the move of default_prefix.or(...) from before the alias parse to after it (in both the inner and outer None branches) cleanly preserves alias-with-explicit-prefix while applying the default to bare names. The new test cases at cli/tools/pm/mod.rs:1035-1052 lock in the four interesting permutations. Verified the Currently unreachable comment is accurate -- with default_registry: Some(Npm), parse() never returns Ok(Err(_)) from this caller, but the test's npm:@denotest/echo was not found, but a matching jsr package exists hint comes from a different downstream code path (npm resolution failure decoration), not the parse Err branch. One non-blocking note about a UX edge case.
| // Packages that only exist on jsr should suggest using jsr: prefix | ||
| "jsr_needs_prefix": { | ||
| "steps": [ | ||
| { |
There was a problem hiding this comment.
The previous behavior for deno add @std/testing was an explicit Did you mean 'deno add jsr:@std/testing'? error -- now it tries npm first. If a third party ever publishes a package at @std/testing on npm (the scope is unreserved on npmjs.com today), users typing deno add @std/testing would silently get that npm package instead of the JSR one they almost certainly meant. Worth a release-note callout that @scope/pkg patterns where the JSR variant is the well-known one should be typed with the jsr: prefix or --jsr flag explicitly. (Not blocking: this is the intentional UX trade-off, and the npm-fallback-suggests-jsr error fires when the npm package legitimately doesn't exist.)
Updates the deno add and deno install reference pages to reflect the 2.8 behavior change: unprefixed names like \`express\` resolve to npm by default, removing the need for \`--npm\` for the common case. Notes that \`jsr:\` and \`npm:\` prefixes still take precedence and that \`--jsr\` opts unprefixed names back to JSR resolution. Refs denoland/deno#33246
fibibot
left a comment
There was a problem hiding this comment.
Substance walks cleanly. The default-registry flip is small and well-bounded:
add_parse_innerinflags.rs:6286–6293switches the no-flag fallthrough fromNone→Some(DefaultRegistry::Npm). Help text + tests update in lockstep.AddRmPackageReq::parseincli/tools/pm/mod.rs:851–875no longer appliesdefault_prefixupfront — it's now applied only after alias-parsing fails. That preserves the existing precedence: explicitnpm:/jsr:wins, then aliases (my-name@npm:foo), then the default registry. New unit-test cases atmod.rs:1098–1120lock in this ordering fornpm:prefix + alias and unprefixed-with-default.- UX win on missing-from-npm:
tests/specs/add/missing_prefix/__test__.jsoncnow tests thatdeno add @denotest/echo(only on JSR) emits"npm:@denotest/echo was not found, but a matching jsr package exists. Did you mean 'deno add jsr:@denotest/echo'?"— that's exactly the right suggestion shape for the new default. - New
npm_default/spec fixtures for bothaddandinstallcover unprefixed-defaults-to-npm, mixed prefixes, and--jsroverride.
Why I'm holding COMMENT, not APPROVE
This is the breaking-default-behavior escalation case the autonomous-APPROVE bar specifically calls out — deno add foo previously errored with "missing prefix", now installs from npm. Even with a clean reland from #33156 (reverted in #33214) and the substance lining up correctly, the policy decision "npm is the default registry for unprefixed names" is exactly the kind of user-facing default flip that warrants a maintainer's eye on each reland — particularly given the v2.7→v2.8 reland gap suggests the previous attempt surfaced something that needed addressing.
Not blocking from the substance side. cc @nathanwhit on the reland — he's been most active on the cli/tools/pm/ install path and has the context for whether anything from the original revert reason still applies here.
CI
70 success / 25 in-progress / 1 skip / 1 cla pending at this head. The build and test_unit_node shards are still landing — worth waiting for the in-progress jobs before final merge call.
…es (#34290) `deno install -g @earendil-works/pi-coding-agent` previously bailed with a "missing a prefix" error and asked the user to retype it with `npm:`, while `deno add @earendil-works/pi-coding-agent` and local `deno install @earendil-works/pi-coding-agent` have defaulted to the npm registry since #33246. The global install path lives in `cli/tools/installer/global.rs` and was missed in that change.
…es (denoland#34290) `deno install -g @earendil-works/pi-coding-agent` previously bailed with a "missing a prefix" error and asked the user to retype it with `npm:`, while `deno add @earendil-works/pi-coding-agent` and local `deno install @earendil-works/pi-coding-agent` have defaulted to the npm registry since denoland#33246. The global install path lives in `cli/tools/installer/global.rs` and was missed in that change.
Reland of #33156, which was reverted in #33214 to be relanded for Deno v2.8.
Before:
After:
Makes
deno add expressanddeno install expresswork withoutrequiring the
npm:prefix or--npmflag. Since npm is by far themost common registry for package installation, this removes friction
for the most common use case.
The
--jsrflag is still available to override the default to jsr,and explicit
jsr:/npm:prefixes always take precedence.