Skip to content

Commit

Permalink
fix: xrange with prerelease or build
Browse files Browse the repository at this point in the history
  • Loading branch information
mbtools committed Apr 11, 2024
1 parent b236c3d commit 9771907
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
18 changes: 8 additions & 10 deletions internal/re.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,16 @@ createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`)
createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`)

createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
`(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
`(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
`(?:${src[t.PRERELEASE]})?${
src[t.BUILD]}?` +
`)?)?`)
`(?:\\.(${src[t.XRANGEIDENTIFIER]}))?` +
`(?:\\.(${src[t.XRANGEIDENTIFIER]}))?` +
`(?:${src[t.PRERELEASE]})?` +
`${src[t.BUILD]}?`)

createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
`(?:${src[t.PRERELEASELOOSE]})?${
src[t.BUILD]}?` +
`)?)?`)
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]}))?` +
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]}))?` +
`(?:${src[t.PRERELEASELOOSE]})?` +
`${src[t.BUILD]}?`)

createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`)
createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`)
Expand Down
14 changes: 13 additions & 1 deletion test/fixtures/range-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,26 @@ module.exports = [
['1.2 - 3.4', '>=1.2.0 <3.5.0-0'],
['>1', '>=2.0.0'],
['>1.2', '>=1.3.0'],
['>1.2.x', '>=1.3.0'],
['>1.2.x-pre', '>=1.3.0'],
['>1.2.x+build', '>=1.3.0'],
['>1.2.x-pre+build', '>=1.3.0'],
['>1.x', '>=2.0.0'],
['>1.x-pre', '>=2.0.0'],
['>1.x+build', '>=2.0.0'],
['>1.x-pre+build', '>=2.0.0'],
['>1', '>=2.0.0'],
['>1-pre', '>=2.0.0'],
['>1+build', '>=2.0.0'],
['>1-pre+build', '>=2.0.0'],
['>X', '<0.0.0-0'],
['<X', '<0.0.0-0'],
['<x <* || >* 2.x', '<0.0.0-0'],
['>x 2.x || * || <x', '*'],
['>=09090', null],
['>=09090', '>=9090.0.0', true],
['>=09090-0', null, { includePrerelease: true }],
['>=09090-0', null, { loose: true, includePrerelease: true }],
['>=09090-0', '>=9090.0.0-0', { loose: true, includePrerelease: true }],
[`^${MAX_SAFE_INTEGER}.0.0`, null],
[`=${MAX_SAFE_INTEGER}.0.0`, `${MAX_SAFE_INTEGER}.0.0`],
[`^${MAX_SAFE_INTEGER - 1}.0.0`, `>=${MAX_SAFE_INTEGER - 1}.0.0 <${MAX_SAFE_INTEGER}.0.0-0`],
Expand Down

0 comments on commit 9771907

Please sign in to comment.