feat(add): --unscoped flag to alias packages by their unscoped name - #36319
Conversation
`deno add --unscoped jsr:@david/jsonc-morph` adds the package to the
import map as "jsonc-morph" instead of "@david/jsonc-morph", which is
the same result as spelling out `jsonc-morph@jsr:@david/jsonc-morph`.
Also supported on `deno install <pkg>`. Applies to package.json too,
where a differing alias is written using npm's alias syntax
("esm-basic": "npm:@denotest/esm-basic@^1.0.0").
An alias the user provided always wins, and unscoped package names are
unaffected. Because two scopes can share a name, adding packages that
would collapse to the same alias is an error rather than letting one
silently overwrite the other.
|
The within-command collision guard is a nice touch, but it only compares against the other packages in the same The second command replaces the first This matches how |
Yes, I noticed this and kept the current behaviour. |
deno add --unscoped jsr:@david/jsonc-morphadds the package to the import map as "jsonc-morph" instead of "@david/jsonc-morph", which is the same result as spelling outjsonc-morph@jsr:@david/jsonc-morph.jsonc-morph@jsr:@david/jsonc-morphis a mouthful, so--unscopedis nicer to write and doesn't have any duplication.The reason I want this, is so I can recommend:
Then the users all import from the same
"jsonc-morph"bare specifier.Also supported on
deno install <pkg>. Applies to package.json too, where a differing alias is written using npm's alias syntax ("esm-basic": "npm:@denotest/esm-basic@^1.0.0").An alias the user provided always wins, and unscoped package names are unaffected. Because two scopes can share a name, adding packages that would collapse to the same alias is an error rather than letting one silently overwrite the other.
This PR was created and iterated on with AI.