semver 3.0.1 → 4.1.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/semver.browser.js CHANGED
@@ -128,18 +128,18 @@ var XRANGEPLAIN = R++;
128
128
  src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' +
129
129
  '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
130
130
  '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
131
- '(?:(' + src[PRERELEASE] + ')' +
132
- ')?)?)?';
131
+ '(?:' + src[PRERELEASE] + ')?' +
132
+ src[BUILD] + '?' +
133
+ ')?)?';
133
134
 
134
135
  var XRANGEPLAINLOOSE = R++;
135
136
  src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
136
137
  '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
137
138
  '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
138
- '(?:(' + src[PRERELEASELOOSE] + ')' +
139
- ')?)?)?';
139
+ '(?:' + src[PRERELEASELOOSE] + ')?' +
140
+ src[BUILD] + '?' +
141
+ ')?)?';
140
142
 
141
- // >=2.x, for example, means >=2.0.0-0
142
- // <1.x would be the same as "<1.0.0-0", though.
143
143
  var XRANGE = R++;
144
144
  src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
145
145
  var XRANGELOOSE = R++;
@@ -236,7 +236,7 @@ function valid(version, loose) {
236
236
 
237
237
  exports.clean = clean;
238
238
  function clean(version, loose) {
239
- var s = parse(version.trim().replace(/^[=v]+/, ""), loose);
239
+ var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
240
240
  return s ? s.version : null;
241
241
  }
242
242
 
@@ -345,36 +345,55 @@ SemVer.prototype.comparePre = function(other) {
345
345
 
346
346
  // preminor will bump the version up to the next minor release, and immediately
347
347
  // down to pre-release. premajor and prepatch work the same way.
348
- SemVer.prototype.inc = function(release) {
348
+ SemVer.prototype.inc = function(release, identifier) {
349
349
  switch (release) {
350
350
  case 'premajor':
351
- this.inc('major');
352
- this.inc('pre');
351
+ this.prerelease.length = 0;
352
+ this.patch = 0;
353
+ this.minor = 0;
354
+ this.major++;
355
+ this.inc('pre', identifier);
353
356
  break;
354
357
  case 'preminor':
355
- this.inc('minor');
356
- this.inc('pre');
358
+ this.prerelease.length = 0;
359
+ this.patch = 0;
360
+ this.minor++;
361
+ this.inc('pre', identifier);
357
362
  break;
358
363
  case 'prepatch':
359
364
  // If this is already a prerelease, it will bump to the next version
360
365
  // drop any prereleases that might already exist, since they are not
361
366
  // relevant at this point.
362
367
  this.prerelease.length = 0;
363
- this.inc('patch');
364
- this.inc('pre');
368
+ this.inc('patch', identifier);
369
+ this.inc('pre', identifier);
365
370
  break;
366
371
  // If the input is a non-prerelease version, this acts the same as
367
372
  // prepatch.
368
373
  case 'prerelease':
369
374
  if (this.prerelease.length === 0)
370
- this.inc('patch');
371
- this.inc('pre');
375
+ this.inc('patch', identifier);
376
+ this.inc('pre', identifier);
372
377
  break;
378
+
373
379
  case 'major':
374
- this.major++;
375
- this.minor = -1;
380
+ // If this is a pre-major version, bump up to the same major version.
381
+ // Otherwise increment major.
382
+ // 1.0.0-5 bumps to 1.0.0
383
+ // 1.1.0 bumps to 2.0.0
384
+ if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0)
385
+ this.major++;
386
+ this.minor = 0;
387
+ this.patch = 0;
388
+ this.prerelease = [];
389
+ break;
376
390
  case 'minor':
377
- this.minor++;
391
+ // If this is a pre-minor version, bump up to the same minor version.
392
+ // Otherwise increment minor.
393
+ // 1.2.0-5 bumps to 1.2.0
394
+ // 1.2.1 bumps to 1.3.0
395
+ if (this.patch !== 0 || this.prerelease.length === 0)
396
+ this.minor++;
378
397
  this.patch = 0;
379
398
  this.prerelease = [];
380
399
  break;
@@ -387,7 +406,7 @@ SemVer.prototype.inc = function(release) {
387
406
  this.patch++;
388
407
  this.prerelease = [];
389
408
  break;
390
- // This probably shouldn't be used publically.
409
+ // This probably shouldn't be used publicly.
391
410
  // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
392
411
  case 'pre':
393
412
  if (this.prerelease.length === 0)
@@ -403,6 +422,15 @@ SemVer.prototype.inc = function(release) {
403
422
  if (i === -1) // didn't increment anything
404
423
  this.prerelease.push(0);
405
424
  }
425
+ if (identifier) {
426
+ // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
427
+ // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
428
+ if (this.prerelease[0] === identifier) {
429
+ if (isNaN(this.prerelease[1]))
430
+ this.prerelease = [identifier, 0];
431
+ } else
432
+ this.prerelease = [identifier, 0];
433
+ }
406
434
  break;
407
435
 
408
436
  default:
@@ -413,9 +441,14 @@ SemVer.prototype.inc = function(release) {
413
441
  };
414
442
 
415
443
  exports.inc = inc;
416
- function inc(version, release, loose) {
444
+ function inc(version, release, loose, identifier) {
445
+ if (typeof(loose) === 'string') {
446
+ identifier = loose;
447
+ loose = undefined;
448
+ }
449
+
417
450
  try {
418
- return new SemVer(version, loose).inc(release).version;
451
+ return new SemVer(version, loose).inc(release, identifier).version;
419
452
  } catch (er) {
420
453
  return null;
421
454
  }
@@ -508,8 +541,16 @@ exports.cmp = cmp;
508
541
  function cmp(a, op, b, loose) {
509
542
  var ret;
510
543
  switch (op) {
511
- case '===': ret = a === b; break;
512
- case '!==': ret = a !== b; break;
544
+ case '===':
545
+ if (typeof a === 'object') a = a.version;
546
+ if (typeof b === 'object') b = b.version;
547
+ ret = a === b;
548
+ break;
549
+ case '!==':
550
+ if (typeof a === 'object') a = a.version;
551
+ if (typeof b === 'object') b = b.version;
552
+ ret = a !== b;
553
+ break;
513
554
  case '': case '=': case '==': ret = eq(a, b, loose); break;
514
555
  case '!=': ret = neq(a, b, loose); break;
515
556
  case '>': ret = gt(a, b, loose); break;
@@ -541,6 +582,8 @@ function Comparator(comp, loose) {
541
582
  this.value = '';
542
583
  else
543
584
  this.value = this.operator + this.semver.version;
585
+
586
+ ;
544
587
  }
545
588
 
546
589
  var ANY = {};
@@ -558,21 +601,8 @@ Comparator.prototype.parse = function(comp) {
558
601
  // if it literally is just '>' or '' then allow anything.
559
602
  if (!m[2])
560
603
  this.semver = ANY;
561
- else {
604
+ else
562
605
  this.semver = new SemVer(m[2], this.loose);
563
-
564
- // <1.2.3-rc DOES allow 1.2.3-beta (has prerelease)
565
- // >=1.2.3 DOES NOT allow 1.2.3-beta
566
- // <=1.2.3 DOES allow 1.2.3-beta
567
- // However, <1.2.3 does NOT allow 1.2.3-beta,
568
- // even though `1.2.3-beta < 1.2.3`
569
- // The assumption is that the 1.2.3 version has something you
570
- // *don't* want, so we push the prerelease down to the minimum.
571
- if (this.operator === '<' && !this.semver.prerelease.length) {
572
- this.semver.prerelease = ['0'];
573
- this.semver.format();
574
- }
575
- }
576
606
  };
577
607
 
578
608
  Comparator.prototype.inspect = function() {
@@ -585,8 +615,14 @@ Comparator.prototype.toString = function() {
585
615
 
586
616
  Comparator.prototype.test = function(version) {
587
617
  ;
588
- return (this.semver === ANY) ? true :
589
- cmp(version, this.operator, this.semver, this.loose);
618
+
619
+ if (this.semver === ANY)
620
+ return true;
621
+
622
+ if (typeof version === 'string')
623
+ version = new SemVer(version, this.loose);
624
+
625
+ return cmp(version, this.operator, this.semver, this.loose);
590
626
  };
591
627
 
592
628
 
@@ -723,20 +759,20 @@ function replaceTilde(comp, loose) {
723
759
  if (isX(M))
724
760
  ret = '';
725
761
  else if (isX(m))
726
- ret = '>=' + M + '.0.0-0 <' + (+M + 1) + '.0.0-0';
762
+ ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
727
763
  else if (isX(p))
728
764
  // ~1.2 == >=1.2.0- <1.3.0-
729
- ret = '>=' + M + '.' + m + '.0-0 <' + M + '.' + (+m + 1) + '.0-0';
765
+ ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
730
766
  else if (pr) {
731
767
  ;
732
768
  if (pr.charAt(0) !== '-')
733
769
  pr = '-' + pr;
734
770
  ret = '>=' + M + '.' + m + '.' + p + pr +
735
- ' <' + M + '.' + (+m + 1) + '.0-0';
771
+ ' <' + M + '.' + (+m + 1) + '.0';
736
772
  } else
737
- // ~1.2.3 == >=1.2.3-0 <1.3.0-0
738
- ret = '>=' + M + '.' + m + '.' + p + '-0' +
739
- ' <' + M + '.' + (+m + 1) + '.0-0';
773
+ // ~1.2.3 == >=1.2.3 <1.3.0
774
+ ret = '>=' + M + '.' + m + '.' + p +
775
+ ' <' + M + '.' + (+m + 1) + '.0';
740
776
 
741
777
  ;
742
778
  return ret;
@@ -756,33 +792,48 @@ function replaceCarets(comp, loose) {
756
792
  }
757
793
 
758
794
  function replaceCaret(comp, loose) {
795
+ ;
759
796
  var r = loose ? re[CARETLOOSE] : re[CARET];
760
797
  return comp.replace(r, function(_, M, m, p, pr) {
761
798
  ;
762
799
  var ret;
763
- if (pr) {
764
- if (pr.charAt(0) !== '-')
765
- pr = '-' + pr;
766
- } else
767
- pr = '';
768
800
 
769
801
  if (isX(M))
770
802
  ret = '';
771
803
  else if (isX(m))
772
- ret = '>=' + M + '.0.0-0 <' + (+M + 1) + '.0.0-0';
804
+ ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
773
805
  else if (isX(p)) {
774
806
  if (M === '0')
775
- ret = '>=' + M + '.' + m + '.0-0 <' + M + '.' + (+m + 1) + '.0-0';
807
+ ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
776
808
  else
777
- ret = '>=' + M + '.' + m + '.0-0 <' + (+M + 1) + '.0.0-0';
778
- } else if (M === '0')
779
- ret = '=' + M + '.' + m + '.' + p + pr;
780
- else if (pr)
781
- ret = '>=' + M + '.' + m + '.' + p + pr +
782
- ' <' + (+M + 1) + '.0.0-0';
783
- else
784
- ret = '>=' + M + '.' + m + '.' + p + '-0' +
785
- ' <' + (+M + 1) + '.0.0-0';
809
+ ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
810
+ } else if (pr) {
811
+ ;
812
+ if (pr.charAt(0) !== '-')
813
+ pr = '-' + pr;
814
+ if (M === '0') {
815
+ if (m === '0')
816
+ ret = '>=' + M + '.' + m + '.' + p + pr +
817
+ ' <' + M + '.' + m + '.' + (+p + 1);
818
+ else
819
+ ret = '>=' + M + '.' + m + '.' + p + pr +
820
+ ' <' + M + '.' + (+m + 1) + '.0';
821
+ } else
822
+ ret = '>=' + M + '.' + m + '.' + p + pr +
823
+ ' <' + (+M + 1) + '.0.0';
824
+ } else {
825
+ ;
826
+ if (M === '0') {
827
+ if (m === '0')
828
+ ret = '>=' + M + '.' + m + '.' + p +
829
+ ' <' + M + '.' + m + '.' + (+p + 1);
830
+ else
831
+ ret = '>=' + M + '.' + m + '.' + p +
832
+ ' <' + M + '.' + (+m + 1) + '.0';
833
+ } else
834
+ ret = '>=' + M + '.' + m + '.' + p +
835
+ ' <' + (+M + 1) + '.0.0';
836
+ }
786
837
 
787
838
  ;
788
839
  return ret;
@@ -809,23 +860,27 @@ function replaceXRange(comp, loose) {
809
860
  if (gtlt === '=' && anyX)
810
861
  gtlt = '';
811
862
 
812
- if (gtlt && anyX) {
813
- // replace X with 0, and then append the -0 min-prerelease
814
- if (xM)
815
- M = 0;
863
+ if (xM) {
864
+ if (gtlt === '>' || gtlt === '<') {
865
+ // nothing is allowed
866
+ ret = '<0.0.0';
867
+ } else {
868
+ // nothing is forbidden
869
+ ret = '*';
870
+ }
871
+ } else if (gtlt && anyX) {
872
+ // replace X with 0
816
873
  if (xm)
817
874
  m = 0;
818
875
  if (xp)
819
876
  p = 0;
820
877
 
821
878
  if (gtlt === '>') {
822
- // >1 => >=2.0.0-0
823
- // >1.2 => >=1.3.0-0
824
- // >1.2.3 => >= 1.2.4-0
879
+ // >1 => >=2.0.0
880
+ // >1.2 => >=1.3.0
881
+ // >1.2.3 => >= 1.2.4
825
882
  gtlt = '>=';
826
- if (xM) {
827
- // no change
828
- } else if (xm) {
883
+ if (xm) {
829
884
  M = +M + 1;
830
885
  m = 0;
831
886
  p = 0;
@@ -833,20 +888,21 @@ function replaceXRange(comp, loose) {
833
888
  m = +m + 1;
834
889
  p = 0;
835
890
  }
891
+ } else if (gtlt === '<=') {
892
+ // <=0.7.x is actually <0.8.0, since any 0.7.x should
893
+ // pass. Similarly, <=7.x is actually <8.0.0, etc.
894
+ gtlt = '<'
895
+ if (xm)
896
+ M = +M + 1
897
+ else
898
+ m = +m + 1
836
899
  }
837
900
 
838
-
839
- ret = gtlt + M + '.' + m + '.' + p + '-0';
840
- } else if (xM) {
841
- // allow any
842
- ret = '*';
901
+ ret = gtlt + M + '.' + m + '.' + p;
843
902
  } else if (xm) {
844
- // append '-0' onto the version, otherwise
845
- // '1.x.x' matches '2.0.0-beta', since the tag
846
- // *lowers* the version value
847
- ret = '>=' + M + '.0.0-0 <' + (+M + 1) + '.0.0-0';
903
+ ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
848
904
  } else if (xp) {
849
- ret = '>=' + M + '.' + m + '.0-0 <' + M + '.' + (+m + 1) + '.0-0';
905
+ ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
850
906
  }
851
907
 
852
908
  ;
@@ -865,9 +921,9 @@ function replaceStars(comp, loose) {
865
921
 
866
922
  // This function is passed to string.replace(re[HYPHENRANGE])
867
923
  // M, m, patch, prerelease, build
868
- // 1.2 - 3.4.5 => >=1.2.0-0 <=3.4.5
869
- // 1.2.3 - 3.4 => >=1.2.0-0 <3.5.0-0 Any 3.4.x will do
870
- // 1.2 - 3.4 => >=1.2.0-0 <3.5.0-0
924
+ // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
925
+ // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
926
+ // 1.2 - 3.4 => >=1.2.0 <3.5.0
871
927
  function hyphenReplace($0,
872
928
  from, fM, fm, fp, fpr, fb,
873
929
  to, tM, tm, tp, tpr, tb) {
@@ -875,18 +931,18 @@ function hyphenReplace($0,
875
931
  if (isX(fM))
876
932
  from = '';
877
933
  else if (isX(fm))
878
- from = '>=' + fM + '.0.0-0';
934
+ from = '>=' + fM + '.0.0';
879
935
  else if (isX(fp))
880
- from = '>=' + fM + '.' + fm + '.0-0';
936
+ from = '>=' + fM + '.' + fm + '.0';
881
937
  else
882
938
  from = '>=' + from;
883
939
 
884
940
  if (isX(tM))
885
941
  to = '';
886
942
  else if (isX(tm))
887
- to = '<' + (+tM + 1) + '.0.0-0';
943
+ to = '<' + (+tM + 1) + '.0.0';
888
944
  else if (isX(tp))
889
- to = '<' + tM + '.' + (+tm + 1) + '.0-0';
945
+ to = '<' + tM + '.' + (+tm + 1) + '.0';
890
946
  else if (tpr)
891
947
  to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
892
948
  else
@@ -900,6 +956,10 @@ function hyphenReplace($0,
900
956
  Range.prototype.test = function(version) {
901
957
  if (!version)
902
958
  return false;
959
+
960
+ if (typeof version === 'string')
961
+ version = new SemVer(version, this.loose);
962
+
903
963
  for (var i = 0; i < this.set.length; i++) {
904
964
  if (testSet(this.set[i], version))
905
965
  return true;
@@ -912,6 +972,31 @@ function testSet(set, version) {
912
972
  if (!set[i].test(version))
913
973
  return false;
914
974
  }
975
+
976
+ if (version.prerelease.length) {
977
+ // Find the set of versions that are allowed to have prereleases
978
+ // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
979
+ // That should allow `1.2.3-pr.2` to pass.
980
+ // However, `1.2.4-alpha.notready` should NOT be allowed,
981
+ // even though it's within the range set by the comparators.
982
+ for (var i = 0; i < set.length; i++) {
983
+ ;
984
+ if (set[i].semver === ANY)
985
+ return true;
986
+
987
+ if (set[i].semver.prerelease.length > 0) {
988
+ var allowed = set[i].semver;
989
+ if (allowed.major === version.major &&
990
+ allowed.minor === version.minor &&
991
+ allowed.patch === version.patch)
992
+ return true;
993
+ }
994
+ }
995
+
996
+ // Version has a -pre, but it's not one of the ones we like.
997
+ return false;
998
+ }
999
+
915
1000
  return true;
916
1001
  }
917
1002
 
Binary file