First adaptation pass

This commit is contained in:
2025-11-06 00:01:59 +01:00
parent 5b1fd847c2
commit 6b883f8126
112 changed files with 44142 additions and 953 deletions
+14 -4
View File
@@ -100,7 +100,7 @@ Options:
-i --increment [<level>]
Increment a version by the specified level. Level can
be one of: major, minor, patch, premajor, preminor,
prepatch, or prerelease. Default level is 'patch'.
prepatch, prerelease, or release. Default level is 'patch'.
Only one version may be specified.
--preid <identifier>
@@ -141,6 +141,8 @@ A "version" is described by the `v2.0.0` specification found at
<https://semver.org/>.
A leading `"="` or `"v"` character is stripped off and ignored.
Support for stripping a leading "v" is kept for compatibility with `v1.0.0` of the SemVer
specification but should not be used anymore.
## Ranges
@@ -237,6 +239,13 @@ $ semver 1.2.4-beta.0 -i prerelease
1.2.4-beta.1
```
To get out of the prerelease phase, use the `release` option:
```bash
$ semver 1.2.4-beta.1 -i release
1.2.4
```
#### Prerelease Identifier Base
The method `.inc` takes an optional parameter 'identifierBase' string
@@ -415,10 +424,10 @@ Strict-mode Comparators and Ranges will be strict about the SemVer
strings that they parse.
* `valid(v)`: Return the parsed version, or null if it's not valid.
* `inc(v, release, options, identifier, identifierBase)`:
* `inc(v, releaseType, options, identifier, identifierBase)`:
Return the version incremented by the release
type (`major`, `premajor`, `minor`, `preminor`, `patch`,
`prepatch`, or `prerelease`), or null if it's not valid
`prepatch`, `prerelease`, or `release`), or null if it's not valid
* `premajor` in one call will bump the version up to the next major
version and down to a prerelease of that major version.
`preminor`, and `prepatch` work the same way.
@@ -426,6 +435,7 @@ strings that they parse.
same as `prepatch`. It increments the patch version and then makes a
prerelease. If the input version is already a prerelease it simply
increments it.
* `release` will remove any prerelease part of the version.
* `identifier` can be used to prefix `premajor`, `preminor`,
`prepatch`, or `prerelease` version increments. `identifierBase`
is the base to be used for the `prerelease` identifier.
@@ -477,7 +487,7 @@ strings that they parse.
### Ranges
* `validRange(range)`: Return the valid range or null if it's not valid
* `validRange(range)`: Return the valid range or null if it's not valid.
* `satisfies(version, range)`: Return true if the version satisfies the
range.
* `maxSatisfying(versions, range)`: Return the highest version in the list
+4 -1
View File
@@ -3,6 +3,8 @@
// Exits successfully and prints matching version(s) if
// any supplied version is valid and passes all tests.
'use strict'
const argv = process.argv.slice(2)
let versions = []
@@ -61,6 +63,7 @@ const main = () => {
switch (argv[0]) {
case 'major': case 'minor': case 'patch': case 'prerelease':
case 'premajor': case 'preminor': case 'prepatch':
case 'release':
inc = argv.shift()
break
default:
@@ -149,7 +152,7 @@ Options:
-i --increment [<level>]
Increment a version by the specified level. Level can
be one of: major, minor, patch, premajor, preminor,
prepatch, or prerelease. Default level is 'patch'.
prepatch, prerelease, or release. Default level is 'patch'.
Only one version may be specified.
--preid <identifier>
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const ANY = Symbol('SemVer ANY')
// hoisted class for cyclic dependency
class Comparator {
+2
View File
@@ -1,3 +1,5 @@
'use strict'
module.exports = {
SemVer: require('./semver.js'),
Range: require('./range.js'),
+3
View File
@@ -1,3 +1,5 @@
'use strict'
const SPACE_CHARACTERS = /\s+/g
// hoisted class for cyclic dependency
@@ -253,6 +255,7 @@ const isSatisfiable = (comparators, options) => {
// already replaced the hyphen ranges
// turn into a set of JUST comparators.
const parseComparator = (comp, options) => {
comp = comp.replace(re[t.BUILD], '')
debug('comp', comp, options)
comp = replaceCarets(comp, options)
debug('caret', comp)
+41 -10
View File
@@ -1,3 +1,5 @@
'use strict'
const debug = require('../internal/debug')
const { MAX_LENGTH, MAX_SAFE_INTEGER } = require('../internal/constants')
const { safeRe: re, t } = require('../internal/re')
@@ -10,7 +12,7 @@ class SemVer {
if (version instanceof SemVer) {
if (version.loose === !!options.loose &&
version.includePrerelease === !!options.includePrerelease) {
version.includePrerelease === !!options.includePrerelease) {
return version
} else {
version = version.version
@@ -109,11 +111,25 @@ class SemVer {
other = new SemVer(other, this.options)
}
return (
compareIdentifiers(this.major, other.major) ||
compareIdentifiers(this.minor, other.minor) ||
compareIdentifiers(this.patch, other.patch)
)
if (this.major < other.major) {
return -1
}
if (this.major > other.major) {
return 1
}
if (this.minor < other.minor) {
return -1
}
if (this.minor > other.minor) {
return 1
}
if (this.patch < other.patch) {
return -1
}
if (this.patch > other.patch) {
return 1
}
return 0
}
comparePre (other) {
@@ -176,6 +192,19 @@ class SemVer {
// preminor will bump the version up to the next minor release, and immediately
// down to pre-release. premajor and prepatch work the same way.
inc (release, identifier, identifierBase) {
if (release.startsWith('pre')) {
if (!identifier && identifierBase === false) {
throw new Error('invalid increment argument: identifier is empty')
}
// Avoid an invalid semver results
if (identifier) {
const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE])
if (!match || match[1] !== identifier) {
throw new Error(`invalid identifier: ${identifier}`)
}
}
}
switch (release) {
case 'premajor':
this.prerelease.length = 0
@@ -206,6 +235,12 @@ class SemVer {
}
this.inc('pre', identifier, identifierBase)
break
case 'release':
if (this.prerelease.length === 0) {
throw new Error(`version ${this.raw} is not a prerelease`)
}
this.prerelease.length = 0
break
case 'major':
// If this is a pre-major version, bump up to the same major version.
@@ -249,10 +284,6 @@ class SemVer {
case 'pre': {
const base = Number(identifierBase) ? 1 : 0
if (!identifier && identifierBase === false) {
throw new Error('invalid increment argument: identifier is empty')
}
if (this.prerelease.length === 0) {
this.prerelease = [base]
} else {
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const parse = require('./parse')
const clean = (version, options) => {
const s = parse(version.trim().replace(/^[=v]+/, ''), options)
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const eq = require('./eq')
const neq = require('./neq')
const gt = require('./gt')
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const parse = require('./parse')
const { safeRe: re, t } = require('../internal/re')
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const compareBuild = (a, b, loose) => {
const versionA = new SemVer(a, loose)
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const compare = require('./compare')
const compareLoose = (a, b) => compare(a, b, true)
module.exports = compareLoose
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const compare = (a, b, loose) =>
new SemVer(a, loose).compare(new SemVer(b, loose))
+7 -12
View File
@@ -1,3 +1,5 @@
'use strict'
const parse = require('./parse.js')
const diff = (version1, version2) => {
@@ -27,20 +29,13 @@ const diff = (version1, version2) => {
return 'major'
}
// Otherwise it can be determined by checking the high version
if (highVersion.patch) {
// anything higher than a patch bump would result in the wrong version
// If the main part has no difference
if (lowVersion.compareMain(highVersion) === 0) {
if (lowVersion.minor && !lowVersion.patch) {
return 'minor'
}
return 'patch'
}
if (highVersion.minor) {
// anything higher than a minor bump would result in the wrong version
return 'minor'
}
// bumping major/minor/patch all have same result
return 'major'
}
// add the `pre` prefix if we are going to a prerelease version
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const compare = require('./compare')
const eq = (a, b, loose) => compare(a, b, loose) === 0
module.exports = eq
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const compare = require('./compare')
const gt = (a, b, loose) => compare(a, b, loose) > 0
module.exports = gt
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const compare = require('./compare')
const gte = (a, b, loose) => compare(a, b, loose) >= 0
module.exports = gte
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const inc = (version, release, options, identifier, identifierBase) => {
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const compare = require('./compare')
const lt = (a, b, loose) => compare(a, b, loose) < 0
module.exports = lt
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const compare = require('./compare')
const lte = (a, b, loose) => compare(a, b, loose) <= 0
module.exports = lte
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const major = (a, loose) => new SemVer(a, loose).major
module.exports = major
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const minor = (a, loose) => new SemVer(a, loose).minor
module.exports = minor
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const compare = require('./compare')
const neq = (a, b, loose) => compare(a, b, loose) !== 0
module.exports = neq
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const parse = (version, options, throwErrors = false) => {
if (version instanceof SemVer) {
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const patch = (a, loose) => new SemVer(a, loose).patch
module.exports = patch
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const parse = require('./parse')
const prerelease = (version, options) => {
const parsed = parse(version, options)
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const compare = require('./compare')
const rcompare = (a, b, loose) => compare(b, a, loose)
module.exports = rcompare
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const compareBuild = require('./compare-build')
const rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose))
module.exports = rsort
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const Range = require('../classes/range')
const satisfies = (version, range, options) => {
try {
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const compareBuild = require('./compare-build')
const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose))
module.exports = sort
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const parse = require('./parse')
const valid = (version, options) => {
const v = parse(version, options)
+2
View File
@@ -1,3 +1,5 @@
'use strict'
// just pre-load all the stuff that index.js lazily exports
const internalRe = require('./internal/re')
const constants = require('./internal/constants')
+2
View File
@@ -1,3 +1,5 @@
'use strict'
// Note: this is the semver.org version of the spec that it implements
// Not necessarily the package version of this code.
const SEMVER_SPEC_VERSION = '2.0.0'
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const debug = (
typeof process === 'object' &&
process.env &&
+6
View File
@@ -1,5 +1,11 @@
'use strict'
const numeric = /^[0-9]+$/
const compareIdentifiers = (a, b) => {
if (typeof a === 'number' && typeof b === 'number') {
return a === b ? 0 : a < b ? -1 : 1
}
const anum = numeric.test(a)
const bnum = numeric.test(b)
+2
View File
@@ -1,3 +1,5 @@
'use strict'
class LRUCache {
constructor () {
this.max = 1000
+2
View File
@@ -1,3 +1,5 @@
'use strict'
// parse out just the options we care about
const looseOption = Object.freeze({ loose: true })
const emptyOpts = Object.freeze({ })
+10 -4
View File
@@ -1,3 +1,5 @@
'use strict'
const {
MAX_SAFE_COMPONENT_LENGTH,
MAX_SAFE_BUILD_LENGTH,
@@ -10,6 +12,7 @@ exports = module.exports = {}
const re = exports.re = []
const safeRe = exports.safeRe = []
const src = exports.src = []
const safeSrc = exports.safeSrc = []
const t = exports.t = {}
let R = 0
@@ -42,6 +45,7 @@ const createToken = (name, value, isGlobal) => {
debug(name, index, value)
t[name] = index
src[index] = value
safeSrc[index] = safe
re[index] = new RegExp(value, isGlobal ? 'g' : undefined)
safeRe[index] = new RegExp(safe, isGlobal ? 'g' : undefined)
}
@@ -74,12 +78,14 @@ createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
// ## Pre-release Version Identifier
// A numeric identifier, or a non-numeric identifier.
// Non-numberic identifiers include numberic identifiers but can be longer.
// Therefore non-numberic identifiers must go first.
createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NUMERICIDENTIFIER]
}|${src[t.NONNUMERICIDENTIFIER]})`)
createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NONNUMERICIDENTIFIER]
}|${src[t.NUMERICIDENTIFIER]})`)
createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]
}|${src[t.NONNUMERICIDENTIFIER]})`)
createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NONNUMERICIDENTIFIER]
}|${src[t.NUMERICIDENTIFIERLOOSE]})`)
// ## Pre-release Version
// Hyphen, followed by one or more dot-separated pre-release version
+8 -7
View File
@@ -1,20 +1,21 @@
{
"name": "semver",
"version": "7.6.3",
"version": "7.7.3",
"description": "The semantic version parser used by npm.",
"main": "index.js",
"scripts": {
"test": "tap",
"snap": "tap",
"lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
"lint": "npm run eslint",
"postlint": "template-oss-check",
"lintfix": "npm run lint -- --fix",
"lintfix": "npm run eslint -- --fix",
"posttest": "npm run lint",
"template-oss-apply": "template-oss-apply --force"
"template-oss-apply": "template-oss-apply --force",
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
},
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.22.0",
"@npmcli/eslint-config": "^5.0.0",
"@npmcli/template-oss": "4.25.1",
"benchmark": "^2.1.4",
"tap": "^16.0.0"
},
@@ -51,7 +52,7 @@
"author": "GitHub Inc.",
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.22.0",
"version": "4.25.1",
"engines": ">=10",
"distPaths": [
"classes/",
+2
View File
@@ -1,2 +1,4 @@
'use strict'
// XXX remove in v8 or beyond
module.exports = require('./index.js')
+2
View File
@@ -1,3 +1,5 @@
'use strict'
// Determine if version is greater than all the versions possible in the range.
const outside = require('./outside')
const gtr = (version, range, options) => outside(version, range, '>', options)
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const Range = require('../classes/range')
const intersects = (r1, r2, options) => {
r1 = new Range(r1, options)
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const outside = require('./outside')
// Determine if version is less than all the versions possible in the range
const ltr = (version, range, options) => outside(version, range, '<', options)
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const Range = require('../classes/range')
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const Range = require('../classes/range')
const minSatisfying = (versions, range, options) => {
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const Range = require('../classes/range')
const gt = require('../functions/gt')
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const SemVer = require('../classes/semver')
const Comparator = require('../classes/comparator')
const { ANY } = Comparator
+2
View File
@@ -1,3 +1,5 @@
'use strict'
// given a set of versions and a range, create a "simplified" range
// that includes the same versions that the original range does
// If the original range is shorter than the simplified one, return that.
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const Range = require('../classes/range.js')
const Comparator = require('../classes/comparator.js')
const { ANY } = Comparator
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const Range = require('../classes/range')
// Mostly just for testing and legacy API reasons
+2
View File
@@ -1,3 +1,5 @@
'use strict'
const Range = require('../classes/range')
const validRange = (range, options) => {
try {