Closed gjedeer closed 4 years ago
Reading the NPM grammar, the version is invalid:
range ::= hyphen | simple ( ' ' simple ) * | ''
simple ::= primitive | partial | tilde | caret
A range
can be empty, an hyphen
(a.b.c-d.e.f
), or a set of simple
blocks separated by a single space.
A simple
block is defined as:
primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial
So: a comparator, immediately attached to a partial
.
A partial is:
partial ::= xr ( '.' xr ( '.' xr qualifier ? )? )?
xr ::= 'x' | 'X' | '*' | nr
nr ::= '0' | ['1'-'9'] ( ['0'-'9'] ) *
qualifier ::= ( '-' pre )? ( '+' build )?
I suggest raising the issue with the developer of that package ;)
It seems what they implement is different from their specification, then: https://github.com/npm/node-semver/blob/master/classes/range.js#L91 - but it looks like I can pre-process the range with the same regex node-semver uses internally.
So, just in case this comes useful for someone in the future, the npm logic translated to Python is as following:
comparator_trim_re = re.compile(r'(\s*)((?:<|>)?=?)\s*([v=\s]*([0-9]+)\.([0-9]+)\.([0-9]+)(?:-?((?:[0-9]+|\d*[a-zA-Z-][a-zA-Z0-9-]*)(?:\.(?:[0-9]+|\d*[a-zA-Z-][a-zA-Z0-9-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?|[v=\s]*(0|[1-9]\d*|x|X|\*)(?:\.(0|[1-9]\d*|x|X|\*)(?:\.(0|[1-9]\d*|x|X|\*)(?:(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][a-zA-Z0-9-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][a-zA-Z0-9-]*))*)))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?)?)?)')
def clean_up_npm_range(range):
return comparator_trim_re.sub(r'\1\2\3', range)
I'm getting an error when parsing an expression from npmjs.com:
The full version spec was:
I did not make up this spec string - it was found when parsing package.json found on npm.