xo 0.54.0 → 0.54.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/config/plugins.cjs +7 -0
  2. package/node_modules/@typescript-eslint/eslint-plugin/dist/configs/all.js +1 -0
  3. package/node_modules/@typescript-eslint/eslint-plugin/dist/configs/all.js.map +1 -1
  4. package/node_modules/@typescript-eslint/eslint-plugin/dist/configs/strict.js +1 -0
  5. package/node_modules/@typescript-eslint/eslint-plugin/dist/configs/strict.js.map +1 -1
  6. package/node_modules/@typescript-eslint/eslint-plugin/dist/rules/enum-utils/shared.js +61 -0
  7. package/node_modules/@typescript-eslint/eslint-plugin/dist/rules/enum-utils/shared.js.map +1 -0
  8. package/node_modules/@typescript-eslint/eslint-plugin/dist/rules/index.js +2 -0
  9. package/node_modules/@typescript-eslint/eslint-plugin/dist/rules/index.js.map +1 -1
  10. package/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unsafe-enum-comparison.js +119 -0
  11. package/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unsafe-enum-comparison.js.map +1 -0
  12. package/node_modules/@typescript-eslint/eslint-plugin/dist/rules/unified-signatures.js +1 -2
  13. package/node_modules/@typescript-eslint/eslint-plugin/dist/rules/unified-signatures.js.map +1 -1
  14. package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-enum-comparison.md +75 -0
  15. package/node_modules/@typescript-eslint/eslint-plugin/package.json +5 -5
  16. package/node_modules/@typescript-eslint/parser/dist/parser.d.ts.map +1 -1
  17. package/node_modules/@typescript-eslint/parser/dist/parser.js +5 -1
  18. package/node_modules/@typescript-eslint/parser/dist/parser.js.map +1 -1
  19. package/node_modules/@typescript-eslint/parser/package.json +5 -5
  20. package/node_modules/@typescript-eslint/scope-manager/package.json +5 -5
  21. package/node_modules/@typescript-eslint/type-utils/_ts3.4/dist/typeFlagUtils.d.ts +8 -3
  22. package/node_modules/@typescript-eslint/type-utils/dist/typeFlagUtils.d.ts +8 -3
  23. package/node_modules/@typescript-eslint/type-utils/dist/typeFlagUtils.d.ts.map +1 -1
  24. package/node_modules/@typescript-eslint/type-utils/dist/typeFlagUtils.js +10 -4
  25. package/node_modules/@typescript-eslint/type-utils/dist/typeFlagUtils.js.map +1 -1
  26. package/node_modules/@typescript-eslint/type-utils/package.json +5 -5
  27. package/node_modules/@typescript-eslint/types/package.json +2 -2
  28. package/node_modules/@typescript-eslint/typescript-estree/package.json +4 -4
  29. package/node_modules/@typescript-eslint/utils/package.json +6 -6
  30. package/node_modules/@typescript-eslint/visitor-keys/package.json +3 -3
  31. package/node_modules/semver/README.md +56 -0
  32. package/node_modules/semver/bin/semver.js +8 -2
  33. package/node_modules/semver/classes/comparator.js +37 -33
  34. package/node_modules/semver/classes/range.js +6 -2
  35. package/node_modules/semver/classes/semver.js +10 -9
  36. package/node_modules/semver/functions/diff.js +24 -8
  37. package/node_modules/semver/functions/inc.js +3 -2
  38. package/node_modules/semver/functions/parse.js +0 -10
  39. package/node_modules/semver/index.js +1 -0
  40. package/node_modules/semver/internal/constants.js +15 -2
  41. package/node_modules/semver/internal/parse-options.js +14 -10
  42. package/node_modules/semver/package.json +7 -6
  43. package/node_modules/semver/ranges/intersects.js +1 -1
  44. package/node_modules/semver/ranges/subset.js +6 -3
  45. package/package.json +1 -1
@@ -26,8 +26,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.isTypeFlagSet = exports.getTypeFlags = void 0;
27
27
  const tsutils_1 = require("tsutils");
28
28
  const ts = __importStar(require("typescript"));
29
+ const ANY_OR_UNKNOWN = ts.TypeFlags.Any | ts.TypeFlags.Unknown;
29
30
  /**
30
- * Gets all of the type flags in a type, iterating through unions automatically
31
+ * Gets all of the type flags in a type, iterating through unions automatically.
31
32
  */
32
33
  function getTypeFlags(type) {
33
34
  // @ts-expect-error Since typescript 5.0, this is invalid, but uses 0 as the default value of TypeFlags.
@@ -39,12 +40,17 @@ function getTypeFlags(type) {
39
40
  }
40
41
  exports.getTypeFlags = getTypeFlags;
41
42
  /**
42
- * Checks if the given type is (or accepts) the given flags
43
- * @param isReceiver true if the type is a receiving type (i.e. the type of a called function's parameter)
43
+ * @param flagsToCheck The composition of one or more `ts.TypeFlags`.
44
+ * @param isReceiver Whether the type is a receiving type (e.g. the type of a
45
+ * called function's parameter).
46
+ * @remarks
47
+ * Note that if the type is a union, this function will decompose it into the
48
+ * parts and get the flags of every union constituent. If this is not desired,
49
+ * use the `isTypeFlag` function from tsutils.
44
50
  */
45
51
  function isTypeFlagSet(type, flagsToCheck, isReceiver) {
46
52
  const flags = getTypeFlags(type);
47
- if (isReceiver && flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) {
53
+ if (isReceiver && flags & ANY_OR_UNKNOWN) {
48
54
  return true;
49
55
  }
50
56
  return (flags & flagsToCheck) !== 0;
@@ -1 +1 @@
1
- {"version":3,"file":"typeFlagUtils.js","sourceRoot":"","sources":["../src/typeFlagUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyC;AACzC,+CAAiC;AAEjC;;GAEG;AACH,SAAgB,YAAY,CAAC,IAAa;IACxC,wGAAwG;IACxG,IAAI,KAAK,GAAiB,CAAC,CAAC;IAC5B,KAAK,MAAM,CAAC,IAAI,IAAA,wBAAc,EAAC,IAAI,CAAC,EAAE;QACpC,KAAK,IAAI,CAAC,CAAC,KAAK,CAAC;KAClB;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,oCAOC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAC3B,IAAa,EACb,YAA0B,EAC1B,UAAoB;IAEpB,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAEjC,IAAI,UAAU,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;QACnE,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CAAC,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAZD,sCAYC"}
1
+ {"version":3,"file":"typeFlagUtils.js","sourceRoot":"","sources":["../src/typeFlagUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyC;AACzC,+CAAiC;AAEjC,MAAM,cAAc,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC;AAE/D;;GAEG;AACH,SAAgB,YAAY,CAAC,IAAa;IACxC,wGAAwG;IACxG,IAAI,KAAK,GAAiB,CAAC,CAAC;IAC5B,KAAK,MAAM,CAAC,IAAI,IAAA,wBAAc,EAAC,IAAI,CAAC,EAAE;QACpC,KAAK,IAAI,CAAC,CAAC,KAAK,CAAC;KAClB;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,oCAOC;AAED;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAC3B,IAAa,EACb,YAA0B,EAC1B,UAAoB;IAEpB,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAEjC,IAAI,UAAU,IAAI,KAAK,GAAG,cAAc,EAAE;QACxC,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CAAC,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAZD,sCAYC"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/type-utils",
3
- "version": "5.57.1",
3
+ "version": "5.58.0",
4
4
  "description": "Type utilities for working with TypeScript + ESLint together",
5
5
  "keywords": [
6
6
  "eslint",
@@ -39,13 +39,13 @@
39
39
  "typecheck": "tsc -p tsconfig.json --noEmit"
40
40
  },
41
41
  "dependencies": {
42
- "@typescript-eslint/typescript-estree": "5.57.1",
43
- "@typescript-eslint/utils": "5.57.1",
42
+ "@typescript-eslint/typescript-estree": "5.58.0",
43
+ "@typescript-eslint/utils": "5.58.0",
44
44
  "debug": "^4.3.4",
45
45
  "tsutils": "^3.21.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@typescript-eslint/parser": "5.57.1",
48
+ "@typescript-eslint/parser": "5.58.0",
49
49
  "typescript": "*"
50
50
  },
51
51
  "peerDependencies": {
@@ -67,5 +67,5 @@
67
67
  ]
68
68
  }
69
69
  },
70
- "gitHead": "772b19cd4b3d565670c07a1a42b36ee082a20387"
70
+ "gitHead": "0c6b63658aa5b01188480150fd777a1fa9b277eb"
71
71
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/types",
3
- "version": "5.57.1",
3
+ "version": "5.58.0",
4
4
  "description": "Types for the TypeScript-ESTree AST spec",
5
5
  "keywords": [
6
6
  "eslint",
@@ -80,5 +80,5 @@
80
80
  "devDependencies": {
81
81
  "typescript": "*"
82
82
  },
83
- "gitHead": "772b19cd4b3d565670c07a1a42b36ee082a20387"
83
+ "gitHead": "0c6b63658aa5b01188480150fd777a1fa9b277eb"
84
84
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/typescript-estree",
3
- "version": "5.57.1",
3
+ "version": "5.58.0",
4
4
  "description": "A parser that converts TypeScript source code into an ESTree compatible form",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -42,8 +42,8 @@
42
42
  "typecheck": "tsc -p tsconfig.json --noEmit"
43
43
  },
44
44
  "dependencies": {
45
- "@typescript-eslint/types": "5.57.1",
46
- "@typescript-eslint/visitor-keys": "5.57.1",
45
+ "@typescript-eslint/types": "5.58.0",
46
+ "@typescript-eslint/visitor-keys": "5.58.0",
47
47
  "debug": "^4.3.4",
48
48
  "globby": "^11.1.0",
49
49
  "is-glob": "^4.0.3",
@@ -81,5 +81,5 @@
81
81
  ]
82
82
  }
83
83
  },
84
- "gitHead": "772b19cd4b3d565670c07a1a42b36ee082a20387"
84
+ "gitHead": "0c6b63658aa5b01188480150fd777a1fa9b277eb"
85
85
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/utils",
3
- "version": "5.57.1",
3
+ "version": "5.58.0",
4
4
  "description": "Utilities for working with TypeScript + ESLint together",
5
5
  "keywords": [
6
6
  "eslint",
@@ -42,9 +42,9 @@
42
42
  "@eslint-community/eslint-utils": "^4.2.0",
43
43
  "@types/json-schema": "^7.0.9",
44
44
  "@types/semver": "^7.3.12",
45
- "@typescript-eslint/scope-manager": "5.57.1",
46
- "@typescript-eslint/types": "5.57.1",
47
- "@typescript-eslint/typescript-estree": "5.57.1",
45
+ "@typescript-eslint/scope-manager": "5.58.0",
46
+ "@typescript-eslint/types": "5.58.0",
47
+ "@typescript-eslint/typescript-estree": "5.58.0",
48
48
  "eslint-scope": "^5.1.1",
49
49
  "semver": "^7.3.7"
50
50
  },
@@ -52,7 +52,7 @@
52
52
  "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@typescript-eslint/parser": "5.57.1",
55
+ "@typescript-eslint/parser": "5.58.0",
56
56
  "typescript": "*"
57
57
  },
58
58
  "funding": {
@@ -66,5 +66,5 @@
66
66
  ]
67
67
  }
68
68
  },
69
- "gitHead": "772b19cd4b3d565670c07a1a42b36ee082a20387"
69
+ "gitHead": "0c6b63658aa5b01188480150fd777a1fa9b277eb"
70
70
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/visitor-keys",
3
- "version": "5.57.1",
3
+ "version": "5.58.0",
4
4
  "description": "Visitor keys used to help traverse the TypeScript-ESTree AST",
5
5
  "keywords": [
6
6
  "eslint",
@@ -39,7 +39,7 @@
39
39
  "typecheck": "tsc -p tsconfig.json --noEmit"
40
40
  },
41
41
  "dependencies": {
42
- "@typescript-eslint/types": "5.57.1",
42
+ "@typescript-eslint/types": "5.58.0",
43
43
  "eslint-visitor-keys": "^3.3.0"
44
44
  },
45
45
  "devDependencies": {
@@ -56,5 +56,5 @@
56
56
  ]
57
57
  }
58
58
  },
59
- "gitHead": "772b19cd4b3d565670c07a1a42b36ee082a20387"
59
+ "gitHead": "0c6b63658aa5b01188480150fd777a1fa9b277eb"
60
60
  }
@@ -110,6 +110,9 @@ Options:
110
110
  -l --loose
111
111
  Interpret versions and ranges loosely
112
112
 
113
+ -n <0|1>
114
+ This is the base to be used for the prerelease identifier.
115
+
113
116
  -p --include-prerelease
114
117
  Always include prerelease versions in range matching
115
118
 
@@ -232,6 +235,24 @@ $ semver 1.2.4-beta.0 -i prerelease
232
235
  1.2.4-beta.1
233
236
  ```
234
237
 
238
+ #### Prerelease Identifier Base
239
+
240
+ The method `.inc` takes an optional parameter 'identifierBase' string
241
+ that will let you let your prerelease number as zero-based or one-based.
242
+ If you do not specify this parameter, it will default to zero-based.
243
+
244
+ ```javascript
245
+ semver.inc('1.2.3', 'prerelease', 'beta', '1')
246
+ // '1.2.4-beta.1'
247
+ ```
248
+
249
+ command-line example:
250
+
251
+ ```bash
252
+ $ semver 1.2.3 -i prerelease --preid beta -n 1
253
+ 1.2.4-beta.1
254
+ ```
255
+
235
256
  ### Advanced Range Syntax
236
257
 
237
258
  Advanced range syntax desugars to primitive comparators in
@@ -513,6 +534,40 @@ ex.
513
534
  * `s.clean(' 2.1.5 ')`: `'2.1.5'`
514
535
  * `s.clean('~1.0.0')`: `null`
515
536
 
537
+ ## Constants
538
+
539
+ As a convenience, helper constants are exported to provide information about what `node-semver` supports:
540
+
541
+ ### `RELEASE_TYPES`
542
+
543
+ - major
544
+ - premajor
545
+ - minor
546
+ - preminor
547
+ - patch
548
+ - prepatch
549
+ - prerelease
550
+
551
+ ```
552
+ const semver = require('semver');
553
+
554
+ if (semver.RELEASE_TYPES.includes(arbitraryUserInput)) {
555
+ console.log('This is a valid release type!');
556
+ } else {
557
+ console.warn('This is NOT a valid release type!');
558
+ }
559
+ ```
560
+
561
+ ### `SEMVER_SPEC_VERSION`
562
+
563
+ 2.0.0
564
+
565
+ ```
566
+ const semver = require('semver');
567
+
568
+ console.log('We are currently using the semver specification version:', semver.SEMVER_SPEC_VERSION);
569
+ ```
570
+
516
571
  ## Exported Modules
517
572
 
518
573
  <!--
@@ -566,3 +621,4 @@ The following modules are available:
566
621
  * `require('semver/ranges/outside')`
567
622
  * `require('semver/ranges/to-comparators')`
568
623
  * `require('semver/ranges/valid')`
624
+
@@ -23,7 +23,10 @@ let rtl = false
23
23
 
24
24
  let identifier
25
25
 
26
+ let identifierBase
27
+
26
28
  const semver = require('../')
29
+ const parseOptions = require('../internal/parse-options')
27
30
 
28
31
  let reverse = false
29
32
 
@@ -71,6 +74,9 @@ const main = () => {
71
74
  case '-r': case '--range':
72
75
  range.push(argv.shift())
73
76
  break
77
+ case '-n':
78
+ identifierBase = argv.shift()
79
+ break
74
80
  case '-c': case '--coerce':
75
81
  coerce = true
76
82
  break
@@ -88,7 +94,7 @@ const main = () => {
88
94
  }
89
95
  }
90
96
 
91
- options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
97
+ options = parseOptions({ loose, includePrerelease, rtl })
92
98
 
93
99
  versions = versions.map((v) => {
94
100
  return coerce ? (semver.coerce(v, options) || { version: v }).version : v
@@ -127,7 +133,7 @@ const success = () => {
127
133
  }).map((v) => {
128
134
  return semver.clean(v, options)
129
135
  }).map((v) => {
130
- return inc ? semver.inc(v, inc, options, identifier) : v
136
+ return inc ? semver.inc(v, inc, options, identifier, identifierBase) : v
131
137
  }).forEach((v, i, _) => {
132
138
  console.log(v)
133
139
  })
@@ -78,13 +78,6 @@ class Comparator {
78
78
  throw new TypeError('a Comparator is required')
79
79
  }
80
80
 
81
- if (!options || typeof options !== 'object') {
82
- options = {
83
- loose: !!options,
84
- includePrerelease: false,
85
- }
86
- }
87
-
88
81
  if (this.operator === '') {
89
82
  if (this.value === '') {
90
83
  return true
@@ -97,32 +90,43 @@ class Comparator {
97
90
  return new Range(this.value, options).test(comp.semver)
98
91
  }
99
92
 
100
- const sameDirectionIncreasing =
101
- (this.operator === '>=' || this.operator === '>') &&
102
- (comp.operator === '>=' || comp.operator === '>')
103
- const sameDirectionDecreasing =
104
- (this.operator === '<=' || this.operator === '<') &&
105
- (comp.operator === '<=' || comp.operator === '<')
106
- const sameSemVer = this.semver.version === comp.semver.version
107
- const differentDirectionsInclusive =
108
- (this.operator === '>=' || this.operator === '<=') &&
109
- (comp.operator === '>=' || comp.operator === '<=')
110
- const oppositeDirectionsLessThan =
111
- cmp(this.semver, '<', comp.semver, options) &&
112
- (this.operator === '>=' || this.operator === '>') &&
113
- (comp.operator === '<=' || comp.operator === '<')
114
- const oppositeDirectionsGreaterThan =
115
- cmp(this.semver, '>', comp.semver, options) &&
116
- (this.operator === '<=' || this.operator === '<') &&
117
- (comp.operator === '>=' || comp.operator === '>')
118
-
119
- return (
120
- sameDirectionIncreasing ||
121
- sameDirectionDecreasing ||
122
- (sameSemVer && differentDirectionsInclusive) ||
123
- oppositeDirectionsLessThan ||
124
- oppositeDirectionsGreaterThan
125
- )
93
+ options = parseOptions(options)
94
+
95
+ // Special cases where nothing can possibly be lower
96
+ if (options.includePrerelease &&
97
+ (this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
98
+ return false
99
+ }
100
+ if (!options.includePrerelease &&
101
+ (this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
102
+ return false
103
+ }
104
+
105
+ // Same direction increasing (> or >=)
106
+ if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
107
+ return true
108
+ }
109
+ // Same direction decreasing (< or <=)
110
+ if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
111
+ return true
112
+ }
113
+ // same SemVer and both sides are inclusive (<= or >=)
114
+ if (
115
+ (this.semver.version === comp.semver.version) &&
116
+ this.operator.includes('=') && comp.operator.includes('=')) {
117
+ return true
118
+ }
119
+ // opposite directions less than
120
+ if (cmp(this.semver, '<', comp.semver, options) &&
121
+ this.operator.startsWith('>') && comp.operator.startsWith('<')) {
122
+ return true
123
+ }
124
+ // opposite directions greater than
125
+ if (cmp(this.semver, '>', comp.semver, options) &&
126
+ this.operator.startsWith('<') && comp.operator.startsWith('>')) {
127
+ return true
128
+ }
129
+ return false
126
130
  }
127
131
  }
128
132
 
@@ -81,8 +81,10 @@ class Range {
81
81
 
82
82
  // memoize range parsing for performance.
83
83
  // this is a very hot path, and fully deterministic.
84
- const memoOpts = Object.keys(this.options).join(',')
85
- const memoKey = `parseRange:${memoOpts}:${range}`
84
+ const memoOpts =
85
+ (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) |
86
+ (this.options.loose && FLAG_LOOSE)
87
+ const memoKey = memoOpts + ':' + range
86
88
  const cached = cache.get(memoKey)
87
89
  if (cached) {
88
90
  return cached
@@ -190,6 +192,7 @@ class Range {
190
192
  return false
191
193
  }
192
194
  }
195
+
193
196
  module.exports = Range
194
197
 
195
198
  const LRU = require('lru-cache')
@@ -206,6 +209,7 @@ const {
206
209
  tildeTrimReplace,
207
210
  caretTrimReplace,
208
211
  } = require('../internal/re')
212
+ const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require('../internal/constants')
209
213
 
210
214
  const isNullSet = c => c.value === '<0.0.0-0'
211
215
  const isAny = c => c.value === ''
@@ -175,36 +175,36 @@ class SemVer {
175
175
 
176
176
  // preminor will bump the version up to the next minor release, and immediately
177
177
  // down to pre-release. premajor and prepatch work the same way.
178
- inc (release, identifier) {
178
+ inc (release, identifier, identifierBase) {
179
179
  switch (release) {
180
180
  case 'premajor':
181
181
  this.prerelease.length = 0
182
182
  this.patch = 0
183
183
  this.minor = 0
184
184
  this.major++
185
- this.inc('pre', identifier)
185
+ this.inc('pre', identifier, identifierBase)
186
186
  break
187
187
  case 'preminor':
188
188
  this.prerelease.length = 0
189
189
  this.patch = 0
190
190
  this.minor++
191
- this.inc('pre', identifier)
191
+ this.inc('pre', identifier, identifierBase)
192
192
  break
193
193
  case 'prepatch':
194
194
  // If this is already a prerelease, it will bump to the next version
195
195
  // drop any prereleases that might already exist, since they are not
196
196
  // relevant at this point.
197
197
  this.prerelease.length = 0
198
- this.inc('patch', identifier)
199
- this.inc('pre', identifier)
198
+ this.inc('patch', identifier, identifierBase)
199
+ this.inc('pre', identifier, identifierBase)
200
200
  break
201
201
  // If the input is a non-prerelease version, this acts the same as
202
202
  // prepatch.
203
203
  case 'prerelease':
204
204
  if (this.prerelease.length === 0) {
205
- this.inc('patch', identifier)
205
+ this.inc('patch', identifier, identifierBase)
206
206
  }
207
- this.inc('pre', identifier)
207
+ this.inc('pre', identifier, identifierBase)
208
208
  break
209
209
 
210
210
  case 'major':
@@ -263,14 +263,15 @@ class SemVer {
263
263
  }
264
264
  }
265
265
  if (identifier) {
266
+ const base = Number(identifierBase) ? 1 : 0
266
267
  // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
267
268
  // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
268
269
  if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
269
270
  if (isNaN(this.prerelease[1])) {
270
- this.prerelease = [identifier, 0]
271
+ this.prerelease = [identifier, base]
271
272
  }
272
273
  } else {
273
- this.prerelease = [identifier, 0]
274
+ this.prerelease = [identifier, base]
274
275
  }
275
276
  }
276
277
  break
@@ -2,19 +2,35 @@ const parse = require('./parse')
2
2
  const eq = require('./eq')
3
3
 
4
4
  const diff = (version1, version2) => {
5
- if (eq(version1, version2)) {
5
+ const v1 = parse(version1)
6
+ const v2 = parse(version2)
7
+ if (eq(v1, v2)) {
6
8
  return null
7
9
  } else {
8
- const v1 = parse(version1)
9
- const v2 = parse(version2)
10
10
  const hasPre = v1.prerelease.length || v2.prerelease.length
11
11
  const prefix = hasPre ? 'pre' : ''
12
12
  const defaultResult = hasPre ? 'prerelease' : ''
13
- for (const key in v1) {
14
- if (key === 'major' || key === 'minor' || key === 'patch') {
15
- if (v1[key] !== v2[key]) {
16
- return prefix + key
17
- }
13
+
14
+ if (v1.major !== v2.major) {
15
+ return prefix + 'major'
16
+ }
17
+ if (v1.minor !== v2.minor) {
18
+ return prefix + 'minor'
19
+ }
20
+
21
+ if (v1.patch !== v2.patch) {
22
+ return prefix + 'patch'
23
+ }
24
+
25
+ if (!v1.prerelease.length || !v2.prerelease.length) {
26
+ if (v1.patch) {
27
+ return 'patch'
28
+ }
29
+ if (v1.minor) {
30
+ return 'minor'
31
+ }
32
+ if (v1.major) {
33
+ return 'major'
18
34
  }
19
35
  }
20
36
  return defaultResult // may be undefined
@@ -1,7 +1,8 @@
1
1
  const SemVer = require('../classes/semver')
2
2
 
3
- const inc = (version, release, options, identifier) => {
3
+ const inc = (version, release, options, identifier, identifierBase) => {
4
4
  if (typeof (options) === 'string') {
5
+ identifierBase = identifier
5
6
  identifier = options
6
7
  options = undefined
7
8
  }
@@ -10,7 +11,7 @@ const inc = (version, release, options, identifier) => {
10
11
  return new SemVer(
11
12
  version instanceof SemVer ? version.version : version,
12
13
  options
13
- ).inc(release, identifier).version
14
+ ).inc(release, identifier, identifierBase).version
14
15
  } catch (er) {
15
16
  return null
16
17
  }
@@ -1,11 +1,6 @@
1
1
  const { MAX_LENGTH } = require('../internal/constants')
2
- const { re, t } = require('../internal/re')
3
2
  const SemVer = require('../classes/semver')
4
-
5
- const parseOptions = require('../internal/parse-options')
6
3
  const parse = (version, options) => {
7
- options = parseOptions(options)
8
-
9
4
  if (version instanceof SemVer) {
10
5
  return version
11
6
  }
@@ -18,11 +13,6 @@ const parse = (version, options) => {
18
13
  return null
19
14
  }
20
15
 
21
- const r = options.loose ? re[t.LOOSE] : re[t.FULL]
22
- if (!r.test(version)) {
23
- return null
24
- }
25
-
26
16
  try {
27
17
  return new SemVer(version, options)
28
18
  } catch (er) {
@@ -83,6 +83,7 @@ module.exports = {
83
83
  src: internalRe.src,
84
84
  tokens: internalRe.t,
85
85
  SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
86
+ RELEASE_TYPES: constants.RELEASE_TYPES,
86
87
  compareIdentifiers: identifiers.compareIdentifiers,
87
88
  rcompareIdentifiers: identifiers.rcompareIdentifiers,
88
89
  }
@@ -9,9 +9,22 @@ const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
9
9
  // Max safe segment length for coercion.
10
10
  const MAX_SAFE_COMPONENT_LENGTH = 16
11
11
 
12
+ const RELEASE_TYPES = [
13
+ 'major',
14
+ 'premajor',
15
+ 'minor',
16
+ 'preminor',
17
+ 'patch',
18
+ 'prepatch',
19
+ 'prerelease',
20
+ ]
21
+
12
22
  module.exports = {
13
- SEMVER_SPEC_VERSION,
14
23
  MAX_LENGTH,
15
- MAX_SAFE_INTEGER,
16
24
  MAX_SAFE_COMPONENT_LENGTH,
25
+ MAX_SAFE_INTEGER,
26
+ RELEASE_TYPES,
27
+ SEMVER_SPEC_VERSION,
28
+ FLAG_INCLUDE_PRERELEASE: 0b001,
29
+ FLAG_LOOSE: 0b010,
17
30
  }
@@ -1,11 +1,15 @@
1
- // parse out just the options we care about so we always get a consistent
2
- // obj with keys in a consistent order.
3
- const opts = ['includePrerelease', 'loose', 'rtl']
4
- const parseOptions = options =>
5
- !options ? {}
6
- : typeof options !== 'object' ? { loose: true }
7
- : opts.filter(k => options[k]).reduce((o, k) => {
8
- o[k] = true
9
- return o
10
- }, {})
1
+ // parse out just the options we care about
2
+ const looseOption = Object.freeze({ loose: true })
3
+ const emptyOpts = Object.freeze({ })
4
+ const parseOptions = options => {
5
+ if (!options) {
6
+ return emptyOpts
7
+ }
8
+
9
+ if (typeof options !== 'object') {
10
+ return looseOption
11
+ }
12
+
13
+ return options
14
+ }
11
15
  module.exports = parseOptions
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semver",
3
- "version": "7.3.8",
3
+ "version": "7.4.0",
4
4
  "description": "The semantic version parser used by npm.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,8 +13,8 @@
13
13
  "template-oss-apply": "template-oss-apply --force"
14
14
  },
15
15
  "devDependencies": {
16
- "@npmcli/eslint-config": "^3.0.1",
17
- "@npmcli/template-oss": "4.4.4",
16
+ "@npmcli/eslint-config": "^4.0.0",
17
+ "@npmcli/template-oss": "4.13.0",
18
18
  "tap": "^16.0.0"
19
19
  },
20
20
  "license": "ISC",
@@ -53,9 +53,8 @@
53
53
  "author": "GitHub Inc.",
54
54
  "templateOSS": {
55
55
  "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
56
- "version": "4.4.4",
56
+ "version": "4.13.0",
57
57
  "engines": ">=10",
58
- "content": "./scripts",
59
58
  "ciVersions": [
60
59
  "10.0.0",
61
60
  "10.x",
@@ -64,6 +63,7 @@
64
63
  "16.x",
65
64
  "18.x"
66
65
  ],
66
+ "npmSpec": "8",
67
67
  "distPaths": [
68
68
  "classes/",
69
69
  "functions/",
@@ -81,6 +81,7 @@
81
81
  "/index.js",
82
82
  "/preload.js",
83
83
  "/range.bnf"
84
- ]
84
+ ],
85
+ "publish": "true"
85
86
  }
86
87
  }