Skip to content

feat(add/install): default to npm registry for unprefixed packages - #33246

Merged
bartlomieju merged 3 commits into
mainfrom
reland/npm-default-registry
May 2, 2026
Merged

bartlomieju merged 3 commits into
mainfrom
reland/npm-default-registry

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

Reland of #33156, which was reverted in #33214 to be relanded for Deno v2.8.


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

Makes deno add express and deno install express work without
requiring the npm: prefix or --npm flag. Since npm is by far the
most common registry for package installation, this removes friction
for the most common use case.

The --jsr flag is still available to override the default to jsr,
and explicit jsr: / npm: prefixes always take precedence.

…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>
@bartlomieju bartlomieju modified the milestones: 3.0, 2.8.0 Apr 12, 2026
@bartlomieju bartlomieju changed the title reland: feat(add/install): default to npm registry for unprefixed packages feat(add/install): default to npm registry for unprefixed packages Apr 12, 2026

@lunadogbot lunadogbot 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.

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": [
{

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.

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.)

lunadogbot added a commit to lunadogbot/docs that referenced this pull request Apr 29, 2026
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 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 walks cleanly. The default-registry flip is small and well-bounded:

  • add_parse_inner in flags.rs:6286–6293 switches the no-flag fallthrough from None → Some(DefaultRegistry::Npm). Help text + tests update in lockstep.
  • AddRmPackageReq::parse in cli/tools/pm/mod.rs:851–875 no longer applies default_prefix upfront — it's now applied only after alias-parsing fails. That preserves the existing precedence: explicit npm: / jsr: wins, then aliases (my-name@npm:foo), then the default registry. New unit-test cases at mod.rs:1098–1120 lock in this ordering for npm: prefix + alias and unprefixed-with-default.
  • UX win on missing-from-npm: tests/specs/add/missing_prefix/__test__.jsonc now tests that deno 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 both add and install cover unprefixed-defaults-to-npm, mixed prefixes, and --jsr override.

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.

@bartlomieju
bartlomieju merged commit 0a8ade2 into main May 2, 2026
267 of 270 checks passed
@bartlomieju
bartlomieju deleted the reland/npm-default-registry branch May 2, 2026 10:44
bartlomieju added a commit that referenced this pull request May 21, 2026
…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.
littledivy pushed a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…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.
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.

3 participants