semver 5.4.1 → 5.7.0

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # changes log
2
+
3
+ ## 5.7
4
+
5
+ * Add `minVersion` method
6
+
7
+ ## 5.6
8
+
9
+ * Move boolean `loose` param to an options object, with
10
+ backwards-compatibility protection.
11
+ * Add ability to opt out of special prerelease version handling with
12
+ the `includePrerelease` option flag.
13
+
14
+ ## 5.5
15
+
16
+ * Add version coercion capabilities
17
+
18
+ ## 5.4
19
+
20
+ * Add intersection checking
21
+
22
+ ## 5.3
23
+
24
+ * Add `minSatisfying` method
25
+
26
+ ## 5.2
27
+
28
+ * Add `prerelease(v)` that returns prerelease components
29
+
30
+ ## 5.1
31
+
32
+ * Add Backus-Naur for ranges
33
+ * Remove excessively cute inspection methods
34
+
35
+ ## 5.0
36
+
37
+ * Remove AMD/Browserified build artifacts
38
+ * Fix ltr and gtr when using the `*` range
39
+ * Fix for range `*` with a prerelease identifier
package/README.md CHANGED
@@ -20,6 +20,9 @@ semver.clean(' =v1.2.3 ') // '1.2.3'
20
20
  semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true
21
21
  semver.gt('1.2.3', '9.8.7') // false
22
22
  semver.lt('1.2.3', '9.8.7') // true
23
+ semver.minVersion('>=1.0.0') // '1.0.0'
24
+ semver.valid(semver.coerce('v2')) // '2.0.0'
25
+ semver.valid(semver.coerce('42.6.7.9.3-alpha')) // '42.6.7'
23
26
  ```
24
27
 
25
28
  As a command-line utility:
@@ -27,9 +30,7 @@ As a command-line utility:
27
30
  ```
28
31
  $ semver -h
29
32
 
30
- SemVer 5.3.0
31
-
32
- A JavaScript implementation of the http://semver.org/ specification
33
+ A JavaScript implementation of the https://semver.org/ specification
33
34
  Copyright Isaac Z. Schlueter
34
35
 
35
36
  Usage: semver [options] <version> [<version> [...]]
@@ -52,6 +53,13 @@ Options:
52
53
  -l --loose
53
54
  Interpret versions and ranges loosely
54
55
 
56
+ -p --include-prerelease
57
+ Always include prerelease versions in range matching
58
+
59
+ -c --coerce
60
+ Coerce a string into SemVer if possible
61
+ (does not imply --loose)
62
+
55
63
  Program exits successfully if any valid version satisfies
56
64
  all supplied ranges, and prints all satisfying versions.
57
65
 
@@ -64,7 +72,7 @@ multiple versions to the utility will just sort them.
64
72
  ## Versions
65
73
 
66
74
  A "version" is described by the `v2.0.0` specification found at
67
- <http://semver.org/>.
75
+ <https://semver.org/>.
68
76
 
69
77
  A leading `"="` or `"v"` character is stripped off and ignored.
70
78
 
@@ -130,6 +138,13 @@ the user is indicating that they are aware of the risk. However, it
130
138
  is still not appropriate to assume that they have opted into taking a
131
139
  similar risk on the *next* set of prerelease versions.
132
140
 
141
+ Note that this behavior can be suppressed (treating all prerelease
142
+ versions as if they were normal versions, for the purpose of range
143
+ matching) by setting the `includePrerelease` flag on the options
144
+ object to any
145
+ [functions](https://github.com/npm/node-semver#functions) that do
146
+ range matching.
147
+
133
148
  #### Prerelease Identifiers
134
149
 
135
150
  The method `.inc` takes an additional `identifier` string argument that
@@ -268,7 +283,7 @@ logical-or ::= ( ' ' ) * '||' ( ' ' ) *
268
283
  range ::= hyphen | simple ( ' ' simple ) * | ''
269
284
  hyphen ::= partial ' - ' partial
270
285
  simple ::= primitive | partial | tilde | caret
271
- primitive ::= ( '<' | '>' | '>=' | '<=' | '=' | ) partial
286
+ primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial
272
287
  partial ::= xr ( '.' xr ( '.' xr qualifier ? )? )?
273
288
  xr ::= 'x' | 'X' | '*' | nr
274
289
  nr ::= '0' | ['1'-'9'] ( ['0'-'9'] ) *
@@ -283,9 +298,19 @@ part ::= nr | [-0-9A-Za-z]+
283
298
 
284
299
  ## Functions
285
300
 
286
- All methods and classes take a final `loose` boolean argument that, if
287
- true, will be more forgiving about not-quite-valid semver strings.
288
- The resulting output will always be 100% strict, of course.
301
+ All methods and classes take a final `options` object argument. All
302
+ options in this object are `false` by default. The options supported
303
+ are:
304
+
305
+ - `loose` Be more forgiving about not-quite-valid semver strings.
306
+ (Any resulting output will always be 100% strict compliant, of
307
+ course.) For backwards compatibility reasons, if the `options`
308
+ argument is a boolean value instead of an object, it is interpreted
309
+ to be the `loose` param.
310
+ - `includePrerelease` Set to suppress the [default
311
+ behavior](https://github.com/npm/node-semver#prerelease-tags) of
312
+ excluding prerelease tagged versions from ranges unless they are
313
+ explicitly opted into.
289
314
 
290
315
  Strict-mode Comparators and Ranges will be strict about the SemVer
291
316
  strings that they parse.
@@ -308,6 +333,8 @@ strings that they parse.
308
333
  * `patch(v)`: Return the patch version number.
309
334
  * `intersects(r1, r2, loose)`: Return true if the two supplied ranges
310
335
  or comparators intersect.
336
+ * `parse(v)`: Attempt to parse a string as a semantic version, returning either
337
+ a `SemVer` object or `null`.
311
338
 
312
339
  ### Comparison
313
340
 
@@ -344,6 +371,8 @@ strings that they parse.
344
371
  that satisfies the range, or `null` if none of them do.
345
372
  * `minSatisfying(versions, range)`: Return the lowest version in the list
346
373
  that satisfies the range, or `null` if none of them do.
374
+ * `minVersion(range)`: Return the lowest version that can possibly match
375
+ the given range.
347
376
  * `gtr(version, range)`: Return `true` if version is greater than all the
348
377
  versions possible in the range.
349
378
  * `ltr(version, range)`: Return `true` if version is less than all the
@@ -364,3 +393,19 @@ satisfy the range.
364
393
 
365
394
  If you want to know if a version satisfies or does not satisfy a
366
395
  range, use the `satisfies(version, range)` function.
396
+
397
+ ### Coercion
398
+
399
+ * `coerce(version)`: Coerces a string to semver if possible
400
+
401
+ This aims to provide a very forgiving translation of a non-semver
402
+ string to semver. It looks for the first digit in a string, and
403
+ consumes all remaining characters which satisfy at least a partial semver
404
+ (e.g., `1`, `1.2`, `1.2.3`) up to the max permitted length (256 characters).
405
+ Longer versions are simply truncated (`4.6.3.9.2-alpha2` becomes `4.6.3`).
406
+ All surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes `3.4.0`).
407
+ Only text which lacks digits will fail coercion (`version one` is not valid).
408
+ The maximum length for any semver component considered for coercion is 16 characters;
409
+ longer components will be ignored (`10000000000000000.4.7.4` becomes `4.7.4`).
410
+ The maximum value for any semver component is `Integer.MAX_SAFE_INTEGER || (2**53 - 1)`;
411
+ higher value components are invalid (`9999999999999999.4.7.4` is likely invalid).
package/bin/semver CHANGED
@@ -4,17 +4,28 @@
4
4
  // any supplied version is valid and passes all tests.
5
5
 
6
6
  var argv = process.argv.slice(2)
7
- , versions = []
8
- , range = []
9
- , gt = []
10
- , lt = []
11
- , eq = []
12
- , inc = null
13
- , version = require("../package.json").version
14
- , loose = false
15
- , identifier = undefined
16
- , semver = require("../semver")
17
- , reverse = false
7
+
8
+ var versions = []
9
+
10
+ var range = []
11
+
12
+ var inc = null
13
+
14
+ var version = require('../package.json').version
15
+
16
+ var loose = false
17
+
18
+ var includePrerelease = false
19
+
20
+ var coerce = false
21
+
22
+ var identifier
23
+
24
+ var semver = require('../semver')
25
+
26
+ var reverse = false
27
+
28
+ var options = {}
18
29
 
19
30
  main()
20
31
 
@@ -22,39 +33,45 @@ function main () {
22
33
  if (!argv.length) return help()
23
34
  while (argv.length) {
24
35
  var a = argv.shift()
25
- var i = a.indexOf('=')
26
- if (i !== -1) {
27
- a = a.slice(0, i)
28
- argv.unshift(a.slice(i + 1))
36
+ var indexOfEqualSign = a.indexOf('=')
37
+ if (indexOfEqualSign !== -1) {
38
+ a = a.slice(0, indexOfEqualSign)
39
+ argv.unshift(a.slice(indexOfEqualSign + 1))
29
40
  }
30
41
  switch (a) {
31
- case "-rv": case "-rev": case "--rev": case "--reverse":
42
+ case '-rv': case '-rev': case '--rev': case '--reverse':
32
43
  reverse = true
33
44
  break
34
- case "-l": case "--loose":
45
+ case '-l': case '--loose':
35
46
  loose = true
36
47
  break
37
- case "-v": case "--version":
48
+ case '-p': case '--include-prerelease':
49
+ includePrerelease = true
50
+ break
51
+ case '-v': case '--version':
38
52
  versions.push(argv.shift())
39
53
  break
40
- case "-i": case "--inc": case "--increment":
54
+ case '-i': case '--inc': case '--increment':
41
55
  switch (argv[0]) {
42
- case "major": case "minor": case "patch": case "prerelease":
43
- case "premajor": case "preminor": case "prepatch":
56
+ case 'major': case 'minor': case 'patch': case 'prerelease':
57
+ case 'premajor': case 'preminor': case 'prepatch':
44
58
  inc = argv.shift()
45
59
  break
46
60
  default:
47
- inc = "patch"
61
+ inc = 'patch'
48
62
  break
49
63
  }
50
64
  break
51
- case "--preid":
65
+ case '--preid':
52
66
  identifier = argv.shift()
53
67
  break
54
- case "-r": case "--range":
68
+ case '-r': case '--range':
55
69
  range.push(argv.shift())
56
70
  break
57
- case "-h": case "--help": case "-?":
71
+ case '-c': case '--coerce':
72
+ coerce = true
73
+ break
74
+ case '-h': case '--help': case '-?':
58
75
  return help()
59
76
  default:
60
77
  versions.push(a)
@@ -62,16 +79,19 @@ function main () {
62
79
  }
63
80
  }
64
81
 
65
- versions = versions.filter(function (v) {
66
- return semver.valid(v, loose)
82
+ var options = { loose: loose, includePrerelease: includePrerelease }
83
+
84
+ versions = versions.map(function (v) {
85
+ return coerce ? (semver.coerce(v) || { version: v }).version : v
86
+ }).filter(function (v) {
87
+ return semver.valid(v)
67
88
  })
68
89
  if (!versions.length) return fail()
69
- if (inc && (versions.length !== 1 || range.length))
70
- return failInc()
90
+ if (inc && (versions.length !== 1 || range.length)) { return failInc() }
71
91
 
72
- for (var i = 0, l = range.length; i < l ; i ++) {
92
+ for (var i = 0, l = range.length; i < l; i++) {
73
93
  versions = versions.filter(function (v) {
74
- return semver.satisfies(v, range[i], loose)
94
+ return semver.satisfies(v, range[i], options)
75
95
  })
76
96
  if (!versions.length) return fail()
77
97
  }
@@ -79,55 +99,62 @@ function main () {
79
99
  }
80
100
 
81
101
  function failInc () {
82
- console.error("--inc can only be used on a single version with no range")
102
+ console.error('--inc can only be used on a single version with no range')
83
103
  fail()
84
104
  }
85
105
 
86
106
  function fail () { process.exit(1) }
87
107
 
88
108
  function success () {
89
- var compare = reverse ? "rcompare" : "compare"
109
+ var compare = reverse ? 'rcompare' : 'compare'
90
110
  versions.sort(function (a, b) {
91
- return semver[compare](a, b, loose)
111
+ return semver[compare](a, b, options)
92
112
  }).map(function (v) {
93
- return semver.clean(v, loose)
113
+ return semver.clean(v, options)
94
114
  }).map(function (v) {
95
- return inc ? semver.inc(v, inc, loose, identifier) : v
96
- }).forEach(function (v,i,_) { console.log(v) })
115
+ return inc ? semver.inc(v, inc, options, identifier) : v
116
+ }).forEach(function (v, i, _) { console.log(v) })
97
117
  }
98
118
 
99
119
  function help () {
100
- console.log(["SemVer " + version
101
- ,""
102
- ,"A JavaScript implementation of the http://semver.org/ specification"
103
- ,"Copyright Isaac Z. Schlueter"
104
- ,""
105
- ,"Usage: semver [options] <version> [<version> [...]]"
106
- ,"Prints valid versions sorted by SemVer precedence"
107
- ,""
108
- ,"Options:"
109
- ,"-r --range <range>"
110
- ," Print versions that match the specified range."
111
- ,""
112
- ,"-i --increment [<level>]"
113
- ," Increment a version by the specified level. Level can"
114
- ," be one of: major, minor, patch, premajor, preminor,"
115
- ," prepatch, or prerelease. Default level is 'patch'."
116
- ," Only one version may be specified."
117
- ,""
118
- ,"--preid <identifier>"
119
- ," Identifier to be used to prefix premajor, preminor,"
120
- ," prepatch or prerelease version increments."
121
- ,""
122
- ,"-l --loose"
123
- ," Interpret versions and ranges loosely"
124
- ,""
125
- ,"Program exits successfully if any valid version satisfies"
126
- ,"all supplied ranges, and prints all satisfying versions."
127
- ,""
128
- ,"If no satisfying versions are found, then exits failure."
129
- ,""
130
- ,"Versions are printed in ascending order, so supplying"
131
- ,"multiple versions to the utility will just sort them."
132
- ].join("\n"))
120
+ console.log(['SemVer ' + version,
121
+ '',
122
+ 'A JavaScript implementation of the https://semver.org/ specification',
123
+ 'Copyright Isaac Z. Schlueter',
124
+ '',
125
+ 'Usage: semver [options] <version> [<version> [...]]',
126
+ 'Prints valid versions sorted by SemVer precedence',
127
+ '',
128
+ 'Options:',
129
+ '-r --range <range>',
130
+ ' Print versions that match the specified range.',
131
+ '',
132
+ '-i --increment [<level>]',
133
+ ' Increment a version by the specified level. Level can',
134
+ ' be one of: major, minor, patch, premajor, preminor,',
135
+ " prepatch, or prerelease. Default level is 'patch'.",
136
+ ' Only one version may be specified.',
137
+ '',
138
+ '--preid <identifier>',
139
+ ' Identifier to be used to prefix premajor, preminor,',
140
+ ' prepatch or prerelease version increments.',
141
+ '',
142
+ '-l --loose',
143
+ ' Interpret versions and ranges loosely',
144
+ '',
145
+ '-p --include-prerelease',
146
+ ' Always include prerelease versions in range matching',
147
+ '',
148
+ '-c --coerce',
149
+ ' Coerce a string into SemVer if possible',
150
+ ' (does not imply --loose)',
151
+ '',
152
+ 'Program exits successfully if any valid version satisfies',
153
+ 'all supplied ranges, and prints all satisfying versions.',
154
+ '',
155
+ 'If no satisfying versions are found, then exits failure.',
156
+ '',
157
+ 'Versions are printed in ascending order, so supplying',
158
+ 'multiple versions to the utility will just sort them.'
159
+ ].join('\n'))
133
160
  }
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "semver",
3
- "version": "5.4.1",
3
+ "version": "5.7.0",
4
4
  "description": "The semantic version parser used by npm.",
5
5
  "main": "semver.js",
6
6
  "scripts": {
7
- "test": "tap test/*.js --cov -J"
7
+ "test": "tap",
8
+ "preversion": "npm test",
9
+ "postversion": "npm publish",
10
+ "postpublish": "git push origin --all; git push origin --tags"
8
11
  },
9
12
  "devDependencies": {
10
- "tap": "^10.7.0"
13
+ "tap": "^13.0.0-rc.18"
11
14
  },
12
15
  "license": "ISC",
13
16
  "repository": "https://github.com/npm/node-semver",
@@ -18,5 +21,8 @@
18
21
  "bin",
19
22
  "range.bnf",
20
23
  "semver.js"
21
- ]
24
+ ],
25
+ "tap": {
26
+ "check-coverage": true
27
+ }
22
28
  }
package/range.bnf CHANGED
@@ -3,10 +3,10 @@ logical-or ::= ( ' ' ) * '||' ( ' ' ) *
3
3
  range ::= hyphen | simple ( ' ' simple ) * | ''
4
4
  hyphen ::= partial ' - ' partial
5
5
  simple ::= primitive | partial | tilde | caret
6
- primitive ::= ( '<' | '>' | '>=' | '<=' | '=' | ) partial
6
+ primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial
7
7
  partial ::= xr ( '.' xr ( '.' xr qualifier ? )? )?
8
8
  xr ::= 'x' | 'X' | '*' | nr
9
- nr ::= '0' | ['1'-'9'] ( ['0'-'9'] ) *
9
+ nr ::= '0' | [1-9] ( [0-9] ) *
10
10
  tilde ::= '~' partial
11
11
  caret ::= '^' partial
12
12
  qualifier ::= ( '-' pre )? ( '+' build )?