fix(add): accept npm version ranges on the command line#34799
Merged
Conversation
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
enabled auto-merge (squash)
June 6, 2026 08:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Deno reused the strict specifier version grammar (which only accepts
^,~, exact versions and tags) for the arguments ofdeno add, so versionranges 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 || 5and hyphenranges like
1 - 2, for bothnpm:andjsr:packages.deno addalready resolves the requirement against the registry to aconcrete version and writes a normalized
^/~/exact constraint to theconfig, so loosening only the command-line parsing is self-contained:
what lands in
deno.json(and innpm:/jsr:specifiers in code) stilluses the strict grammar, and a bare
import "npm:pkg@>=4"is stillrejected as before. The parse now falls back to the looser npm range
grammar when the strict reference parser refuses the input.
Closes #26587