Skip to content

Commit

Permalink
fix: reuse parsed options
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Apr 6, 2023
1 parent 9edf714 commit eccb1f2
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bin/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let rtl = false
let identifier

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

let reverse = false

Expand Down Expand Up @@ -88,7 +89,7 @@ const main = () => {
}
}

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

versions = versions.map((v) => {
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
Expand Down
3 changes: 1 addition & 2 deletions functions/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const SemVer = require('../classes/semver')

const parseOptions = require('../internal/parse-options')
const parse = (version, options) => {
options = parseOptions(options)

if (version instanceof SemVer) {
return version
}
Expand All @@ -18,6 +16,7 @@ const parse = (version, options) => {
return null
}

options = parseOptions(options)
const r = options.loose ? re[t.LOOSE] : re[t.FULL]
if (!r.test(version)) {
return null
Expand Down
2 changes: 2 additions & 0 deletions ranges/intersects.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const Range = require('../classes/range')
const parseOptions = require('../internal/parse-options')
const intersects = (r1, r2, options) => {
options = parseOptions(options)
r1 = new Range(r1, options)
r2 = new Range(r2, options)
return r1.intersects(r2)
Expand Down
2 changes: 2 additions & 0 deletions ranges/max-satisfying.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const SemVer = require('../classes/semver')
const Range = require('../classes/range')
const parseOptions = require('../internal/parse-options')

const maxSatisfying = (versions, range, options) => {
let max = null
let maxSV = null
let rangeObj = null
options = parseOptions(options)
try {
rangeObj = new Range(range, options)
} catch (er) {
Expand Down
2 changes: 2 additions & 0 deletions ranges/min-satisfying.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const SemVer = require('../classes/semver')
const Range = require('../classes/range')
const parseOptions = require('../internal/parse-options')
const minSatisfying = (versions, range, options) => {
let min = null
let minSV = null
let rangeObj = null
options = parseOptions(options)
try {
rangeObj = new Range(range, options)
} catch (er) {
Expand Down
2 changes: 2 additions & 0 deletions ranges/outside.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const gt = require('../functions/gt')
const lt = require('../functions/lt')
const lte = require('../functions/lte')
const gte = require('../functions/gte')
const parseOptions = require('../internal/parse-options')

const outside = (version, range, hilo, options) => {
options = parseOptions(options)
version = new SemVer(version, options)
range = new Range(range, options)

Expand Down
2 changes: 2 additions & 0 deletions ranges/simplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// If the original range is shorter than the simplified one, return that.
const satisfies = require('../functions/satisfies.js')
const compare = require('../functions/compare.js')
const parseOptions = require('../internal/parse-options.js')
module.exports = (versions, range, options) => {
options = parseOptions(options)
const set = []
let first = null
let prev = null
Expand Down
2 changes: 2 additions & 0 deletions ranges/subset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Comparator = require('../classes/comparator.js')
const { ANY } = Comparator
const satisfies = require('../functions/satisfies.js')
const compare = require('../functions/compare.js')
const parseOptions = require('../internal/parse-options.js')

// Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff:
// - Every simple range `r1, r2, ...` is a null set, OR
Expand Down Expand Up @@ -45,6 +46,7 @@ const subset = (sub, dom, options = {}) => {
return true
}

options = parseOptions(options)
sub = new Range(sub, options)
dom = new Range(dom, options)
let sawNonNull = false
Expand Down

0 comments on commit eccb1f2

Please sign in to comment.