Socket
Socket
Sign inDemoInstall

semver

Package Overview
Dependencies
Maintainers
6
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

semver - npm Package Compare versions

Comparing version 7.3.8 to 7.4.0

10

bin/semver.js

@@ -26,3 +26,6 @@ #!/usr/bin/env node

let identifierBase
const semver = require('../')
const parseOptions = require('../internal/parse-options')

@@ -75,2 +78,5 @@ let reverse = false

break
case '-n':
identifierBase = argv.shift()
break
case '-c': case '--coerce':

@@ -93,3 +99,3 @@ coerce = true

options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
options = parseOptions({ loose, includePrerelease, rtl })

@@ -133,3 +139,3 @@ versions = versions.map((v) => {

}).map((v) => {
return inc ? semver.inc(v, inc, options, identifier) : v
return inc ? semver.inc(v, inc, options, identifier, identifierBase) : v
}).forEach((v, i, _) => {

@@ -136,0 +142,0 @@ console.log(v)

68

classes/comparator.js

@@ -81,9 +81,2 @@ const ANY = Symbol('SemVer ANY')

if (!options || typeof options !== 'object') {
options = {
loose: !!options,
includePrerelease: false,
}
}
if (this.operator === '') {

@@ -101,28 +94,39 @@ if (this.value === '') {

const sameDirectionIncreasing =
(this.operator === '>=' || this.operator === '>') &&
(comp.operator === '>=' || comp.operator === '>')
const sameDirectionDecreasing =
(this.operator === '<=' || this.operator === '<') &&
(comp.operator === '<=' || comp.operator === '<')
const sameSemVer = this.semver.version === comp.semver.version
const differentDirectionsInclusive =
(this.operator === '>=' || this.operator === '<=') &&
(comp.operator === '>=' || comp.operator === '<=')
const oppositeDirectionsLessThan =
cmp(this.semver, '<', comp.semver, options) &&
(this.operator === '>=' || this.operator === '>') &&
(comp.operator === '<=' || comp.operator === '<')
const oppositeDirectionsGreaterThan =
cmp(this.semver, '>', comp.semver, options) &&
(this.operator === '<=' || this.operator === '<') &&
(comp.operator === '>=' || comp.operator === '>')
options = parseOptions(options)
return (
sameDirectionIncreasing ||
sameDirectionDecreasing ||
(sameSemVer && differentDirectionsInclusive) ||
oppositeDirectionsLessThan ||
oppositeDirectionsGreaterThan
)
// Special cases where nothing can possibly be lower
if (options.includePrerelease &&
(this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
return false
}
if (!options.includePrerelease &&
(this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
return false
}
// Same direction increasing (> or >=)
if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
return true
}
// Same direction decreasing (< or <=)
if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
return true
}
// same SemVer and both sides are inclusive (<= or >=)
if (
(this.semver.version === comp.semver.version) &&
this.operator.includes('=') && comp.operator.includes('=')) {
return true
}
// opposite directions less than
if (cmp(this.semver, '<', comp.semver, options) &&
this.operator.startsWith('>') && comp.operator.startsWith('<')) {
return true
}
// opposite directions greater than
if (cmp(this.semver, '>', comp.semver, options) &&
this.operator.startsWith('<') && comp.operator.startsWith('>')) {
return true
}
return false
}

@@ -129,0 +133,0 @@ }

@@ -84,4 +84,6 @@ // hoisted class for cyclic dependency

// this is a very hot path, and fully deterministic.
const memoOpts = Object.keys(this.options).join(',')
const memoKey = `parseRange:${memoOpts}:${range}`
const memoOpts =
(this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) |
(this.options.loose && FLAG_LOOSE)
const memoKey = memoOpts + ':' + range
const cached = cache.get(memoKey)

@@ -194,2 +196,3 @@ if (cached) {

}
module.exports = Range

@@ -211,2 +214,3 @@

} = require('../internal/re')
const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require('../internal/constants')

@@ -213,0 +217,0 @@ const isNullSet = c => c.value === '<0.0.0-0'

@@ -178,3 +178,3 @@ const debug = require('../internal/debug')

// down to pre-release. premajor and prepatch work the same way.
inc (release, identifier) {
inc (release, identifier, identifierBase) {
switch (release) {

@@ -186,3 +186,3 @@ case 'premajor':

this.major++
this.inc('pre', identifier)
this.inc('pre', identifier, identifierBase)
break

@@ -193,3 +193,3 @@ case 'preminor':

this.minor++
this.inc('pre', identifier)
this.inc('pre', identifier, identifierBase)
break

@@ -201,4 +201,4 @@ case 'prepatch':

this.prerelease.length = 0
this.inc('patch', identifier)
this.inc('pre', identifier)
this.inc('patch', identifier, identifierBase)
this.inc('pre', identifier, identifierBase)
break

@@ -209,5 +209,5 @@ // If the input is a non-prerelease version, this acts the same as

if (this.prerelease.length === 0) {
this.inc('patch', identifier)
this.inc('patch', identifier, identifierBase)
}
this.inc('pre', identifier)
this.inc('pre', identifier, identifierBase)
break

@@ -271,2 +271,3 @@

if (identifier) {
const base = Number(identifierBase) ? 1 : 0
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,

@@ -276,6 +277,6 @@ // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0

if (isNaN(this.prerelease[1])) {
this.prerelease = [identifier, 0]
this.prerelease = [identifier, base]
}
} else {
this.prerelease = [identifier, 0]
this.prerelease = [identifier, base]
}

@@ -282,0 +283,0 @@ }

@@ -5,16 +5,32 @@ const parse = require('./parse')

const diff = (version1, version2) => {
if (eq(version1, version2)) {
const v1 = parse(version1)
const v2 = parse(version2)
if (eq(v1, v2)) {
return null
} else {
const v1 = parse(version1)
const v2 = parse(version2)
const hasPre = v1.prerelease.length || v2.prerelease.length
const prefix = hasPre ? 'pre' : ''
const defaultResult = hasPre ? 'prerelease' : ''
for (const key in v1) {
if (key === 'major' || key === 'minor' || key === 'patch') {
if (v1[key] !== v2[key]) {
return prefix + key
}
if (v1.major !== v2.major) {
return prefix + 'major'
}
if (v1.minor !== v2.minor) {
return prefix + 'minor'
}
if (v1.patch !== v2.patch) {
return prefix + 'patch'
}
if (!v1.prerelease.length || !v2.prerelease.length) {
if (v1.patch) {
return 'patch'
}
if (v1.minor) {
return 'minor'
}
if (v1.major) {
return 'major'
}
}

@@ -21,0 +37,0 @@ return defaultResult // may be undefined

const SemVer = require('../classes/semver')
const inc = (version, release, options, identifier) => {
const inc = (version, release, options, identifier, identifierBase) => {
if (typeof (options) === 'string') {
identifierBase = identifier
identifier = options

@@ -13,3 +14,3 @@ options = undefined

options
).inc(release, identifier).version
).inc(release, identifier, identifierBase).version
} catch (er) {

@@ -16,0 +17,0 @@ return null

const { MAX_LENGTH } = require('../internal/constants')
const { re, t } = require('../internal/re')
const SemVer = require('../classes/semver')
const parseOptions = require('../internal/parse-options')
const parse = (version, options) => {
options = parseOptions(options)
if (version instanceof SemVer) {

@@ -21,7 +16,2 @@ return version

const r = options.loose ? re[t.LOOSE] : re[t.FULL]
if (!r.test(version)) {
return null
}
try {

@@ -28,0 +18,0 @@ return new SemVer(version, options)

@@ -86,4 +86,5 @@ // just pre-load all the stuff that index.js lazily exports

SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
RELEASE_TYPES: constants.RELEASE_TYPES,
compareIdentifiers: identifiers.compareIdentifiers,
rcompareIdentifiers: identifiers.rcompareIdentifiers,
}

@@ -12,7 +12,20 @@ // Note: this is the semver.org version of the spec that it implements

const RELEASE_TYPES = [
'major',
'premajor',
'minor',
'preminor',
'patch',
'prepatch',
'prerelease',
]
module.exports = {
SEMVER_SPEC_VERSION,
MAX_LENGTH,
MAX_SAFE_COMPONENT_LENGTH,
MAX_SAFE_INTEGER,
MAX_SAFE_COMPONENT_LENGTH,
RELEASE_TYPES,
SEMVER_SPEC_VERSION,
FLAG_INCLUDE_PRERELEASE: 0b001,
FLAG_LOOSE: 0b010,
}

@@ -1,11 +0,15 @@

// parse out just the options we care about so we always get a consistent
// obj with keys in a consistent order.
const opts = ['includePrerelease', 'loose', 'rtl']
const parseOptions = options =>
!options ? {}
: typeof options !== 'object' ? { loose: true }
: opts.filter(k => options[k]).reduce((o, k) => {
o[k] = true
return o
}, {})
// parse out just the options we care about
const looseOption = Object.freeze({ loose: true })
const emptyOpts = Object.freeze({ })
const parseOptions = options => {
if (!options) {
return emptyOpts
}
if (typeof options !== 'object') {
return looseOption
}
return options
}
module.exports = parseOptions
{
"name": "semver",
"version": "7.3.8",
"version": "7.4.0",
"description": "The semantic version parser used by npm.",

@@ -16,4 +16,4 @@ "main": "index.js",

"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "4.4.4",
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.13.0",
"tap": "^16.0.0"

@@ -57,5 +57,4 @@ },

"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.4.4",
"version": "4.13.0",
"engines": ">=10",
"content": "./scripts",
"ciVersions": [

@@ -69,2 +68,3 @@ "10.0.0",

],
"npmSpec": "8",
"distPaths": [

@@ -87,4 +87,5 @@ "classes/",

"/range.bnf"
]
],
"publish": "true"
}
}

@@ -5,4 +5,4 @@ const Range = require('../classes/range')

r2 = new Range(r2, options)
return r1.intersects(r2)
return r1.intersects(r2, options)
}
module.exports = intersects

@@ -71,2 +71,5 @@ const Range = require('../classes/range.js')

const minimumVersionWithPreRelease = [new Comparator('>=0.0.0-0')]
const minimumVersion = [new Comparator('>=0.0.0')]
const simpleSubset = (sub, dom, options) => {

@@ -81,5 +84,5 @@ if (sub === dom) {

} else if (options.includePrerelease) {
sub = [new Comparator('>=0.0.0-0')]
sub = minimumVersionWithPreRelease
} else {
sub = [new Comparator('>=0.0.0')]
sub = minimumVersion
}

@@ -92,3 +95,3 @@ }

} else {
dom = [new Comparator('>=0.0.0')]
dom = minimumVersion
}

@@ -95,0 +98,0 @@ }

@@ -113,2 +113,5 @@ semver(1) -- The semantic versioner for npm

-n <0|1>
This is the base to be used for the prerelease identifier.
-p --include-prerelease

@@ -236,2 +239,20 @@ Always include prerelease versions in range matching

#### Prerelease Identifier Base
The method `.inc` takes an optional parameter 'identifierBase' string
that will let you let your prerelease number as zero-based or one-based.
If you do not specify this parameter, it will default to zero-based.
```javascript
semver.inc('1.2.3', 'prerelease', 'beta', '1')
// '1.2.4-beta.1'
```
command-line example:
```bash
$ semver 1.2.3 -i prerelease --preid beta -n 1
1.2.4-beta.1
```
### Advanced Range Syntax

@@ -518,2 +539,36 @@

## Constants
As a convenience, helper constants are exported to provide information about what `node-semver` supports:
### `RELEASE_TYPES`
- major
- premajor
- minor
- preminor
- patch
- prepatch
- prerelease
```
const semver = require('semver');
if (semver.RELEASE_TYPES.includes(arbitraryUserInput)) {
console.log('This is a valid release type!');
} else {
console.warn('This is NOT a valid release type!');
}
```
### `SEMVER_SPEC_VERSION`
2.0.0
```
const semver = require('semver');
console.log('We are currently using the semver specification version:', semver.SEMVER_SPEC_VERSION);
```
## Exported Modules

@@ -572,1 +627,2 @@

* `require('semver/ranges/valid')`
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc