Skip to content

fix(add): accept npm version ranges on the command line#34799

Merged
bartlomieju merged 2 commits into
mainfrom
fix/deno-add-version-ranges
Jun 6, 2026
Merged

fix(add): accept npm version ranges on the command line#34799
bartlomieju merged 2 commits into
mainfrom
fix/deno-add-version-ranges

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

Deno reused the strict specifier version grammar (which only accepts ^,
~, exact versions and tags) for the arguments of deno add, so version
ranges that npm itself supports were rejected with "Invalid specifier
version requirement". This affected comparator ranges like >=4,
space-combined ranges like >=4 <5, or-ranges like ^4 || 5 and hyphen
ranges like 1 - 2, for both npm: and jsr: packages.

deno add already resolves the requirement against the registry to a
concrete version and writes a normalized ^/~/exact constraint to the
config, so loosening only the command-line parsing is self-contained:
what lands in deno.json (and in npm:/jsr: specifiers in code) still
uses the strict grammar, and a bare import "npm:pkg@>=4" is still
rejected as before. The parse now falls back to the looser npm range
grammar when the strict reference parser refuses the input.

Closes #26587

The strict specifier version grammar used for npm:/jsr: specifiers only
accepts ^, ~, exact versions and tags, and it was also applied to the
arguments of deno add. As a result ranges that npm itself supports, such
as >=4, >=4 <5, ^4 || 5 and 1 - 2, were rejected with "Invalid specifier
version requirement".

deno add resolves the requirement to a concrete version before writing
it to the config, so accepting the looser npm range grammar on the
command line is self-contained: what ends up in deno.json (and in
specifiers in code) still uses the strict grammar. Fall back to loose
parsing in AddRmPackageReq::parse when the strict reference parser
rejects the input.

Closes #26587
@bartlomieju
bartlomieju enabled auto-merge (squash) June 6, 2026 08:34
@bartlomieju
bartlomieju merged commit 84b80f0 into main Jun 6, 2026
137 checks passed
@bartlomieju
bartlomieju deleted the fix/deno-add-version-ranges branch June 6, 2026 09:07
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.

Some version ranges (<, >, <=, >=) not working.

1 participant