@vltpkg/semver 1.8.0 → 1.8.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.
- package/dist/index.js +24 -220
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -400,8 +400,8 @@ export const intersects = (r1, r2, includePrerelease) => {
|
|
|
400
400
|
const cached = inner?.get(range2);
|
|
401
401
|
if (cached !== undefined)
|
|
402
402
|
return cached;
|
|
403
|
-
//
|
|
404
|
-
const result = range1.
|
|
403
|
+
// some version must satisfy both ranges
|
|
404
|
+
const result = critical(range1, range2).some(v => range1.test(v) && range2.test(v));
|
|
405
405
|
if (!inner) {
|
|
406
406
|
inner = new WeakMap();
|
|
407
407
|
intersectsCache.set(range1, inner);
|
|
@@ -418,228 +418,32 @@ export const subset = (r1, r2, includePrerelease) => {
|
|
|
418
418
|
const range2 = typeof r2 === 'string' ? parseRange(r2, includePrerelease) : r2;
|
|
419
419
|
if (!range1 || !range2)
|
|
420
420
|
return false;
|
|
421
|
-
//
|
|
422
|
-
|
|
423
|
-
return true;
|
|
424
|
-
if (range1.isAny)
|
|
425
|
-
return false;
|
|
426
|
-
// Every comparator set in r1 must be a subset of at least one
|
|
427
|
-
// comparator set in r2
|
|
428
|
-
return range1.set.every(set1 => range2.set.some(set2 => comparatorSubset(set1, set2)));
|
|
421
|
+
// no version may satisfy r1 without also satisfying r2
|
|
422
|
+
return !critical(range1, range2).some(v => range1.test(v) && !range2.test(v));
|
|
429
423
|
};
|
|
430
424
|
/**
|
|
431
|
-
*
|
|
432
|
-
*
|
|
425
|
+
* The versions that decide whether two ranges overlap. A range matches a
|
|
426
|
+
* union of intervals that begin and end at its own bounds, so a non-empty
|
|
427
|
+
* overlap or difference always contains one of the versions next to a bound.
|
|
433
428
|
*/
|
|
434
|
-
const
|
|
435
|
-
const
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
!eq(bounds1.lowerBound, bounds2.hasExact) ||
|
|
451
|
-
!eq(bounds1.upperBound, bounds2.hasExact) ||
|
|
452
|
-
!bounds1.lowerInclusive ||
|
|
453
|
-
!bounds1.upperInclusive) {
|
|
454
|
-
return false;
|
|
455
|
-
}
|
|
456
|
-
return true;
|
|
457
|
-
}
|
|
458
|
-
// If comp1 has an exact match, check it satisfies comp2's bounds
|
|
459
|
-
if (bounds1.hasExact) {
|
|
460
|
-
if (bounds2.lowerBound) {
|
|
461
|
-
if (bounds2.lowerInclusive ?
|
|
462
|
-
lt(bounds1.hasExact, bounds2.lowerBound)
|
|
463
|
-
: lte(bounds1.hasExact, bounds2.lowerBound)) {
|
|
464
|
-
return false;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
if (bounds2.upperBound) {
|
|
468
|
-
if (bounds2.upperInclusive ?
|
|
469
|
-
gt(bounds1.hasExact, bounds2.upperBound)
|
|
470
|
-
: gte(bounds1.hasExact, bounds2.upperBound)) {
|
|
471
|
-
return false;
|
|
429
|
+
const critical = (...ranges) => {
|
|
430
|
+
const v = (M, m, p, pr) => new Version('', M, m, p, pr, undefined);
|
|
431
|
+
const out = [v(0, 0, 0, '0'), v(0, 0, 0)];
|
|
432
|
+
for (const range of ranges) {
|
|
433
|
+
for (const comp of range.set) {
|
|
434
|
+
for (const t of comp.tuples) {
|
|
435
|
+
if (!Array.isArray(t))
|
|
436
|
+
continue;
|
|
437
|
+
const { major: M, minor: m, patch: p, prerelease: pr } = t[1];
|
|
438
|
+
out.push(t[1], v(M, m, p), // the release of this bound
|
|
439
|
+
v(M, m, p, '0'), // lowest prerelease of its tuple
|
|
440
|
+
v(M, m, p + 1), // next release
|
|
441
|
+
v(M, m, p + 1, '0'));
|
|
442
|
+
// first version after a prerelease
|
|
443
|
+
if (pr?.length)
|
|
444
|
+
out.push(v(M, m, p, [...pr, 0].join('.')));
|
|
472
445
|
}
|
|
473
446
|
}
|
|
474
|
-
return true;
|
|
475
|
-
}
|
|
476
|
-
// comp1's lower bound must be >= comp2's lower bound
|
|
477
|
-
if (bounds2.lowerBound) {
|
|
478
|
-
if (!bounds1.lowerBound)
|
|
479
|
-
return false;
|
|
480
|
-
const cmp = compare(bounds1.lowerBound, bounds2.lowerBound);
|
|
481
|
-
if (cmp < 0)
|
|
482
|
-
return false;
|
|
483
|
-
if (cmp === 0 &&
|
|
484
|
-
!bounds2.lowerInclusive &&
|
|
485
|
-
bounds1.lowerInclusive)
|
|
486
|
-
return false;
|
|
487
|
-
}
|
|
488
|
-
// comp1's upper bound must be <= comp2's upper bound
|
|
489
|
-
if (bounds2.upperBound) {
|
|
490
|
-
if (!bounds1.upperBound)
|
|
491
|
-
return false;
|
|
492
|
-
const cmp = compare(bounds1.upperBound, bounds2.upperBound);
|
|
493
|
-
if (cmp > 0)
|
|
494
|
-
return false;
|
|
495
|
-
if (cmp === 0 &&
|
|
496
|
-
!bounds2.upperInclusive &&
|
|
497
|
-
bounds1.upperInclusive)
|
|
498
|
-
return false;
|
|
499
|
-
}
|
|
500
|
-
return true;
|
|
501
|
-
};
|
|
502
|
-
const getBounds = (tuples) => {
|
|
503
|
-
let lowerBound = null;
|
|
504
|
-
let lowerInclusive = false;
|
|
505
|
-
let upperBound = null;
|
|
506
|
-
let upperInclusive = false;
|
|
507
|
-
let hasExact = null;
|
|
508
|
-
for (const [op, ver] of tuples) {
|
|
509
|
-
switch (op) {
|
|
510
|
-
case '':
|
|
511
|
-
hasExact = ver;
|
|
512
|
-
break;
|
|
513
|
-
case '>=':
|
|
514
|
-
/* c8 ignore start */
|
|
515
|
-
if (!lowerBound ||
|
|
516
|
-
gt(ver, lowerBound) ||
|
|
517
|
-
(eq(ver, lowerBound) && !lowerInclusive)) {
|
|
518
|
-
lowerBound = ver;
|
|
519
|
-
lowerInclusive = true;
|
|
520
|
-
}
|
|
521
|
-
/* c8 ignore stop */
|
|
522
|
-
break;
|
|
523
|
-
case '>':
|
|
524
|
-
if (!lowerBound || gt(ver, lowerBound)) {
|
|
525
|
-
lowerBound = ver;
|
|
526
|
-
lowerInclusive = false;
|
|
527
|
-
}
|
|
528
|
-
break;
|
|
529
|
-
case '<=':
|
|
530
|
-
/* c8 ignore start */
|
|
531
|
-
if (!upperBound ||
|
|
532
|
-
lt(ver, upperBound) ||
|
|
533
|
-
(eq(ver, upperBound) && !upperInclusive)) {
|
|
534
|
-
upperBound = ver;
|
|
535
|
-
upperInclusive = true;
|
|
536
|
-
}
|
|
537
|
-
/* c8 ignore stop */
|
|
538
|
-
break;
|
|
539
|
-
case '<':
|
|
540
|
-
if (!upperBound || lt(ver, upperBound)) {
|
|
541
|
-
upperBound = ver;
|
|
542
|
-
upperInclusive = false;
|
|
543
|
-
}
|
|
544
|
-
break;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
return {
|
|
548
|
-
lowerBound,
|
|
549
|
-
lowerInclusive,
|
|
550
|
-
upperBound,
|
|
551
|
-
upperInclusive,
|
|
552
|
-
hasExact,
|
|
553
|
-
};
|
|
554
|
-
};
|
|
555
|
-
/**
|
|
556
|
-
* Check if two comparators can be satisfied simultaneously
|
|
557
|
-
*/
|
|
558
|
-
const intersectComparators = (comp1, comp2) => {
|
|
559
|
-
// Collect all tuples from both comparators
|
|
560
|
-
const tuples1 = comp1.tuples.filter((t) => Array.isArray(t));
|
|
561
|
-
const tuples2 = comp2.tuples.filter((t) => Array.isArray(t));
|
|
562
|
-
// Check if there's a satisfiable combination
|
|
563
|
-
return satisfiableRange(tuples1.concat(tuples2));
|
|
564
|
-
};
|
|
565
|
-
/**
|
|
566
|
-
* Check if a set of operator-version tuples represents a satisfiable range
|
|
567
|
-
* This is a simplified implementation that handles the most common cases
|
|
568
|
-
*/
|
|
569
|
-
const satisfiableRange = (tuples) => {
|
|
570
|
-
// Find bounds
|
|
571
|
-
let lowerBound = null;
|
|
572
|
-
let lowerInclusive = false;
|
|
573
|
-
let upperBound = null;
|
|
574
|
-
let upperInclusive = false;
|
|
575
|
-
let hasExact = null;
|
|
576
|
-
for (const [op, ver] of tuples) {
|
|
577
|
-
switch (op) {
|
|
578
|
-
case '':
|
|
579
|
-
// Exact match - if we already have a different exact match, no intersection
|
|
580
|
-
if (hasExact && !eq(hasExact, ver))
|
|
581
|
-
return false;
|
|
582
|
-
hasExact = ver;
|
|
583
|
-
break;
|
|
584
|
-
case '>=':
|
|
585
|
-
/* c8 ignore start */
|
|
586
|
-
if (!lowerBound ||
|
|
587
|
-
gt(ver, lowerBound) ||
|
|
588
|
-
(eq(ver, lowerBound) && !lowerInclusive)) {
|
|
589
|
-
lowerBound = ver;
|
|
590
|
-
lowerInclusive = true;
|
|
591
|
-
}
|
|
592
|
-
/* c8 ignore stop */
|
|
593
|
-
break;
|
|
594
|
-
case '>':
|
|
595
|
-
if (!lowerBound || gt(ver, lowerBound)) {
|
|
596
|
-
lowerBound = ver;
|
|
597
|
-
lowerInclusive = false;
|
|
598
|
-
}
|
|
599
|
-
break;
|
|
600
|
-
case '<=':
|
|
601
|
-
if (!upperBound || lt(ver, upperBound)) {
|
|
602
|
-
upperBound = ver;
|
|
603
|
-
upperInclusive = true;
|
|
604
|
-
}
|
|
605
|
-
break;
|
|
606
|
-
case '<':
|
|
607
|
-
/* c8 ignore start */
|
|
608
|
-
if (!upperBound ||
|
|
609
|
-
lt(ver, upperBound) ||
|
|
610
|
-
eq(ver, upperBound)) {
|
|
611
|
-
upperBound = ver;
|
|
612
|
-
upperInclusive = false;
|
|
613
|
-
}
|
|
614
|
-
/* c8 ignore stop */
|
|
615
|
-
break;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
// If we have an exact match, check if it's within bounds
|
|
619
|
-
if (hasExact) {
|
|
620
|
-
if (lowerBound) {
|
|
621
|
-
if (lowerInclusive ?
|
|
622
|
-
lt(hasExact, lowerBound)
|
|
623
|
-
: lte(hasExact, lowerBound)) {
|
|
624
|
-
return false;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
if (upperBound) {
|
|
628
|
-
if (upperInclusive ?
|
|
629
|
-
gt(hasExact, upperBound)
|
|
630
|
-
: gte(hasExact, upperBound)) {
|
|
631
|
-
return false;
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
return true;
|
|
635
|
-
}
|
|
636
|
-
// Check if lower bound is less than or equal to upper bound
|
|
637
|
-
if (lowerBound && upperBound) {
|
|
638
|
-
if (gt(lowerBound, upperBound))
|
|
639
|
-
return false;
|
|
640
|
-
if (eq(lowerBound, upperBound) &&
|
|
641
|
-
!(lowerInclusive && upperInclusive))
|
|
642
|
-
return false;
|
|
643
447
|
}
|
|
644
|
-
return
|
|
448
|
+
return out;
|
|
645
449
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/semver",
|
|
3
3
|
"description": "The semantic version parser used by vlt",
|
|
4
|
-
"version": "1.8.
|
|
4
|
+
"version": "1.8.1",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"url": "http://vlt.sh"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@vltpkg/error-cause": "1.8.
|
|
17
|
-
"@vltpkg/fast-split": "1.8.
|
|
18
|
-
"@vltpkg/types": "1.8.
|
|
16
|
+
"@vltpkg/error-cause": "1.8.1",
|
|
17
|
+
"@vltpkg/fast-split": "1.8.1",
|
|
18
|
+
"@vltpkg/types": "1.8.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@eslint/js": "^10.0.1",
|