@socketsecurity/cli-with-sentry 1.1.15 → 1.1.18

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 (103) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cli.js +14 -15
  3. package/dist/cli.js.map +1 -1
  4. package/dist/constants.js +35 -37
  5. package/dist/constants.js.map +1 -1
  6. package/dist/shadow-npm-bin.js +6 -6
  7. package/dist/shadow-npm-bin.js.map +1 -1
  8. package/dist/shadow-pnpm-bin.js +3 -5
  9. package/dist/shadow-pnpm-bin.js.map +1 -1
  10. package/dist/shadow-yarn-bin.js +2 -2
  11. package/dist/shadow-yarn-bin.js.map +1 -1
  12. package/dist/tsconfig.dts.tsbuildinfo +1 -1
  13. package/dist/types/commands/fix/coana-fix.d.mts.map +1 -1
  14. package/dist/types/commands/optimize/apply-optimization.d.mts.map +1 -1
  15. package/dist/types/commands/optimize/update-lockfile.d.mts.map +1 -1
  16. package/dist/types/commands/patch/cmd-patch.d.mts.map +1 -1
  17. package/dist/types/commands/patch/handle-patch.d.mts.map +1 -1
  18. package/dist/types/commands/yarn/cmd-yarn.d.mts +1 -1
  19. package/dist/types/commands/yarn/cmd-yarn.d.mts.map +1 -1
  20. package/dist/types/constants.d.mts +15 -19
  21. package/dist/types/constants.d.mts.map +1 -1
  22. package/dist/types/shadow/pnpm/bin.d.mts.map +1 -1
  23. package/dist/types/utils/agent.d.mts.map +1 -1
  24. package/dist/types/utils/dlx.d.mts.map +1 -1
  25. package/dist/types/utils/package-environment.d.mts.map +1 -1
  26. package/dist/types/utils/path-resolve.d.mts.map +1 -1
  27. package/dist/utils.js +65 -27
  28. package/dist/utils.js.map +1 -1
  29. package/dist/vendor.js +522 -524
  30. package/external/@socketsecurity/registry/external/@inquirer/confirm.js +45 -205
  31. package/external/@socketsecurity/registry/external/@inquirer/input.js +45 -205
  32. package/external/@socketsecurity/registry/external/@inquirer/password.js +181 -205
  33. package/external/@socketsecurity/registry/external/@inquirer/search.js +47 -207
  34. package/external/@socketsecurity/registry/external/@inquirer/select.js +183 -207
  35. package/external/@socketsecurity/registry/external/@npmcli/package-json/index.js +388 -2280
  36. package/external/@socketsecurity/registry/external/browserslist.js +11534 -567
  37. package/external/@socketsecurity/registry/external/cacache.js +2575 -4914
  38. package/external/@socketsecurity/registry/external/libnpmpack.js +64667 -166061
  39. package/external/@socketsecurity/registry/external/make-fetch-happen.js +384 -4044
  40. package/external/@socketsecurity/registry/external/normalize-package-data.js +30 -278
  41. package/external/@socketsecurity/registry/external/npm-package-arg.js +28 -9
  42. package/external/@socketsecurity/registry/external/pacote.js +46680 -66482
  43. package/external/@socketsecurity/registry/external/spdx-correct.js +19 -0
  44. package/external/@socketsecurity/registry/external/spdx-expression-parse.js +19 -0
  45. package/external/@socketsecurity/registry/lib/agent.js +390 -0
  46. package/external/@socketsecurity/registry/lib/arrays.js +31 -0
  47. package/external/@socketsecurity/registry/lib/bin.js +650 -0
  48. package/external/@socketsecurity/registry/lib/constants/bun-lock.js +3 -0
  49. package/external/@socketsecurity/registry/lib/constants/bun-lockb.js +3 -0
  50. package/external/@socketsecurity/registry/lib/constants/bun.js +3 -0
  51. package/external/@socketsecurity/registry/lib/constants/dot-git-dir.js +3 -0
  52. package/external/@socketsecurity/registry/lib/constants/dot-socket-dir.js +3 -0
  53. package/external/@socketsecurity/registry/lib/constants/empty-value.js +3 -0
  54. package/external/@socketsecurity/registry/lib/constants/env.js +17 -3
  55. package/external/@socketsecurity/registry/lib/constants/ext-yaml.js +3 -0
  56. package/external/@socketsecurity/registry/lib/constants/ext-yml.js +3 -0
  57. package/external/@socketsecurity/registry/lib/constants/index.js +20 -11
  58. package/external/@socketsecurity/registry/lib/constants/npm-exec-path.js +2 -2
  59. package/external/@socketsecurity/registry/lib/constants/npm-real-exec-path.js +1 -1
  60. package/external/@socketsecurity/registry/lib/constants/npm-shrinkwrap-json.js +3 -0
  61. package/external/@socketsecurity/registry/lib/constants/pnpm-exec-path.js +5 -0
  62. package/external/@socketsecurity/registry/lib/constants/pnpm-lock-yaml.js +3 -0
  63. package/external/@socketsecurity/registry/lib/constants/unknown-error.js +3 -0
  64. package/external/@socketsecurity/registry/lib/constants/unknown-value.js +3 -0
  65. package/external/@socketsecurity/registry/lib/constants/vlt-lock-json.js +3 -0
  66. package/external/@socketsecurity/registry/lib/constants/vlt.js +3 -0
  67. package/external/@socketsecurity/registry/lib/constants/yarn-berry.js +3 -0
  68. package/external/@socketsecurity/registry/lib/constants/yarn-classic.js +3 -0
  69. package/external/@socketsecurity/registry/lib/constants/yarn-exec-path.js +5 -0
  70. package/external/@socketsecurity/registry/lib/constants/yarn.js +3 -0
  71. package/external/@socketsecurity/registry/lib/debug.js +53 -0
  72. package/external/@socketsecurity/registry/lib/env.js +18 -0
  73. package/external/@socketsecurity/registry/lib/fs.js +218 -2
  74. package/external/@socketsecurity/registry/lib/functions.js +5 -0
  75. package/external/@socketsecurity/registry/lib/globs.js +22 -1
  76. package/external/@socketsecurity/registry/lib/json.js +16 -0
  77. package/external/@socketsecurity/registry/lib/logger.js +157 -0
  78. package/external/@socketsecurity/registry/lib/objects.js +103 -0
  79. package/external/@socketsecurity/registry/lib/packages.js +88 -0
  80. package/external/@socketsecurity/registry/lib/path.js +51 -1
  81. package/external/@socketsecurity/registry/lib/promises.js +55 -0
  82. package/external/@socketsecurity/registry/lib/regexps.js +5 -0
  83. package/external/@socketsecurity/registry/lib/sorts.js +17 -0
  84. package/external/@socketsecurity/registry/lib/spawn.js +105 -7
  85. package/external/@socketsecurity/registry/lib/streams.js +26 -0
  86. package/external/@socketsecurity/registry/lib/strings.js +123 -9
  87. package/external/@socketsecurity/registry/lib/url.js +21 -0
  88. package/external/@socketsecurity/registry/lib/words.js +16 -0
  89. package/external/@socketsecurity/registry/manifest.json +5 -4
  90. package/package.json +6 -5
  91. package/external/@socketsecurity/registry/external/ansi-regex.js +0 -13
  92. package/external/@socketsecurity/registry/lib/constants/node-workspaces.js +0 -3
  93. package/external/@socketsecurity/registry/lib/constants/parse-args-config.js +0 -14
  94. package/external/@socketsecurity/registry/lib/constants/skip-tests-by-ecosystem.js +0 -43
  95. package/external/@socketsecurity/registry/lib/constants/template-cjs-browser.js +0 -3
  96. package/external/@socketsecurity/registry/lib/constants/template-cjs-esm.js +0 -3
  97. package/external/@socketsecurity/registry/lib/constants/template-cjs.js +0 -3
  98. package/external/@socketsecurity/registry/lib/constants/template-es-shim-constructor.js +0 -3
  99. package/external/@socketsecurity/registry/lib/constants/template-es-shim-prototype-method.js +0 -3
  100. package/external/@socketsecurity/registry/lib/constants/template-es-shim-static-method.js +0 -3
  101. package/external/@socketsecurity/registry/lib/constants/win32-ensure-tests-by-ecosystem.js +0 -3
  102. package/external/@socketsecurity/registry/lib/npm.js +0 -404
  103. /package/external/@socketsecurity/registry/lib/constants/{hidden-package-lock-json.js → dot-package-lock-json.js} +0 -0
@@ -984,12 +984,12 @@ function requireSemver$1() {
984
984
  }
985
985
 
986
986
  let parse_1
987
- let hasRequiredParse$2
988
- function requireParse$2() {
989
- if (hasRequiredParse$2) {
987
+ let hasRequiredParse$1
988
+ function requireParse$1() {
989
+ if (hasRequiredParse$1) {
990
990
  return parse_1
991
991
  }
992
- hasRequiredParse$2 = 1
992
+ hasRequiredParse$1 = 1
993
993
  const SemVer = requireSemver$1()
994
994
  const parse = (version, options, throwErrors = false) => {
995
995
  if (version instanceof SemVer) {
@@ -1015,7 +1015,7 @@ function requireValid$1() {
1015
1015
  return valid_1
1016
1016
  }
1017
1017
  hasRequiredValid$1 = 1
1018
- const parse = requireParse$2()
1018
+ const parse = requireParse$1()
1019
1019
  const valid = (version, options) => {
1020
1020
  const v = parse(version, options)
1021
1021
  return v ? v.version : null
@@ -1031,7 +1031,7 @@ function requireClean() {
1031
1031
  return clean_1
1032
1032
  }
1033
1033
  hasRequiredClean = 1
1034
- const parse = requireParse$2()
1034
+ const parse = requireParse$1()
1035
1035
  const clean = (version, options) => {
1036
1036
  const s = parse(version.trim().replace(/^[=v]+/, ''), options)
1037
1037
  return s ? s.version : null
@@ -1191,22 +1191,22 @@ function requireLib$a() {
1191
1191
  return lib$a
1192
1192
  }
1193
1193
 
1194
- const commonjs$8 = {}
1194
+ const commonjs$5 = {}
1195
1195
 
1196
- let hasRequiredCommonjs$8
1197
- function requireCommonjs$8() {
1198
- if (hasRequiredCommonjs$8) {
1199
- return commonjs$8
1196
+ let hasRequiredCommonjs$5
1197
+ function requireCommonjs$5() {
1198
+ if (hasRequiredCommonjs$5) {
1199
+ return commonjs$5
1200
1200
  }
1201
- hasRequiredCommonjs$8 = 1
1201
+ hasRequiredCommonjs$5 = 1
1202
1202
  /**
1203
1203
  * @module LRUCache
1204
1204
  */
1205
- Object.defineProperty(commonjs$8, '__esModule', {
1205
+ Object.defineProperty(commonjs$5, '__esModule', {
1206
1206
  value: true
1207
1207
  })
1208
- commonjs$8.LRUCache = void 0
1209
- const perf =
1208
+ commonjs$5.LRUCache = void 0
1209
+ const defaultPerf =
1210
1210
  typeof performance === 'object' &&
1211
1211
  performance &&
1212
1212
  typeof performance.now === 'function'
@@ -1363,6 +1363,13 @@ function requireCommonjs$8() {
1363
1363
  #disposeAfter
1364
1364
  #fetchMethod
1365
1365
  #memoMethod
1366
+ #perf
1367
+ /**
1368
+ * {@link LRUCache.OptionsBase.perf}
1369
+ */
1370
+ get perf() {
1371
+ return this.#perf
1372
+ }
1366
1373
  /**
1367
1374
  * {@link LRUCache.OptionsBase.ttl}
1368
1375
  */
@@ -1554,8 +1561,17 @@ function requireCommonjs$8() {
1554
1561
  noDeleteOnStaleGet,
1555
1562
  allowStaleOnFetchRejection,
1556
1563
  allowStaleOnFetchAbort,
1557
- ignoreFetchAbort
1564
+ ignoreFetchAbort,
1565
+ perf
1558
1566
  } = options
1567
+ if (perf !== undefined) {
1568
+ if (typeof perf?.now !== 'function') {
1569
+ throw new TypeError(
1570
+ 'perf option must have a now() method if specified'
1571
+ )
1572
+ }
1573
+ }
1574
+ this.#perf = perf ?? defaultPerf
1559
1575
  if (max !== 0 && !isPosInt(max)) {
1560
1576
  throw new TypeError('max option must be a nonnegative integer')
1561
1577
  }
@@ -1675,7 +1691,7 @@ function requireCommonjs$8() {
1675
1691
  const starts = new ZeroArray(this.#max)
1676
1692
  this.#ttls = ttls
1677
1693
  this.#starts = starts
1678
- this.#setItemTTL = (index, ttl, start = perf.now()) => {
1694
+ this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
1679
1695
  starts[index] = ttl !== 0 ? start : 0
1680
1696
  ttls[index] = ttl
1681
1697
  if (ttl !== 0 && this.ttlAutopurge) {
@@ -1693,7 +1709,7 @@ function requireCommonjs$8() {
1693
1709
  }
1694
1710
  }
1695
1711
  this.#updateItemAge = index => {
1696
- starts[index] = ttls[index] !== 0 ? perf.now() : 0
1712
+ starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0
1697
1713
  }
1698
1714
  this.#statusTTL = (status, index) => {
1699
1715
  if (ttls[index]) {
@@ -1714,7 +1730,7 @@ function requireCommonjs$8() {
1714
1730
  // that costly call repeatedly.
1715
1731
  let cachedNow = 0
1716
1732
  const getNow = () => {
1717
- const n = perf.now()
1733
+ const n = this.#perf.now()
1718
1734
  if (this.ttlResolution > 0) {
1719
1735
  cachedNow = n
1720
1736
  const t = setTimeout(() => (cachedNow = 0), this.ttlResolution)
@@ -2033,10 +2049,13 @@ function requireCommonjs$8() {
2033
2049
  return undefined
2034
2050
  }
2035
2051
  const v = this.#valList[i]
2052
+ /* c8 ignore start - this isn't tested for the info function,
2053
+ * but it's the same logic as found in other places. */
2036
2054
  const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
2037
2055
  if (value === undefined) {
2038
2056
  return undefined
2039
2057
  }
2058
+ /* c8 ignore end */
2040
2059
  const entry = {
2041
2060
  value
2042
2061
  }
@@ -2044,7 +2063,7 @@ function requireCommonjs$8() {
2044
2063
  const ttl = this.#ttls[i]
2045
2064
  const start = this.#starts[i]
2046
2065
  if (ttl && start) {
2047
- const remain = ttl - (perf.now() - start)
2066
+ const remain = ttl - (this.#perf.now() - start)
2048
2067
  entry.ttl = remain
2049
2068
  entry.start = Date.now()
2050
2069
  }
@@ -2085,7 +2104,7 @@ function requireCommonjs$8() {
2085
2104
  entry.ttl = this.#ttls[i]
2086
2105
  // always dump the start relative to a portable timestamp
2087
2106
  // it's ok for this to be a bit slow, it's a rare operation.
2088
- const age = perf.now() - this.#starts[i]
2107
+ const age = this.#perf.now() - this.#starts[i]
2089
2108
  entry.start = Math.floor(Date.now() - age)
2090
2109
  }
2091
2110
  if (this.#sizes) {
@@ -2115,7 +2134,7 @@ function requireCommonjs$8() {
2115
2134
  //
2116
2135
  // it's ok for this to be a bit slow, it's a rare operation.
2117
2136
  const age = Date.now() - entry.start
2118
- entry.start = perf.now() - age
2137
+ entry.start = this.#perf.now() - age
2119
2138
  }
2120
2139
  this.set(key, entry.value, entry)
2121
2140
  }
@@ -2427,7 +2446,7 @@ function requireCommonjs$8() {
2427
2446
  const bf = p
2428
2447
  if (this.#valList[index] === p) {
2429
2448
  if (v === undefined) {
2430
- if (bf.__staleWhileFetching) {
2449
+ if (bf.__staleWhileFetching !== undefined) {
2431
2450
  this.#valList[index] = bf.__staleWhileFetching
2432
2451
  } else {
2433
2452
  this.#delete(k, 'fetch')
@@ -2843,8 +2862,8 @@ function requireCommonjs$8() {
2843
2862
  }
2844
2863
  }
2845
2864
  }
2846
- commonjs$8.LRUCache = LRUCache
2847
- return commonjs$8
2865
+ commonjs$5.LRUCache = LRUCache
2866
+ return commonjs$5
2848
2867
  }
2849
2868
 
2850
2869
  /* eslint-disable max-len */
@@ -3343,7 +3362,7 @@ function requireLib$9() {
3343
3362
  return lib$9
3344
3363
  }
3345
3364
  hasRequiredLib$9 = 1
3346
- const { LRUCache } = /*@__PURE__*/ requireCommonjs$8()
3365
+ const { LRUCache } = /*@__PURE__*/ requireCommonjs$5()
3347
3366
  const hosts = requireHosts$1()
3348
3367
  const fromUrl = requireFromUrl$1()
3349
3368
  const parseUrl = requireParseUrl$1()
@@ -3586,149 +3605,136 @@ function requireLib$9() {
3586
3605
  return lib$9
3587
3606
  }
3588
3607
 
3589
- const commonjs$7 = {}
3590
-
3591
- const commonjs$6 = {}
3592
-
3593
- const commonjs$5 = {}
3594
-
3595
3608
  const commonjs$4 = {}
3596
3609
 
3597
- let hasRequiredCommonjs$7
3598
- function requireCommonjs$7() {
3599
- if (hasRequiredCommonjs$7) {
3600
- return commonjs$4
3610
+ const commonjs$3 = {}
3611
+
3612
+ let balancedMatch
3613
+ let hasRequiredBalancedMatch
3614
+ function requireBalancedMatch() {
3615
+ if (hasRequiredBalancedMatch) {
3616
+ return balancedMatch
3601
3617
  }
3602
- hasRequiredCommonjs$7 = 1
3603
- ;(function (exports) {
3604
- Object.defineProperty(exports, '__esModule', {
3605
- value: true
3606
- })
3607
- exports.range = exports.balanced = void 0
3608
- const balanced = (a, b, str) => {
3609
- const ma = a instanceof RegExp ? maybeMatch(a, str) : a
3610
- const mb = b instanceof RegExp ? maybeMatch(b, str) : b
3611
- const r = ma !== null && mb != null && (0, exports.range)(ma, mb, str)
3612
- return (
3613
- r && {
3614
- start: r[0],
3615
- end: r[1],
3616
- pre: str.slice(0, r[0]),
3617
- body: str.slice(r[0] + ma.length, r[1]),
3618
- post: str.slice(r[1] + mb.length)
3619
- }
3620
- )
3618
+ hasRequiredBalancedMatch = 1
3619
+ balancedMatch = balanced
3620
+ function balanced(a, b, str) {
3621
+ if (a instanceof RegExp) {
3622
+ a = maybeMatch(a, str)
3621
3623
  }
3622
- exports.balanced = balanced
3623
- const maybeMatch = (reg, str) => {
3624
- const m = str.match(reg)
3625
- return m ? m[0] : null
3626
- }
3627
- const range = (a, b, str) => {
3628
- let begs,
3629
- beg,
3630
- left,
3631
- right = undefined,
3632
- result
3633
- let ai = str.indexOf(a)
3634
- let bi = str.indexOf(b, ai + 1)
3635
- let i = ai
3636
- if (ai >= 0 && bi > 0) {
3637
- if (a === b) {
3638
- return [ai, bi]
3639
- }
3640
- begs = []
3641
- left = str.length
3642
- while (i >= 0 && !result) {
3643
- if (i === ai) {
3644
- begs.push(i)
3645
- ai = str.indexOf(a, i + 1)
3646
- } else if (begs.length === 1) {
3647
- const r = begs.pop()
3648
- if (r !== undefined) {
3649
- result = [r, bi]
3650
- }
3651
- } else {
3652
- beg = begs.pop()
3653
- if (beg !== undefined && beg < left) {
3654
- left = beg
3655
- right = bi
3656
- }
3657
- bi = str.indexOf(b, i + 1)
3624
+ if (b instanceof RegExp) {
3625
+ b = maybeMatch(b, str)
3626
+ }
3627
+ const r = range(a, b, str)
3628
+ return (
3629
+ r && {
3630
+ start: r[0],
3631
+ end: r[1],
3632
+ pre: str.slice(0, r[0]),
3633
+ body: str.slice(r[0] + a.length, r[1]),
3634
+ post: str.slice(r[1] + b.length)
3635
+ }
3636
+ )
3637
+ }
3638
+ function maybeMatch(reg, str) {
3639
+ const m = str.match(reg)
3640
+ return m ? m[0] : null
3641
+ }
3642
+ balanced.range = range
3643
+ function range(a, b, str) {
3644
+ let begs, beg, left, right, result
3645
+ let ai = str.indexOf(a)
3646
+ let bi = str.indexOf(b, ai + 1)
3647
+ let i = ai
3648
+ if (ai >= 0 && bi > 0) {
3649
+ if (a === b) {
3650
+ return [ai, bi]
3651
+ }
3652
+ begs = []
3653
+ left = str.length
3654
+ while (i >= 0 && !result) {
3655
+ if (i == ai) {
3656
+ begs.push(i)
3657
+ ai = str.indexOf(a, i + 1)
3658
+ } else if (begs.length == 1) {
3659
+ result = [begs.pop(), bi]
3660
+ } else {
3661
+ beg = begs.pop()
3662
+ if (beg < left) {
3663
+ left = beg
3664
+ right = bi
3658
3665
  }
3659
- i = ai < bi && ai >= 0 ? ai : bi
3660
- }
3661
- if (begs.length && right !== undefined) {
3662
- result = [left, right]
3666
+ bi = str.indexOf(b, i + 1)
3663
3667
  }
3668
+ i = ai < bi && ai >= 0 ? ai : bi
3669
+ }
3670
+ if (begs.length) {
3671
+ result = [left, right]
3664
3672
  }
3665
- return result
3666
3673
  }
3667
- exports.range = range
3668
- })(commonjs$4)
3669
- return commonjs$4
3674
+ return result
3675
+ }
3676
+ return balancedMatch
3670
3677
  }
3671
3678
 
3672
- let hasRequiredCommonjs$6
3673
- function requireCommonjs$6() {
3674
- if (hasRequiredCommonjs$6) {
3675
- return commonjs$5
3679
+ let braceExpansion
3680
+ let hasRequiredBraceExpansion
3681
+ function requireBraceExpansion() {
3682
+ if (hasRequiredBraceExpansion) {
3683
+ return braceExpansion
3676
3684
  }
3677
- hasRequiredCommonjs$6 = 1
3678
- Object.defineProperty(commonjs$5, '__esModule', {
3679
- value: true
3680
- })
3681
- commonjs$5.expand = expand
3682
- const balanced_match_1 = requireCommonjs$7()
3685
+ hasRequiredBraceExpansion = 1
3686
+ const balanced = requireBalancedMatch()
3687
+ braceExpansion = expandTop
3683
3688
  const escSlash = '\0SLASH' + Math.random() + '\0'
3684
3689
  const escOpen = '\0OPEN' + Math.random() + '\0'
3685
3690
  const escClose = '\0CLOSE' + Math.random() + '\0'
3686
3691
  const escComma = '\0COMMA' + Math.random() + '\0'
3687
3692
  const escPeriod = '\0PERIOD' + Math.random() + '\0'
3688
- const escSlashPattern = new RegExp(escSlash, 'g')
3689
- const escOpenPattern = new RegExp(escOpen, 'g')
3690
- const escClosePattern = new RegExp(escClose, 'g')
3691
- const escCommaPattern = new RegExp(escComma, 'g')
3692
- const escPeriodPattern = new RegExp(escPeriod, 'g')
3693
- const slashPattern = /\\\\/g
3694
- const openPattern = /\\{/g
3695
- const closePattern = /\\}/g
3696
- const commaPattern = /\\,/g
3697
- const periodPattern = /\\./g
3698
3693
  function numeric(str) {
3699
- return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0)
3694
+ return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0)
3700
3695
  }
3701
3696
  function escapeBraces(str) {
3702
3697
  return str
3703
- .replace(slashPattern, escSlash)
3704
- .replace(openPattern, escOpen)
3705
- .replace(closePattern, escClose)
3706
- .replace(commaPattern, escComma)
3707
- .replace(periodPattern, escPeriod)
3698
+ .split('\\\\')
3699
+ .join(escSlash)
3700
+ .split('\\{')
3701
+ .join(escOpen)
3702
+ .split('\\}')
3703
+ .join(escClose)
3704
+ .split('\\,')
3705
+ .join(escComma)
3706
+ .split('\\.')
3707
+ .join(escPeriod)
3708
3708
  }
3709
3709
  function unescapeBraces(str) {
3710
3710
  return str
3711
- .replace(escSlashPattern, '\\')
3712
- .replace(escOpenPattern, '{')
3713
- .replace(escClosePattern, '}')
3714
- .replace(escCommaPattern, ',')
3715
- .replace(escPeriodPattern, '.')
3716
- }
3717
- /**
3718
- * Basically just str.split(","), but handling cases
3719
- * where we have nested braced sections, which should be
3720
- * treated as individual members, like {a,{b,c},d}
3721
- */
3711
+ .split(escSlash)
3712
+ .join('\\')
3713
+ .split(escOpen)
3714
+ .join('{')
3715
+ .split(escClose)
3716
+ .join('}')
3717
+ .split(escComma)
3718
+ .join(',')
3719
+ .split(escPeriod)
3720
+ .join('.')
3721
+ }
3722
+
3723
+ // Basically just str.split(","), but handling cases
3724
+ // where we have nested braced sections, which should be
3725
+ // treated as individual members, like {a,{b,c},d}
3722
3726
  function parseCommaParts(str) {
3723
3727
  if (!str) {
3724
3728
  return ['']
3725
3729
  }
3726
3730
  const parts = []
3727
- const m = (0, balanced_match_1.balanced)('{', '}', str)
3731
+ const m = balanced('{', '}', str)
3728
3732
  if (!m) {
3729
3733
  return str.split(',')
3730
3734
  }
3731
- const { pre, body, post } = m
3735
+ const pre = m.pre
3736
+ const body = m.body
3737
+ const post = m.post
3732
3738
  const p = pre.split(',')
3733
3739
  p[p.length - 1] += '{' + body + '}'
3734
3740
  const postParts = parseCommaParts(post)
@@ -3739,20 +3745,21 @@ function requireCommonjs$6() {
3739
3745
  parts.push.apply(parts, p)
3740
3746
  return parts
3741
3747
  }
3742
- function expand(str) {
3748
+ function expandTop(str) {
3743
3749
  if (!str) {
3744
3750
  return []
3745
3751
  }
3752
+
3746
3753
  // I don't know why Bash 4.3 does this, but it does.
3747
3754
  // Anything starting with {} will have the first two bytes preserved
3748
3755
  // but *only* at the top level, so {},a}b will not expand to anything,
3749
3756
  // but a{},b}c will be expanded to [a}c,abc].
3750
3757
  // One could argue that this is a bug in Bash, but since the goal of
3751
3758
  // this module is to match Bash's rules, we escape a leading {}
3752
- if (str.slice(0, 2) === '{}') {
3753
- str = '\\{\\}' + str.slice(2)
3759
+ if (str.substr(0, 2) === '{}') {
3760
+ str = '\\{\\}' + str.substr(2)
3754
3761
  }
3755
- return expand_(escapeBraces(str), true).map(unescapeBraces)
3762
+ return expand(escapeBraces(str), true).map(unescapeBraces)
3756
3763
  }
3757
3764
  function embrace(str) {
3758
3765
  return '{' + str + '}'
@@ -3766,19 +3773,19 @@ function requireCommonjs$6() {
3766
3773
  function gte(i, y) {
3767
3774
  return i >= y
3768
3775
  }
3769
- function expand_(str, isTop) {
3770
- /** @type {string[]} */
3776
+ function expand(str, isTop) {
3771
3777
  const expansions = []
3772
- const m = (0, balanced_match_1.balanced)('{', '}', str)
3778
+ const m = balanced('{', '}', str)
3773
3779
  if (!m) {
3774
3780
  return [str]
3775
3781
  }
3782
+
3776
3783
  // no need to expand pre, since it is guaranteed to be free of brace-sets
3777
3784
  const pre = m.pre
3778
- const post = m.post.length ? expand_(m.post, false) : ['']
3779
- if (/\$$/.test(m.pre)) {
3780
- for (let k = 0; k < post.length; k++) {
3781
- const expansion = pre + '{' + m.body + '}' + post[k]
3785
+ const post = m.post.length ? expand(m.post, false) : ['']
3786
+ if (m.pre.endsWith('\u0024' /*'$'*/)) {
3787
+ for (var k = 0; k < post.length; k++) {
3788
+ var expansion = pre + '{' + m.body + '}' + post[k]
3782
3789
  expansions.push(expansion)
3783
3790
  }
3784
3791
  } else {
@@ -3792,7 +3799,7 @@ function requireCommonjs$6() {
3792
3799
  // {a},b}
3793
3800
  if (m.post.match(/,(?!,).*\}/)) {
3794
3801
  str = m.pre + '{' + m.body + escClose + m.post
3795
- return expand_(str)
3802
+ return expand(str)
3796
3803
  }
3797
3804
  return [str]
3798
3805
  }
@@ -3801,26 +3808,25 @@ function requireCommonjs$6() {
3801
3808
  n = m.body.split(/\.\./)
3802
3809
  } else {
3803
3810
  n = parseCommaParts(m.body)
3804
- if (n.length === 1 && n[0] !== undefined) {
3811
+ if (n.length === 1) {
3805
3812
  // x{{a,b}}y ==> x{a}y x{b}y
3806
- n = expand_(n[0], false).map(embrace)
3807
- //XXX is this necessary? Can't seem to hit it in tests.
3808
- /* c8 ignore start */
3813
+ n = expand(n[0], false).map(embrace)
3809
3814
  if (n.length === 1) {
3810
- return post.map(p => m.pre + n[0] + p)
3815
+ return post.map(function (p) {
3816
+ return m.pre + n[0] + p
3817
+ })
3811
3818
  }
3812
- /* c8 ignore stop */
3813
3819
  }
3814
3820
  }
3821
+
3815
3822
  // at this point, n is the parts, and we know it's not a comma set
3816
3823
  // with a single entry.
3817
3824
  let N
3818
- if (isSequence && n[0] !== undefined && n[1] !== undefined) {
3825
+ if (isSequence) {
3819
3826
  const x = numeric(n[0])
3820
3827
  const y = numeric(n[1])
3821
3828
  const width = Math.max(n[0].length, n[1].length)
3822
- let incr =
3823
- n.length === 3 && n[2] !== undefined ? Math.abs(numeric(n[2])) : 1
3829
+ let incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1
3824
3830
  let test = lte
3825
3831
  const reverse = y < x
3826
3832
  if (reverse) {
@@ -3854,13 +3860,13 @@ function requireCommonjs$6() {
3854
3860
  }
3855
3861
  } else {
3856
3862
  N = []
3857
- for (let j = 0; j < n.length; j++) {
3858
- N.push.apply(N, expand_(n[j], false))
3863
+ for (var j = 0; j < n.length; j++) {
3864
+ N.push.apply(N, expand(n[j], false))
3859
3865
  }
3860
3866
  }
3861
- for (let j = 0; j < N.length; j++) {
3862
- for (let k = 0; k < post.length; k++) {
3863
- const expansion = pre + N[j] + post[k]
3867
+ for (var j = 0; j < N.length; j++) {
3868
+ for (var k = 0; k < post.length; k++) {
3869
+ var expansion = pre + N[j] + post[k]
3864
3870
  if (!isTop || isSequence || expansion) {
3865
3871
  expansions.push(expansion)
3866
3872
  }
@@ -3869,7 +3875,7 @@ function requireCommonjs$6() {
3869
3875
  }
3870
3876
  return expansions
3871
3877
  }
3872
- return commonjs$5
3878
+ return braceExpansion
3873
3879
  }
3874
3880
 
3875
3881
  const assertValidPattern = {}
@@ -4773,13 +4779,22 @@ function require_escape$1() {
4773
4779
  return _escape$1
4774
4780
  }
4775
4781
 
4776
- let hasRequiredCommonjs$5
4777
- function requireCommonjs$5() {
4778
- if (hasRequiredCommonjs$5) {
4779
- return commonjs$6
4782
+ let hasRequiredCommonjs$4
4783
+ function requireCommonjs$4() {
4784
+ if (hasRequiredCommonjs$4) {
4785
+ return commonjs$3
4780
4786
  }
4781
- hasRequiredCommonjs$5 = 1
4787
+ hasRequiredCommonjs$4 = 1
4782
4788
  ;(function (exports) {
4789
+ const __importDefault =
4790
+ (this && this.__importDefault) ||
4791
+ function (mod) {
4792
+ return mod && mod.__esModule
4793
+ ? mod
4794
+ : {
4795
+ default: mod
4796
+ }
4797
+ }
4783
4798
  Object.defineProperty(exports, '__esModule', {
4784
4799
  value: true
4785
4800
  })
@@ -4796,7 +4811,7 @@ function requireCommonjs$5() {
4796
4811
  exports.sep =
4797
4812
  exports.minimatch =
4798
4813
  void 0
4799
- const brace_expansion_1 = requireCommonjs$6()
4814
+ const brace_expansion_1 = __importDefault(requireBraceExpansion())
4800
4815
  const assert_valid_pattern_js_1 = requireAssertValidPattern()
4801
4816
  const ast_js_1 = requireAst()
4802
4817
  const escape_js_1 = require_escape$1()
@@ -4964,7 +4979,7 @@ function requireCommonjs$5() {
4964
4979
  // shortcut. no need to expand.
4965
4980
  return [pattern]
4966
4981
  }
4967
- return (0, brace_expansion_1.expand)(pattern)
4982
+ return (0, brace_expansion_1.default)(pattern)
4968
4983
  }
4969
4984
  exports.braceExpand = braceExpand
4970
4985
  exports.minimatch.braceExpand = exports.braceExpand
@@ -5482,11 +5497,11 @@ function requireCommonjs$5() {
5482
5497
  pattern
5483
5498
  })
5484
5499
  this.debug('matchOne', file.length, pattern.length)
5485
- for (
5486
- var fi = 0, pi = 0, fl = file.length, pl = pattern.length;
5487
- fi < fl && pi < pl;
5488
- fi++, pi++
5489
- ) {
5500
+ let fi = 0,
5501
+ pi = 0,
5502
+ fl = file.length,
5503
+ pl = pattern.length
5504
+ for (; fi < fl && pi < pl; fi++, pi++) {
5490
5505
  this.debug('matchOne loop')
5491
5506
  const p = pattern[pi]
5492
5507
  const f = file[fi]
@@ -5726,1811 +5741,155 @@ function requireCommonjs$5() {
5726
5741
  })
5727
5742
  pp.forEach((p, i) => {
5728
5743
  const next = pp[i + 1]
5729
- const prev = pp[i - 1]
5730
- if (p !== exports.GLOBSTAR || prev === exports.GLOBSTAR) {
5731
- return
5732
- }
5733
- if (prev === undefined) {
5734
- if (next !== undefined && next !== exports.GLOBSTAR) {
5735
- pp[i + 1] = '(?:\\/|' + twoStar + '\\/)?' + next
5736
- } else {
5737
- pp[i] = twoStar
5738
- }
5739
- } else if (next === undefined) {
5740
- pp[i - 1] = prev + '(?:\\/|' + twoStar + ')?'
5741
- } else if (next !== exports.GLOBSTAR) {
5742
- pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + '\\/)' + next
5743
- pp[i + 1] = exports.GLOBSTAR
5744
- }
5745
- })
5746
- return pp.filter(p => p !== exports.GLOBSTAR).join('/')
5747
- })
5748
- .join('|')
5749
- // need to wrap in parens if we had more than one thing with |,
5750
- // otherwise only the first will be anchored to ^ and the last to $
5751
- const [open, close] = set.length > 1 ? ['(?:', ')'] : ['', '']
5752
- // must match entire pattern
5753
- // ending in a * or ** will make it less strict.
5754
- re = '^' + open + re + close + '$'
5755
- // can match anything, as long as it's not this.
5756
- if (this.negate) {
5757
- re = '^(?!' + re + ').+$'
5758
- }
5759
- try {
5760
- this.regexp = new RegExp(re, [...flags].join(''))
5761
- /* c8 ignore start */
5762
- } catch (ex) {
5763
- // should be impossible
5764
- this.regexp = false
5765
- }
5766
- /* c8 ignore stop */
5767
- return this.regexp
5768
- }
5769
- slashSplit(p) {
5770
- // if p starts with // on windows, we preserve that
5771
- // so that UNC paths aren't broken. Otherwise, any number of
5772
- // / characters are coalesced into one, unless
5773
- // preserveMultipleSlashes is set to true.
5774
- if (this.preserveMultipleSlashes) {
5775
- return p.split('/')
5776
- } else if (this.isWindows && /^\/\/[^/]+/.test(p)) {
5777
- // add an extra '' for the one we lose
5778
- return ['', ...p.split(/\/+/)]
5779
- } else {
5780
- return p.split(/\/+/)
5781
- }
5782
- }
5783
- match(f, partial = this.partial) {
5784
- this.debug('match', f, this.pattern)
5785
- // short-circuit in the case of busted things.
5786
- // comments, etc.
5787
- if (this.comment) {
5788
- return false
5789
- }
5790
- if (this.empty) {
5791
- return f === ''
5792
- }
5793
- if (f === '/' && partial) {
5794
- return true
5795
- }
5796
- const options = this.options
5797
- // windows: need to use /, not \
5798
- if (this.isWindows) {
5799
- f = f.split('\\').join('/')
5800
- }
5801
- // treat the test path as a set of pathparts.
5802
- const ff = this.slashSplit(f)
5803
- this.debug(this.pattern, 'split', ff)
5804
- // just ONE of the pattern sets in this.set needs to match
5805
- // in order for it to be valid. If negating, then just one
5806
- // match means that we have failed.
5807
- // Either way, return on the first hit.
5808
- const set = this.set
5809
- this.debug(this.pattern, 'set', set)
5810
- // Find the basename of the path by looking for the last non-empty segment
5811
- let filename = ff[ff.length - 1]
5812
- if (!filename) {
5813
- for (let i = ff.length - 2; !filename && i >= 0; i--) {
5814
- filename = ff[i]
5815
- }
5816
- }
5817
- for (let i = 0; i < set.length; i++) {
5818
- const pattern = set[i]
5819
- let file = ff
5820
- if (options.matchBase && pattern.length === 1) {
5821
- file = [filename]
5822
- }
5823
- const hit = this.matchOne(file, pattern, partial)
5824
- if (hit) {
5825
- if (options.flipNegate) {
5826
- return true
5827
- }
5828
- return !this.negate
5829
- }
5830
- }
5831
- // didn't get any hits. this is success if it's a negative
5832
- // pattern, failure otherwise.
5833
- if (options.flipNegate) {
5834
- return false
5835
- }
5836
- return this.negate
5837
- }
5838
- static defaults(def) {
5839
- return exports.minimatch.defaults(def).Minimatch
5840
- }
5841
- }
5842
- exports.Minimatch = Minimatch
5843
- /* c8 ignore start */
5844
- const ast_js_2 = requireAst()
5845
- Object.defineProperty(exports, 'AST', {
5846
- enumerable: true,
5847
- get: function () {
5848
- return ast_js_2.AST
5849
- }
5850
- })
5851
- const escape_js_2 = require_escape$1()
5852
- Object.defineProperty(exports, 'escape', {
5853
- enumerable: true,
5854
- get: function () {
5855
- return escape_js_2.escape
5856
- }
5857
- })
5858
- const unescape_js_2 = require_unescape()
5859
- Object.defineProperty(exports, 'unescape', {
5860
- enumerable: true,
5861
- get: function () {
5862
- return unescape_js_2.unescape
5863
- }
5864
- })
5865
- /* c8 ignore stop */
5866
- exports.minimatch.AST = ast_js_1.AST
5867
- exports.minimatch.Minimatch = Minimatch
5868
- exports.minimatch.escape = escape_js_1.escape
5869
- exports.minimatch.unescape = unescape_js_1.unescape
5870
- })(commonjs$6)
5871
- return commonjs$6
5872
- }
5873
-
5874
- const glob = {}
5875
-
5876
- const commonjs$3 = {}
5877
-
5878
- const commonjs$2 = {}
5879
-
5880
- let hasRequiredCommonjs$4
5881
- function requireCommonjs$4() {
5882
- if (hasRequiredCommonjs$4) {
5883
- return commonjs$2
5884
- }
5885
- hasRequiredCommonjs$4 = 1
5886
- /**
5887
- * @module LRUCache
5888
- */
5889
- Object.defineProperty(commonjs$2, '__esModule', {
5890
- value: true
5891
- })
5892
- commonjs$2.LRUCache = void 0
5893
- const perf =
5894
- typeof performance === 'object' &&
5895
- performance &&
5896
- typeof performance.now === 'function'
5897
- ? performance
5898
- : Date
5899
- const warned = new Set()
5900
- /* c8 ignore start */
5901
- const PROCESS = typeof process === 'object' && !!process ? process : {}
5902
- /* c8 ignore start */
5903
- const emitWarning = (msg, type, code, fn) => {
5904
- typeof PROCESS.emitWarning === 'function'
5905
- ? PROCESS.emitWarning(msg, type, code, fn)
5906
- : console.error(`[${code}] ${type}: ${msg}`)
5907
- }
5908
- let AC = globalThis.AbortController
5909
- let AS = globalThis.AbortSignal
5910
- /* c8 ignore start */
5911
- if (typeof AC === 'undefined') {
5912
- //@ts-ignore
5913
- AS = class AbortSignal {
5914
- onabort
5915
- _onabort = []
5916
- reason
5917
- aborted = false
5918
- addEventListener(_, fn) {
5919
- this._onabort.push(fn)
5920
- }
5921
- }
5922
- //@ts-ignore
5923
- AC = class AbortController {
5924
- constructor() {
5925
- warnACPolyfill()
5926
- }
5927
- signal = new AS()
5928
- abort(reason) {
5929
- if (this.signal.aborted) {
5930
- return
5931
- }
5932
- //@ts-ignore
5933
- this.signal.reason = reason
5934
- //@ts-ignore
5935
- this.signal.aborted = true
5936
- //@ts-ignore
5937
- for (const fn of this.signal._onabort) {
5938
- fn(reason)
5939
- }
5940
- this.signal.onabort?.(reason)
5941
- }
5942
- }
5943
- let printACPolyfillWarning =
5944
- PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== '1'
5945
- const warnACPolyfill = () => {
5946
- if (!printACPolyfillWarning) {
5947
- return
5948
- }
5949
- printACPolyfillWarning = false
5950
- emitWarning(
5951
- 'AbortController is not defined. If using lru-cache in ' +
5952
- 'node 14, load an AbortController polyfill from the ' +
5953
- '`node-abort-controller` package. A minimal polyfill is ' +
5954
- 'provided for use by LRUCache.fetch(), but it should not be ' +
5955
- 'relied upon in other contexts (eg, passing it to other APIs that ' +
5956
- 'use AbortController/AbortSignal might have undesirable effects). ' +
5957
- 'You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.',
5958
- 'NO_ABORT_CONTROLLER',
5959
- 'ENOTSUP',
5960
- warnACPolyfill
5961
- )
5962
- }
5963
- }
5964
- /* c8 ignore stop */
5965
- const shouldWarn = code => !warned.has(code)
5966
- const isPosInt = n => n && n === Math.floor(n) && n > 0 && isFinite(n)
5967
- /* c8 ignore start */
5968
- // This is a little bit ridiculous, tbh.
5969
- // The maximum array length is 2^32-1 or thereabouts on most JS impls.
5970
- // And well before that point, you're caching the entire world, I mean,
5971
- // that's ~32GB of just integers for the next/prev links, plus whatever
5972
- // else to hold that many keys and values. Just filling the memory with
5973
- // zeroes at init time is brutal when you get that big.
5974
- // But why not be complete?
5975
- // Maybe in the future, these limits will have expanded.
5976
- const getUintArray = max =>
5977
- !isPosInt(max)
5978
- ? null
5979
- : max <= Math.pow(2, 8)
5980
- ? Uint8Array
5981
- : max <= Math.pow(2, 16)
5982
- ? Uint16Array
5983
- : max <= Math.pow(2, 32)
5984
- ? Uint32Array
5985
- : max <= Number.MAX_SAFE_INTEGER
5986
- ? ZeroArray
5987
- : null
5988
- /* c8 ignore stop */
5989
- class ZeroArray extends Array {
5990
- constructor(size) {
5991
- super(size)
5992
- this.fill(0)
5993
- }
5994
- }
5995
- class Stack {
5996
- heap
5997
- length
5998
- // private constructor
5999
- static #constructing = false
6000
- static create(max) {
6001
- const HeapCls = getUintArray(max)
6002
- if (!HeapCls) {
6003
- return []
6004
- }
6005
- Stack.#constructing = true
6006
- const s = new Stack(max, HeapCls)
6007
- Stack.#constructing = false
6008
- return s
6009
- }
6010
- constructor(max, HeapCls) {
6011
- /* c8 ignore start */
6012
- if (!Stack.#constructing) {
6013
- throw new TypeError('instantiate Stack using Stack.create(n)')
6014
- }
6015
- /* c8 ignore stop */
6016
- this.heap = new HeapCls(max)
6017
- this.length = 0
6018
- }
6019
- push(n) {
6020
- this.heap[this.length++] = n
6021
- }
6022
- pop() {
6023
- return this.heap[--this.length]
6024
- }
6025
- }
6026
- /**
6027
- * Default export, the thing you're using this module to get.
6028
- *
6029
- * The `K` and `V` types define the key and value types, respectively. The
6030
- * optional `FC` type defines the type of the `context` object passed to
6031
- * `cache.fetch()` and `cache.memo()`.
6032
- *
6033
- * Keys and values **must not** be `null` or `undefined`.
6034
- *
6035
- * All properties from the options object (with the exception of `max`,
6036
- * `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
6037
- * added as normal public members. (The listed options are read-only getters.)
6038
- *
6039
- * Changing any of these will alter the defaults for subsequent method calls.
6040
- */
6041
- class LRUCache {
6042
- // options that cannot be changed without disaster
6043
- #max
6044
- #maxSize
6045
- #dispose
6046
- #onInsert
6047
- #disposeAfter
6048
- #fetchMethod
6049
- #memoMethod
6050
- /**
6051
- * {@link LRUCache.OptionsBase.ttl}
6052
- */
6053
- ttl
6054
- /**
6055
- * {@link LRUCache.OptionsBase.ttlResolution}
6056
- */
6057
- ttlResolution
6058
- /**
6059
- * {@link LRUCache.OptionsBase.ttlAutopurge}
6060
- */
6061
- ttlAutopurge
6062
- /**
6063
- * {@link LRUCache.OptionsBase.updateAgeOnGet}
6064
- */
6065
- updateAgeOnGet
6066
- /**
6067
- * {@link LRUCache.OptionsBase.updateAgeOnHas}
6068
- */
6069
- updateAgeOnHas
6070
- /**
6071
- * {@link LRUCache.OptionsBase.allowStale}
6072
- */
6073
- allowStale
6074
- /**
6075
- * {@link LRUCache.OptionsBase.noDisposeOnSet}
6076
- */
6077
- noDisposeOnSet
6078
- /**
6079
- * {@link LRUCache.OptionsBase.noUpdateTTL}
6080
- */
6081
- noUpdateTTL
6082
- /**
6083
- * {@link LRUCache.OptionsBase.maxEntrySize}
6084
- */
6085
- maxEntrySize
6086
- /**
6087
- * {@link LRUCache.OptionsBase.sizeCalculation}
6088
- */
6089
- sizeCalculation
6090
- /**
6091
- * {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
6092
- */
6093
- noDeleteOnFetchRejection
6094
- /**
6095
- * {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
6096
- */
6097
- noDeleteOnStaleGet
6098
- /**
6099
- * {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
6100
- */
6101
- allowStaleOnFetchAbort
6102
- /**
6103
- * {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
6104
- */
6105
- allowStaleOnFetchRejection
6106
- /**
6107
- * {@link LRUCache.OptionsBase.ignoreFetchAbort}
6108
- */
6109
- ignoreFetchAbort
6110
- // computed properties
6111
- #size
6112
- #calculatedSize
6113
- #keyMap
6114
- #keyList
6115
- #valList
6116
- #next
6117
- #prev
6118
- #head
6119
- #tail
6120
- #free
6121
- #disposed
6122
- #sizes
6123
- #starts
6124
- #ttls
6125
- #hasDispose
6126
- #hasFetchMethod
6127
- #hasDisposeAfter
6128
- #hasOnInsert
6129
- /**
6130
- * Do not call this method unless you need to inspect the
6131
- * inner workings of the cache. If anything returned by this
6132
- * object is modified in any way, strange breakage may occur.
6133
- *
6134
- * These fields are private for a reason!
6135
- *
6136
- * @internal
6137
- */
6138
- static unsafeExposeInternals(c) {
6139
- return {
6140
- // properties
6141
- starts: c.#starts,
6142
- ttls: c.#ttls,
6143
- sizes: c.#sizes,
6144
- keyMap: c.#keyMap,
6145
- keyList: c.#keyList,
6146
- valList: c.#valList,
6147
- next: c.#next,
6148
- prev: c.#prev,
6149
- get head() {
6150
- return c.#head
6151
- },
6152
- get tail() {
6153
- return c.#tail
6154
- },
6155
- free: c.#free,
6156
- // methods
6157
- isBackgroundFetch: p => c.#isBackgroundFetch(p),
6158
- backgroundFetch: (k, index, options, context) =>
6159
- c.#backgroundFetch(k, index, options, context),
6160
- moveToTail: index => c.#moveToTail(index),
6161
- indexes: options => c.#indexes(options),
6162
- rindexes: options => c.#rindexes(options),
6163
- isStale: index => c.#isStale(index)
6164
- }
6165
- }
6166
- // Protected read-only members
6167
- /**
6168
- * {@link LRUCache.OptionsBase.max} (read-only)
6169
- */
6170
- get max() {
6171
- return this.#max
6172
- }
6173
- /**
6174
- * {@link LRUCache.OptionsBase.maxSize} (read-only)
6175
- */
6176
- get maxSize() {
6177
- return this.#maxSize
6178
- }
6179
- /**
6180
- * The total computed size of items in the cache (read-only)
6181
- */
6182
- get calculatedSize() {
6183
- return this.#calculatedSize
6184
- }
6185
- /**
6186
- * The number of items stored in the cache (read-only)
6187
- */
6188
- get size() {
6189
- return this.#size
6190
- }
6191
- /**
6192
- * {@link LRUCache.OptionsBase.fetchMethod} (read-only)
6193
- */
6194
- get fetchMethod() {
6195
- return this.#fetchMethod
6196
- }
6197
- get memoMethod() {
6198
- return this.#memoMethod
6199
- }
6200
- /**
6201
- * {@link LRUCache.OptionsBase.dispose} (read-only)
6202
- */
6203
- get dispose() {
6204
- return this.#dispose
6205
- }
6206
- /**
6207
- * {@link LRUCache.OptionsBase.onInsert} (read-only)
6208
- */
6209
- get onInsert() {
6210
- return this.#onInsert
6211
- }
6212
- /**
6213
- * {@link LRUCache.OptionsBase.disposeAfter} (read-only)
6214
- */
6215
- get disposeAfter() {
6216
- return this.#disposeAfter
6217
- }
6218
- constructor(options) {
6219
- const {
6220
- max = 0,
6221
- ttl,
6222
- ttlResolution = 1,
6223
- ttlAutopurge,
6224
- updateAgeOnGet,
6225
- updateAgeOnHas,
6226
- allowStale,
6227
- dispose,
6228
- onInsert,
6229
- disposeAfter,
6230
- noDisposeOnSet,
6231
- noUpdateTTL,
6232
- maxSize = 0,
6233
- maxEntrySize = 0,
6234
- sizeCalculation,
6235
- fetchMethod,
6236
- memoMethod,
6237
- noDeleteOnFetchRejection,
6238
- noDeleteOnStaleGet,
6239
- allowStaleOnFetchRejection,
6240
- allowStaleOnFetchAbort,
6241
- ignoreFetchAbort
6242
- } = options
6243
- if (max !== 0 && !isPosInt(max)) {
6244
- throw new TypeError('max option must be a nonnegative integer')
6245
- }
6246
- const UintArray = max ? getUintArray(max) : Array
6247
- if (!UintArray) {
6248
- throw new Error('invalid max value: ' + max)
6249
- }
6250
- this.#max = max
6251
- this.#maxSize = maxSize
6252
- this.maxEntrySize = maxEntrySize || this.#maxSize
6253
- this.sizeCalculation = sizeCalculation
6254
- if (this.sizeCalculation) {
6255
- if (!this.#maxSize && !this.maxEntrySize) {
6256
- throw new TypeError(
6257
- 'cannot set sizeCalculation without setting maxSize or maxEntrySize'
6258
- )
6259
- }
6260
- if (typeof this.sizeCalculation !== 'function') {
6261
- throw new TypeError('sizeCalculation set to non-function')
6262
- }
6263
- }
6264
- if (memoMethod !== undefined && typeof memoMethod !== 'function') {
6265
- throw new TypeError('memoMethod must be a function if defined')
6266
- }
6267
- this.#memoMethod = memoMethod
6268
- if (fetchMethod !== undefined && typeof fetchMethod !== 'function') {
6269
- throw new TypeError('fetchMethod must be a function if specified')
6270
- }
6271
- this.#fetchMethod = fetchMethod
6272
- this.#hasFetchMethod = !!fetchMethod
6273
- this.#keyMap = new Map()
6274
- this.#keyList = new Array(max).fill(undefined)
6275
- this.#valList = new Array(max).fill(undefined)
6276
- this.#next = new UintArray(max)
6277
- this.#prev = new UintArray(max)
6278
- this.#head = 0
6279
- this.#tail = 0
6280
- this.#free = Stack.create(max)
6281
- this.#size = 0
6282
- this.#calculatedSize = 0
6283
- if (typeof dispose === 'function') {
6284
- this.#dispose = dispose
6285
- }
6286
- if (typeof onInsert === 'function') {
6287
- this.#onInsert = onInsert
6288
- }
6289
- if (typeof disposeAfter === 'function') {
6290
- this.#disposeAfter = disposeAfter
6291
- this.#disposed = []
6292
- } else {
6293
- this.#disposeAfter = undefined
6294
- this.#disposed = undefined
6295
- }
6296
- this.#hasDispose = !!this.#dispose
6297
- this.#hasOnInsert = !!this.#onInsert
6298
- this.#hasDisposeAfter = !!this.#disposeAfter
6299
- this.noDisposeOnSet = !!noDisposeOnSet
6300
- this.noUpdateTTL = !!noUpdateTTL
6301
- this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection
6302
- this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection
6303
- this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort
6304
- this.ignoreFetchAbort = !!ignoreFetchAbort
6305
- // NB: maxEntrySize is set to maxSize if it's set
6306
- if (this.maxEntrySize !== 0) {
6307
- if (this.#maxSize !== 0) {
6308
- if (!isPosInt(this.#maxSize)) {
6309
- throw new TypeError(
6310
- 'maxSize must be a positive integer if specified'
6311
- )
6312
- }
6313
- }
6314
- if (!isPosInt(this.maxEntrySize)) {
6315
- throw new TypeError(
6316
- 'maxEntrySize must be a positive integer if specified'
6317
- )
6318
- }
6319
- this.#initializeSizeTracking()
6320
- }
6321
- this.allowStale = !!allowStale
6322
- this.noDeleteOnStaleGet = !!noDeleteOnStaleGet
6323
- this.updateAgeOnGet = !!updateAgeOnGet
6324
- this.updateAgeOnHas = !!updateAgeOnHas
6325
- this.ttlResolution =
6326
- isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1
6327
- this.ttlAutopurge = !!ttlAutopurge
6328
- this.ttl = ttl || 0
6329
- if (this.ttl) {
6330
- if (!isPosInt(this.ttl)) {
6331
- throw new TypeError('ttl must be a positive integer if specified')
6332
- }
6333
- this.#initializeTTLTracking()
6334
- }
6335
- // do not allow completely unbounded caches
6336
- if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
6337
- throw new TypeError('At least one of max, maxSize, or ttl is required')
6338
- }
6339
- if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
6340
- const code = 'LRU_CACHE_UNBOUNDED'
6341
- if (shouldWarn(code)) {
6342
- warned.add(code)
6343
- const msg =
6344
- 'TTL caching without ttlAutopurge, max, or maxSize can ' +
6345
- 'result in unbounded memory consumption.'
6346
- emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache)
6347
- }
6348
- }
6349
- }
6350
- /**
6351
- * Return the number of ms left in the item's TTL. If item is not in cache,
6352
- * returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
6353
- */
6354
- getRemainingTTL(key) {
6355
- return this.#keyMap.has(key) ? Infinity : 0
6356
- }
6357
- #initializeTTLTracking() {
6358
- const ttls = new ZeroArray(this.#max)
6359
- const starts = new ZeroArray(this.#max)
6360
- this.#ttls = ttls
6361
- this.#starts = starts
6362
- this.#setItemTTL = (index, ttl, start = perf.now()) => {
6363
- starts[index] = ttl !== 0 ? start : 0
6364
- ttls[index] = ttl
6365
- if (ttl !== 0 && this.ttlAutopurge) {
6366
- const t = setTimeout(() => {
6367
- if (this.#isStale(index)) {
6368
- this.#delete(this.#keyList[index], 'expire')
6369
- }
6370
- }, ttl + 1)
6371
- // unref() not supported on all platforms
6372
- /* c8 ignore start */
6373
- if (t.unref) {
6374
- t.unref()
6375
- }
6376
- /* c8 ignore stop */
6377
- }
6378
- }
6379
- this.#updateItemAge = index => {
6380
- starts[index] = ttls[index] !== 0 ? perf.now() : 0
6381
- }
6382
- this.#statusTTL = (status, index) => {
6383
- if (ttls[index]) {
6384
- const ttl = ttls[index]
6385
- const start = starts[index]
6386
- /* c8 ignore next */
6387
- if (!ttl || !start) {
6388
- return
6389
- }
6390
- status.ttl = ttl
6391
- status.start = start
6392
- status.now = cachedNow || getNow()
6393
- const age = status.now - start
6394
- status.remainingTTL = ttl - age
6395
- }
6396
- }
6397
- // debounce calls to perf.now() to 1s so we're not hitting
6398
- // that costly call repeatedly.
6399
- let cachedNow = 0
6400
- const getNow = () => {
6401
- const n = perf.now()
6402
- if (this.ttlResolution > 0) {
6403
- cachedNow = n
6404
- const t = setTimeout(() => (cachedNow = 0), this.ttlResolution)
6405
- // not available on all platforms
6406
- /* c8 ignore start */
6407
- if (t.unref) {
6408
- t.unref()
6409
- }
6410
- /* c8 ignore stop */
6411
- }
6412
- return n
6413
- }
6414
- this.getRemainingTTL = key => {
6415
- const index = this.#keyMap.get(key)
6416
- if (index === undefined) {
6417
- return 0
6418
- }
6419
- const ttl = ttls[index]
6420
- const start = starts[index]
6421
- if (!ttl || !start) {
6422
- return Infinity
6423
- }
6424
- const age = (cachedNow || getNow()) - start
6425
- return ttl - age
6426
- }
6427
- this.#isStale = index => {
6428
- const s = starts[index]
6429
- const t = ttls[index]
6430
- return !!t && !!s && (cachedNow || getNow()) - s > t
6431
- }
6432
- }
6433
- // conditionally set private methods related to TTL
6434
- #updateItemAge = () => {}
6435
- #statusTTL = () => {}
6436
- #setItemTTL = () => {}
6437
- /* c8 ignore stop */
6438
- #isStale = () => false
6439
- #initializeSizeTracking() {
6440
- const sizes = new ZeroArray(this.#max)
6441
- this.#calculatedSize = 0
6442
- this.#sizes = sizes
6443
- this.#removeItemSize = index => {
6444
- this.#calculatedSize -= sizes[index]
6445
- sizes[index] = 0
6446
- }
6447
- this.#requireSize = (k, v, size, sizeCalculation) => {
6448
- // provisionally accept background fetches.
6449
- // actual value size will be checked when they return.
6450
- if (this.#isBackgroundFetch(v)) {
6451
- return 0
6452
- }
6453
- if (!isPosInt(size)) {
6454
- if (sizeCalculation) {
6455
- if (typeof sizeCalculation !== 'function') {
6456
- throw new TypeError('sizeCalculation must be a function')
6457
- }
6458
- size = sizeCalculation(v, k)
6459
- if (!isPosInt(size)) {
6460
- throw new TypeError(
6461
- 'sizeCalculation return invalid (expect positive integer)'
6462
- )
6463
- }
6464
- } else {
6465
- throw new TypeError(
6466
- 'invalid size value (must be positive integer). ' +
6467
- 'When maxSize or maxEntrySize is used, sizeCalculation ' +
6468
- 'or size must be set.'
6469
- )
6470
- }
6471
- }
6472
- return size
6473
- }
6474
- this.#addItemSize = (index, size, status) => {
6475
- sizes[index] = size
6476
- if (this.#maxSize) {
6477
- const maxSize = this.#maxSize - sizes[index]
6478
- while (this.#calculatedSize > maxSize) {
6479
- this.#evict(true)
6480
- }
6481
- }
6482
- this.#calculatedSize += sizes[index]
6483
- if (status) {
6484
- status.entrySize = size
6485
- status.totalCalculatedSize = this.#calculatedSize
6486
- }
6487
- }
6488
- }
6489
- #removeItemSize = _i => {}
6490
- #addItemSize = (_i, _s, _st) => {}
6491
- #requireSize = (_k, _v, size, sizeCalculation) => {
6492
- if (size || sizeCalculation) {
6493
- throw new TypeError(
6494
- 'cannot set size without setting maxSize or maxEntrySize on cache'
6495
- )
6496
- }
6497
- return 0
6498
- };
6499
- *#indexes({ allowStale = this.allowStale } = {}) {
6500
- if (this.#size) {
6501
- for (let i = this.#tail; true; ) {
6502
- if (!this.#isValidIndex(i)) {
6503
- break
6504
- }
6505
- if (allowStale || !this.#isStale(i)) {
6506
- yield i
6507
- }
6508
- if (i === this.#head) {
6509
- break
6510
- } else {
6511
- i = this.#prev[i]
6512
- }
6513
- }
6514
- }
6515
- }
6516
- *#rindexes({ allowStale = this.allowStale } = {}) {
6517
- if (this.#size) {
6518
- for (let i = this.#head; true; ) {
6519
- if (!this.#isValidIndex(i)) {
6520
- break
6521
- }
6522
- if (allowStale || !this.#isStale(i)) {
6523
- yield i
6524
- }
6525
- if (i === this.#tail) {
6526
- break
6527
- } else {
6528
- i = this.#next[i]
6529
- }
6530
- }
6531
- }
6532
- }
6533
- #isValidIndex(index) {
6534
- return (
6535
- index !== undefined && this.#keyMap.get(this.#keyList[index]) === index
6536
- )
6537
- }
6538
- /**
6539
- * Return a generator yielding `[key, value]` pairs,
6540
- * in order from most recently used to least recently used.
6541
- */
6542
- *entries() {
6543
- for (const i of this.#indexes()) {
6544
- if (
6545
- this.#valList[i] !== undefined &&
6546
- this.#keyList[i] !== undefined &&
6547
- !this.#isBackgroundFetch(this.#valList[i])
6548
- ) {
6549
- yield [this.#keyList[i], this.#valList[i]]
6550
- }
6551
- }
6552
- }
6553
- /**
6554
- * Inverse order version of {@link LRUCache.entries}
6555
- *
6556
- * Return a generator yielding `[key, value]` pairs,
6557
- * in order from least recently used to most recently used.
6558
- */
6559
- *rentries() {
6560
- for (const i of this.#rindexes()) {
6561
- if (
6562
- this.#valList[i] !== undefined &&
6563
- this.#keyList[i] !== undefined &&
6564
- !this.#isBackgroundFetch(this.#valList[i])
6565
- ) {
6566
- yield [this.#keyList[i], this.#valList[i]]
6567
- }
6568
- }
6569
- }
6570
- /**
6571
- * Return a generator yielding the keys in the cache,
6572
- * in order from most recently used to least recently used.
6573
- */
6574
- *keys() {
6575
- for (const i of this.#indexes()) {
6576
- const k = this.#keyList[i]
6577
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
6578
- yield k
6579
- }
6580
- }
6581
- }
6582
- /**
6583
- * Inverse order version of {@link LRUCache.keys}
6584
- *
6585
- * Return a generator yielding the keys in the cache,
6586
- * in order from least recently used to most recently used.
6587
- */
6588
- *rkeys() {
6589
- for (const i of this.#rindexes()) {
6590
- const k = this.#keyList[i]
6591
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
6592
- yield k
6593
- }
6594
- }
6595
- }
6596
- /**
6597
- * Return a generator yielding the values in the cache,
6598
- * in order from most recently used to least recently used.
6599
- */
6600
- *values() {
6601
- for (const i of this.#indexes()) {
6602
- const v = this.#valList[i]
6603
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
6604
- yield this.#valList[i]
6605
- }
6606
- }
6607
- }
6608
- /**
6609
- * Inverse order version of {@link LRUCache.values}
6610
- *
6611
- * Return a generator yielding the values in the cache,
6612
- * in order from least recently used to most recently used.
6613
- */
6614
- *rvalues() {
6615
- for (const i of this.#rindexes()) {
6616
- const v = this.#valList[i]
6617
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
6618
- yield this.#valList[i]
6619
- }
6620
- }
6621
- }
6622
- /**
6623
- * Iterating over the cache itself yields the same results as
6624
- * {@link LRUCache.entries}
6625
- */
6626
- [Symbol.iterator]() {
6627
- return this.entries()
6628
- }
6629
- /**
6630
- * A String value that is used in the creation of the default string
6631
- * description of an object. Called by the built-in method
6632
- * `Object.prototype.toString`.
6633
- */
6634
- [Symbol.toStringTag] = 'LRUCache'
6635
- /**
6636
- * Find a value for which the supplied fn method returns a truthy value,
6637
- * similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
6638
- */
6639
- find(fn, getOptions = {}) {
6640
- for (const i of this.#indexes()) {
6641
- const v = this.#valList[i]
6642
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
6643
- if (value === undefined) {
6644
- continue
6645
- }
6646
- if (fn(value, this.#keyList[i], this)) {
6647
- return this.get(this.#keyList[i], getOptions)
6648
- }
6649
- }
6650
- }
6651
- /**
6652
- * Call the supplied function on each item in the cache, in order from most
6653
- * recently used to least recently used.
6654
- *
6655
- * `fn` is called as `fn(value, key, cache)`.
6656
- *
6657
- * If `thisp` is provided, function will be called in the `this`-context of
6658
- * the provided object, or the cache if no `thisp` object is provided.
6659
- *
6660
- * Does not update age or recenty of use, or iterate over stale values.
6661
- */
6662
- forEach(fn, thisp = this) {
6663
- for (const i of this.#indexes()) {
6664
- const v = this.#valList[i]
6665
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
6666
- if (value === undefined) {
6667
- continue
6668
- }
6669
- fn.call(thisp, value, this.#keyList[i], this)
6670
- }
6671
- }
6672
- /**
6673
- * The same as {@link LRUCache.forEach} but items are iterated over in
6674
- * reverse order. (ie, less recently used items are iterated over first.)
6675
- */
6676
- rforEach(fn, thisp = this) {
6677
- for (const i of this.#rindexes()) {
6678
- const v = this.#valList[i]
6679
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
6680
- if (value === undefined) {
6681
- continue
6682
- }
6683
- fn.call(thisp, value, this.#keyList[i], this)
6684
- }
6685
- }
6686
- /**
6687
- * Delete any stale entries. Returns true if anything was removed,
6688
- * false otherwise.
6689
- */
6690
- purgeStale() {
6691
- let deleted = false
6692
- for (const i of this.#rindexes({
6693
- allowStale: true
6694
- })) {
6695
- if (this.#isStale(i)) {
6696
- this.#delete(this.#keyList[i], 'expire')
6697
- deleted = true
6698
- }
6699
- }
6700
- return deleted
6701
- }
6702
- /**
6703
- * Get the extended info about a given entry, to get its value, size, and
6704
- * TTL info simultaneously. Returns `undefined` if the key is not present.
6705
- *
6706
- * Unlike {@link LRUCache#dump}, which is designed to be portable and survive
6707
- * serialization, the `start` value is always the current timestamp, and the
6708
- * `ttl` is a calculated remaining time to live (negative if expired).
6709
- *
6710
- * Always returns stale values, if their info is found in the cache, so be
6711
- * sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
6712
- * if relevant.
6713
- */
6714
- info(key) {
6715
- const i = this.#keyMap.get(key)
6716
- if (i === undefined) {
6717
- return undefined
6718
- }
6719
- const v = this.#valList[i]
6720
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
6721
- if (value === undefined) {
6722
- return undefined
6723
- }
6724
- const entry = {
6725
- value
6726
- }
6727
- if (this.#ttls && this.#starts) {
6728
- const ttl = this.#ttls[i]
6729
- const start = this.#starts[i]
6730
- if (ttl && start) {
6731
- const remain = ttl - (perf.now() - start)
6732
- entry.ttl = remain
6733
- entry.start = Date.now()
6734
- }
6735
- }
6736
- if (this.#sizes) {
6737
- entry.size = this.#sizes[i]
6738
- }
6739
- return entry
6740
- }
6741
- /**
6742
- * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
6743
- * passed to {@link LRUCache#load}.
6744
- *
6745
- * The `start` fields are calculated relative to a portable `Date.now()`
6746
- * timestamp, even if `performance.now()` is available.
6747
- *
6748
- * Stale entries are always included in the `dump`, even if
6749
- * {@link LRUCache.OptionsBase.allowStale} is false.
6750
- *
6751
- * Note: this returns an actual array, not a generator, so it can be more
6752
- * easily passed around.
6753
- */
6754
- dump() {
6755
- const arr = []
6756
- for (const i of this.#indexes({
6757
- allowStale: true
6758
- })) {
6759
- const key = this.#keyList[i]
6760
- const v = this.#valList[i]
6761
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
6762
- if (value === undefined || key === undefined) {
6763
- continue
6764
- }
6765
- const entry = {
6766
- value
6767
- }
6768
- if (this.#ttls && this.#starts) {
6769
- entry.ttl = this.#ttls[i]
6770
- // always dump the start relative to a portable timestamp
6771
- // it's ok for this to be a bit slow, it's a rare operation.
6772
- const age = perf.now() - this.#starts[i]
6773
- entry.start = Math.floor(Date.now() - age)
6774
- }
6775
- if (this.#sizes) {
6776
- entry.size = this.#sizes[i]
6777
- }
6778
- arr.unshift([key, entry])
6779
- }
6780
- return arr
6781
- }
6782
- /**
6783
- * Reset the cache and load in the items in entries in the order listed.
6784
- *
6785
- * The shape of the resulting cache may be different if the same options are
6786
- * not used in both caches.
6787
- *
6788
- * The `start` fields are assumed to be calculated relative to a portable
6789
- * `Date.now()` timestamp, even if `performance.now()` is available.
6790
- */
6791
- load(arr) {
6792
- this.clear()
6793
- for (const [key, entry] of arr) {
6794
- if (entry.start) {
6795
- // entry.start is a portable timestamp, but we may be using
6796
- // node's performance.now(), so calculate the offset, so that
6797
- // we get the intended remaining TTL, no matter how long it's
6798
- // been on ice.
6799
- //
6800
- // it's ok for this to be a bit slow, it's a rare operation.
6801
- const age = Date.now() - entry.start
6802
- entry.start = perf.now() - age
6803
- }
6804
- this.set(key, entry.value, entry)
6805
- }
6806
- }
6807
- /**
6808
- * Add a value to the cache.
6809
- *
6810
- * Note: if `undefined` is specified as a value, this is an alias for
6811
- * {@link LRUCache#delete}
6812
- *
6813
- * Fields on the {@link LRUCache.SetOptions} options param will override
6814
- * their corresponding values in the constructor options for the scope
6815
- * of this single `set()` operation.
6816
- *
6817
- * If `start` is provided, then that will set the effective start
6818
- * time for the TTL calculation. Note that this must be a previous
6819
- * value of `performance.now()` if supported, or a previous value of
6820
- * `Date.now()` if not.
6821
- *
6822
- * Options object may also include `size`, which will prevent
6823
- * calling the `sizeCalculation` function and just use the specified
6824
- * number if it is a positive integer, and `noDisposeOnSet` which
6825
- * will prevent calling a `dispose` function in the case of
6826
- * overwrites.
6827
- *
6828
- * If the `size` (or return value of `sizeCalculation`) for a given
6829
- * entry is greater than `maxEntrySize`, then the item will not be
6830
- * added to the cache.
6831
- *
6832
- * Will update the recency of the entry.
6833
- *
6834
- * If the value is `undefined`, then this is an alias for
6835
- * `cache.delete(key)`. `undefined` is never stored in the cache.
6836
- */
6837
- set(k, v, setOptions = {}) {
6838
- if (v === undefined) {
6839
- this.delete(k)
6840
- return this
6841
- }
6842
- const {
6843
- ttl = this.ttl,
6844
- start,
6845
- noDisposeOnSet = this.noDisposeOnSet,
6846
- sizeCalculation = this.sizeCalculation,
6847
- status
6848
- } = setOptions
6849
- let { noUpdateTTL = this.noUpdateTTL } = setOptions
6850
- const size = this.#requireSize(
6851
- k,
6852
- v,
6853
- setOptions.size || 0,
6854
- sizeCalculation
6855
- )
6856
- // if the item doesn't fit, don't do anything
6857
- // NB: maxEntrySize set to maxSize by default
6858
- if (this.maxEntrySize && size > this.maxEntrySize) {
6859
- if (status) {
6860
- status.set = 'miss'
6861
- status.maxEntrySizeExceeded = true
6862
- }
6863
- // have to delete, in case something is there already.
6864
- this.#delete(k, 'set')
6865
- return this
6866
- }
6867
- let index = this.#size === 0 ? undefined : this.#keyMap.get(k)
6868
- if (index === undefined) {
6869
- // addition
6870
- index =
6871
- this.#size === 0
6872
- ? this.#tail
6873
- : this.#free.length !== 0
6874
- ? this.#free.pop()
6875
- : this.#size === this.#max
6876
- ? this.#evict(false)
6877
- : this.#size
6878
- this.#keyList[index] = k
6879
- this.#valList[index] = v
6880
- this.#keyMap.set(k, index)
6881
- this.#next[this.#tail] = index
6882
- this.#prev[index] = this.#tail
6883
- this.#tail = index
6884
- this.#size++
6885
- this.#addItemSize(index, size, status)
6886
- if (status) {
6887
- status.set = 'add'
6888
- }
6889
- noUpdateTTL = false
6890
- if (this.#hasOnInsert) {
6891
- this.#onInsert?.(v, k, 'add')
6892
- }
6893
- } else {
6894
- // update
6895
- this.#moveToTail(index)
6896
- const oldVal = this.#valList[index]
6897
- if (v !== oldVal) {
6898
- if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
6899
- oldVal.__abortController.abort(new Error('replaced'))
6900
- const { __staleWhileFetching: s } = oldVal
6901
- if (s !== undefined && !noDisposeOnSet) {
6902
- if (this.#hasDispose) {
6903
- this.#dispose?.(s, k, 'set')
6904
- }
6905
- if (this.#hasDisposeAfter) {
6906
- this.#disposed?.push([s, k, 'set'])
6907
- }
6908
- }
6909
- } else if (!noDisposeOnSet) {
6910
- if (this.#hasDispose) {
6911
- this.#dispose?.(oldVal, k, 'set')
6912
- }
6913
- if (this.#hasDisposeAfter) {
6914
- this.#disposed?.push([oldVal, k, 'set'])
6915
- }
6916
- }
6917
- this.#removeItemSize(index)
6918
- this.#addItemSize(index, size, status)
6919
- this.#valList[index] = v
6920
- if (status) {
6921
- status.set = 'replace'
6922
- const oldValue =
6923
- oldVal && this.#isBackgroundFetch(oldVal)
6924
- ? oldVal.__staleWhileFetching
6925
- : oldVal
6926
- if (oldValue !== undefined) {
6927
- status.oldValue = oldValue
6928
- }
6929
- }
6930
- } else if (status) {
6931
- status.set = 'update'
6932
- }
6933
- if (this.#hasOnInsert) {
6934
- this.onInsert?.(v, k, v === oldVal ? 'update' : 'replace')
6935
- }
6936
- }
6937
- if (ttl !== 0 && !this.#ttls) {
6938
- this.#initializeTTLTracking()
6939
- }
6940
- if (this.#ttls) {
6941
- if (!noUpdateTTL) {
6942
- this.#setItemTTL(index, ttl, start)
6943
- }
6944
- if (status) {
6945
- this.#statusTTL(status, index)
6946
- }
6947
- }
6948
- if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
6949
- const dt = this.#disposed
6950
- let task
6951
- while ((task = dt?.shift())) {
6952
- this.#disposeAfter?.(...task)
6953
- }
6954
- }
6955
- return this
6956
- }
6957
- /**
6958
- * Evict the least recently used item, returning its value or
6959
- * `undefined` if cache is empty.
6960
- */
6961
- pop() {
6962
- try {
6963
- while (this.#size) {
6964
- const val = this.#valList[this.#head]
6965
- this.#evict(true)
6966
- if (this.#isBackgroundFetch(val)) {
6967
- if (val.__staleWhileFetching) {
6968
- return val.__staleWhileFetching
6969
- }
6970
- } else if (val !== undefined) {
6971
- return val
6972
- }
6973
- }
6974
- } finally {
6975
- if (this.#hasDisposeAfter && this.#disposed) {
6976
- const dt = this.#disposed
6977
- let task
6978
- while ((task = dt?.shift())) {
6979
- this.#disposeAfter?.(...task)
6980
- }
6981
- }
6982
- }
6983
- }
6984
- #evict(free) {
6985
- const head = this.#head
6986
- const k = this.#keyList[head]
6987
- const v = this.#valList[head]
6988
- if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
6989
- v.__abortController.abort(new Error('evicted'))
6990
- } else if (this.#hasDispose || this.#hasDisposeAfter) {
6991
- if (this.#hasDispose) {
6992
- this.#dispose?.(v, k, 'evict')
6993
- }
6994
- if (this.#hasDisposeAfter) {
6995
- this.#disposed?.push([v, k, 'evict'])
6996
- }
6997
- }
6998
- this.#removeItemSize(head)
6999
- // if we aren't about to use the index, then null these out
7000
- if (free) {
7001
- this.#keyList[head] = undefined
7002
- this.#valList[head] = undefined
7003
- this.#free.push(head)
7004
- }
7005
- if (this.#size === 1) {
7006
- this.#head = this.#tail = 0
7007
- this.#free.length = 0
7008
- } else {
7009
- this.#head = this.#next[head]
7010
- }
7011
- this.#keyMap.delete(k)
7012
- this.#size--
7013
- return head
7014
- }
7015
- /**
7016
- * Check if a key is in the cache, without updating the recency of use.
7017
- * Will return false if the item is stale, even though it is technically
7018
- * in the cache.
7019
- *
7020
- * Check if a key is in the cache, without updating the recency of
7021
- * use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
7022
- * to `true` in either the options or the constructor.
7023
- *
7024
- * Will return `false` if the item is stale, even though it is technically in
7025
- * the cache. The difference can be determined (if it matters) by using a
7026
- * `status` argument, and inspecting the `has` field.
7027
- *
7028
- * Will not update item age unless
7029
- * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
7030
- */
7031
- has(k, hasOptions = {}) {
7032
- const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions
7033
- const index = this.#keyMap.get(k)
7034
- if (index !== undefined) {
7035
- const v = this.#valList[index]
7036
- if (
7037
- this.#isBackgroundFetch(v) &&
7038
- v.__staleWhileFetching === undefined
7039
- ) {
7040
- return false
7041
- }
7042
- if (!this.#isStale(index)) {
7043
- if (updateAgeOnHas) {
7044
- this.#updateItemAge(index)
7045
- }
7046
- if (status) {
7047
- status.has = 'hit'
7048
- this.#statusTTL(status, index)
7049
- }
7050
- return true
7051
- } else if (status) {
7052
- status.has = 'stale'
7053
- this.#statusTTL(status, index)
7054
- }
7055
- } else if (status) {
7056
- status.has = 'miss'
7057
- }
7058
- return false
7059
- }
7060
- /**
7061
- * Like {@link LRUCache#get} but doesn't update recency or delete stale
7062
- * items.
7063
- *
7064
- * Returns `undefined` if the item is stale, unless
7065
- * {@link LRUCache.OptionsBase.allowStale} is set.
7066
- */
7067
- peek(k, peekOptions = {}) {
7068
- const { allowStale = this.allowStale } = peekOptions
7069
- const index = this.#keyMap.get(k)
7070
- if (index === undefined || (!allowStale && this.#isStale(index))) {
7071
- return
7072
- }
7073
- const v = this.#valList[index]
7074
- // either stale and allowed, or forcing a refresh of non-stale value
7075
- return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
7076
- }
7077
- #backgroundFetch(k, index, options, context) {
7078
- const v = index === undefined ? undefined : this.#valList[index]
7079
- if (this.#isBackgroundFetch(v)) {
7080
- return v
7081
- }
7082
- const ac = new AC()
7083
- const { signal } = options
7084
- // when/if our AC signals, then stop listening to theirs.
7085
- signal?.addEventListener('abort', () => ac.abort(signal.reason), {
7086
- signal: ac.signal
7087
- })
7088
- const fetchOpts = {
7089
- signal: ac.signal,
7090
- options,
7091
- context
7092
- }
7093
- const cb = (v, updateCache = false) => {
7094
- const { aborted } = ac.signal
7095
- const ignoreAbort = options.ignoreFetchAbort && v !== undefined
7096
- if (options.status) {
7097
- if (aborted && !updateCache) {
7098
- options.status.fetchAborted = true
7099
- options.status.fetchError = ac.signal.reason
7100
- if (ignoreAbort) {
7101
- options.status.fetchAbortIgnored = true
7102
- }
7103
- } else {
7104
- options.status.fetchResolved = true
7105
- }
7106
- }
7107
- if (aborted && !ignoreAbort && !updateCache) {
7108
- return fetchFail(ac.signal.reason)
7109
- }
7110
- // either we didn't abort, and are still here, or we did, and ignored
7111
- const bf = p
7112
- if (this.#valList[index] === p) {
7113
- if (v === undefined) {
7114
- if (bf.__staleWhileFetching) {
7115
- this.#valList[index] = bf.__staleWhileFetching
7116
- } else {
7117
- this.#delete(k, 'fetch')
7118
- }
7119
- } else {
7120
- if (options.status) {
7121
- options.status.fetchUpdated = true
7122
- }
7123
- this.set(k, v, fetchOpts.options)
7124
- }
7125
- }
7126
- return v
7127
- }
7128
- const eb = er => {
7129
- if (options.status) {
7130
- options.status.fetchRejected = true
7131
- options.status.fetchError = er
7132
- }
7133
- return fetchFail(er)
7134
- }
7135
- const fetchFail = er => {
7136
- const { aborted } = ac.signal
7137
- const allowStaleAborted = aborted && options.allowStaleOnFetchAbort
7138
- const allowStale =
7139
- allowStaleAborted || options.allowStaleOnFetchRejection
7140
- const noDelete = allowStale || options.noDeleteOnFetchRejection
7141
- const bf = p
7142
- if (this.#valList[index] === p) {
7143
- // if we allow stale on fetch rejections, then we need to ensure that
7144
- // the stale value is not removed from the cache when the fetch fails.
7145
- const del = !noDelete || bf.__staleWhileFetching === undefined
7146
- if (del) {
7147
- this.#delete(k, 'fetch')
7148
- } else if (!allowStaleAborted) {
7149
- // still replace the *promise* with the stale value,
7150
- // since we are done with the promise at this point.
7151
- // leave it untouched if we're still waiting for an
7152
- // aborted background fetch that hasn't yet returned.
7153
- this.#valList[index] = bf.__staleWhileFetching
7154
- }
7155
- }
7156
- if (allowStale) {
7157
- if (options.status && bf.__staleWhileFetching !== undefined) {
7158
- options.status.returnedStale = true
7159
- }
7160
- return bf.__staleWhileFetching
7161
- } else if (bf.__returned === bf) {
7162
- throw er
7163
- }
7164
- }
7165
- const pcall = (res, rej) => {
7166
- const fmp = this.#fetchMethod?.(k, v, fetchOpts)
7167
- if (fmp && fmp instanceof Promise) {
7168
- fmp.then(v => res(v === undefined ? undefined : v), rej)
7169
- }
7170
- // ignored, we go until we finish, regardless.
7171
- // defer check until we are actually aborting,
7172
- // so fetchMethod can override.
7173
- ac.signal.addEventListener('abort', () => {
7174
- if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
7175
- res(undefined)
7176
- // when it eventually resolves, update the cache.
7177
- if (options.allowStaleOnFetchAbort) {
7178
- res = v => cb(v, true)
7179
- }
7180
- }
7181
- })
7182
- }
7183
- if (options.status) {
7184
- options.status.fetchDispatched = true
7185
- }
7186
- const p = new Promise(pcall).then(cb, eb)
7187
- const bf = Object.assign(p, {
7188
- __abortController: ac,
7189
- __staleWhileFetching: v,
7190
- __returned: undefined
7191
- })
7192
- if (index === undefined) {
7193
- // internal, don't expose status.
7194
- this.set(k, bf, {
7195
- ...fetchOpts.options,
7196
- status: undefined
7197
- })
7198
- index = this.#keyMap.get(k)
7199
- } else {
7200
- this.#valList[index] = bf
7201
- }
7202
- return bf
7203
- }
7204
- #isBackgroundFetch(p) {
7205
- if (!this.#hasFetchMethod) {
7206
- return false
7207
- }
7208
- const b = p
7209
- return (
7210
- !!b &&
7211
- b instanceof Promise &&
7212
- b.hasOwnProperty('__staleWhileFetching') &&
7213
- b.__abortController instanceof AC
7214
- )
7215
- }
7216
- async fetch(k, fetchOptions = {}) {
7217
- const {
7218
- // get options
7219
- allowStale = this.allowStale,
7220
- updateAgeOnGet = this.updateAgeOnGet,
7221
- noDeleteOnStaleGet = this.noDeleteOnStaleGet,
7222
- // set options
7223
- ttl = this.ttl,
7224
- noDisposeOnSet = this.noDisposeOnSet,
7225
- size = 0,
7226
- sizeCalculation = this.sizeCalculation,
7227
- noUpdateTTL = this.noUpdateTTL,
7228
- // fetch exclusive options
7229
- noDeleteOnFetchRejection = this.noDeleteOnFetchRejection,
7230
- allowStaleOnFetchRejection = this.allowStaleOnFetchRejection,
7231
- ignoreFetchAbort = this.ignoreFetchAbort,
7232
- allowStaleOnFetchAbort = this.allowStaleOnFetchAbort,
7233
- context,
7234
- forceRefresh = false,
7235
- status,
7236
- signal
7237
- } = fetchOptions
7238
- if (!this.#hasFetchMethod) {
7239
- if (status) {
7240
- status.fetch = 'get'
7241
- }
7242
- return this.get(k, {
7243
- allowStale,
7244
- updateAgeOnGet,
7245
- noDeleteOnStaleGet,
7246
- status
7247
- })
7248
- }
7249
- const options = {
7250
- allowStale,
7251
- updateAgeOnGet,
7252
- noDeleteOnStaleGet,
7253
- ttl,
7254
- noDisposeOnSet,
7255
- size,
7256
- sizeCalculation,
7257
- noUpdateTTL,
7258
- noDeleteOnFetchRejection,
7259
- allowStaleOnFetchRejection,
7260
- allowStaleOnFetchAbort,
7261
- ignoreFetchAbort,
7262
- status,
7263
- signal
7264
- }
7265
- let index = this.#keyMap.get(k)
7266
- if (index === undefined) {
7267
- if (status) {
7268
- status.fetch = 'miss'
7269
- }
7270
- const p = this.#backgroundFetch(k, index, options, context)
7271
- return (p.__returned = p)
7272
- } else {
7273
- // in cache, maybe already fetching
7274
- const v = this.#valList[index]
7275
- if (this.#isBackgroundFetch(v)) {
7276
- const stale = allowStale && v.__staleWhileFetching !== undefined
7277
- if (status) {
7278
- status.fetch = 'inflight'
7279
- if (stale) {
7280
- status.returnedStale = true
7281
- }
7282
- }
7283
- return stale ? v.__staleWhileFetching : (v.__returned = v)
7284
- }
7285
- // if we force a refresh, that means do NOT serve the cached value,
7286
- // unless we are already in the process of refreshing the cache.
7287
- const isStale = this.#isStale(index)
7288
- if (!forceRefresh && !isStale) {
7289
- if (status) {
7290
- status.fetch = 'hit'
7291
- }
7292
- this.#moveToTail(index)
7293
- if (updateAgeOnGet) {
7294
- this.#updateItemAge(index)
7295
- }
7296
- if (status) {
7297
- this.#statusTTL(status, index)
7298
- }
7299
- return v
7300
- }
7301
- // ok, it is stale or a forced refresh, and not already fetching.
7302
- // refresh the cache.
7303
- const p = this.#backgroundFetch(k, index, options, context)
7304
- const hasStale = p.__staleWhileFetching !== undefined
7305
- const staleVal = hasStale && allowStale
7306
- if (status) {
7307
- status.fetch = isStale ? 'stale' : 'refresh'
7308
- if (staleVal && isStale) {
7309
- status.returnedStale = true
7310
- }
7311
- }
7312
- return staleVal ? p.__staleWhileFetching : (p.__returned = p)
7313
- }
7314
- }
7315
- async forceFetch(k, fetchOptions = {}) {
7316
- const v = await this.fetch(k, fetchOptions)
7317
- if (v === undefined) {
7318
- throw new Error('fetch() returned undefined')
7319
- }
7320
- return v
7321
- }
7322
- memo(k, memoOptions = {}) {
7323
- const memoMethod = this.#memoMethod
7324
- if (!memoMethod) {
7325
- throw new Error('no memoMethod provided to constructor')
7326
- }
7327
- const { context, forceRefresh, ...options } = memoOptions
7328
- const v = this.get(k, options)
7329
- if (!forceRefresh && v !== undefined) {
7330
- return v
7331
- }
7332
- const vv = memoMethod(k, v, {
7333
- options,
7334
- context
7335
- })
7336
- this.set(k, vv, options)
7337
- return vv
7338
- }
7339
- /**
7340
- * Return a value from the cache. Will update the recency of the cache
7341
- * entry found.
7342
- *
7343
- * If the key is not found, get() will return `undefined`.
7344
- */
7345
- get(k, getOptions = {}) {
7346
- const {
7347
- allowStale = this.allowStale,
7348
- updateAgeOnGet = this.updateAgeOnGet,
7349
- noDeleteOnStaleGet = this.noDeleteOnStaleGet,
7350
- status
7351
- } = getOptions
7352
- const index = this.#keyMap.get(k)
7353
- if (index !== undefined) {
7354
- const value = this.#valList[index]
7355
- const fetching = this.#isBackgroundFetch(value)
7356
- if (status) {
7357
- this.#statusTTL(status, index)
7358
- }
7359
- if (this.#isStale(index)) {
7360
- if (status) {
7361
- status.get = 'stale'
7362
- }
7363
- // delete only if not an in-flight background fetch
7364
- if (!fetching) {
7365
- if (!noDeleteOnStaleGet) {
7366
- this.#delete(k, 'expire')
7367
- }
7368
- if (status && allowStale) {
7369
- status.returnedStale = true
7370
- }
7371
- return allowStale ? value : undefined
7372
- } else {
7373
- if (
7374
- status &&
7375
- allowStale &&
7376
- value.__staleWhileFetching !== undefined
7377
- ) {
7378
- status.returnedStale = true
7379
- }
7380
- return allowStale ? value.__staleWhileFetching : undefined
7381
- }
7382
- } else {
7383
- if (status) {
7384
- status.get = 'hit'
7385
- }
7386
- // if we're currently fetching it, we don't actually have it yet
7387
- // it's not stale, which means this isn't a staleWhileRefetching.
7388
- // If it's not stale, and fetching, AND has a __staleWhileFetching
7389
- // value, then that means the user fetched with {forceRefresh:true},
7390
- // so it's safe to return that value.
7391
- if (fetching) {
7392
- return value.__staleWhileFetching
7393
- }
7394
- this.#moveToTail(index)
7395
- if (updateAgeOnGet) {
7396
- this.#updateItemAge(index)
7397
- }
7398
- return value
5744
+ const prev = pp[i - 1]
5745
+ if (p !== exports.GLOBSTAR || prev === exports.GLOBSTAR) {
5746
+ return
5747
+ }
5748
+ if (prev === undefined) {
5749
+ if (next !== undefined && next !== exports.GLOBSTAR) {
5750
+ pp[i + 1] = '(?:\\/|' + twoStar + '\\/)?' + next
5751
+ } else {
5752
+ pp[i] = twoStar
5753
+ }
5754
+ } else if (next === undefined) {
5755
+ pp[i - 1] = prev + '(?:\\/|' + twoStar + ')?'
5756
+ } else if (next !== exports.GLOBSTAR) {
5757
+ pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + '\\/)' + next
5758
+ pp[i + 1] = exports.GLOBSTAR
5759
+ }
5760
+ })
5761
+ return pp.filter(p => p !== exports.GLOBSTAR).join('/')
5762
+ })
5763
+ .join('|')
5764
+ // need to wrap in parens if we had more than one thing with |,
5765
+ // otherwise only the first will be anchored to ^ and the last to $
5766
+ const [open, close] = set.length > 1 ? ['(?:', ')'] : ['', '']
5767
+ // must match entire pattern
5768
+ // ending in a * or ** will make it less strict.
5769
+ re = '^' + open + re + close + '$'
5770
+ // can match anything, as long as it's not this.
5771
+ if (this.negate) {
5772
+ re = '^(?!' + re + ').+$'
7399
5773
  }
7400
- } else if (status) {
7401
- status.get = 'miss'
5774
+ try {
5775
+ this.regexp = new RegExp(re, [...flags].join(''))
5776
+ /* c8 ignore start */
5777
+ } catch (ex) {
5778
+ // should be impossible
5779
+ this.regexp = false
5780
+ }
5781
+ /* c8 ignore stop */
5782
+ return this.regexp
7402
5783
  }
7403
- }
7404
- #connect(p, n) {
7405
- this.#prev[n] = p
7406
- this.#next[p] = n
7407
- }
7408
- #moveToTail(index) {
7409
- // if tail already, nothing to do
7410
- // if head, move head to next[index]
7411
- // else
7412
- // move next[prev[index]] to next[index] (head has no prev)
7413
- // move prev[next[index]] to prev[index]
7414
- // prev[index] = tail
7415
- // next[tail] = index
7416
- // tail = index
7417
- if (index !== this.#tail) {
7418
- if (index === this.#head) {
7419
- this.#head = this.#next[index]
5784
+ slashSplit(p) {
5785
+ // if p starts with // on windows, we preserve that
5786
+ // so that UNC paths aren't broken. Otherwise, any number of
5787
+ // / characters are coalesced into one, unless
5788
+ // preserveMultipleSlashes is set to true.
5789
+ if (this.preserveMultipleSlashes) {
5790
+ return p.split('/')
5791
+ } else if (this.isWindows && /^\/\/[^/]+/.test(p)) {
5792
+ // add an extra '' for the one we lose
5793
+ return ['', ...p.split(/\/+/)]
7420
5794
  } else {
7421
- this.#connect(this.#prev[index], this.#next[index])
5795
+ return p.split(/\/+/)
7422
5796
  }
7423
- this.#connect(this.#tail, index)
7424
- this.#tail = index
7425
5797
  }
7426
- }
7427
- /**
7428
- * Deletes a key out of the cache.
7429
- *
7430
- * Returns true if the key was deleted, false otherwise.
7431
- */
7432
- delete(k) {
7433
- return this.#delete(k, 'delete')
7434
- }
7435
- #delete(k, reason) {
7436
- let deleted = false
7437
- if (this.#size !== 0) {
7438
- const index = this.#keyMap.get(k)
7439
- if (index !== undefined) {
7440
- deleted = true
7441
- if (this.#size === 1) {
7442
- this.#clear(reason)
7443
- } else {
7444
- this.#removeItemSize(index)
7445
- const v = this.#valList[index]
7446
- if (this.#isBackgroundFetch(v)) {
7447
- v.__abortController.abort(new Error('deleted'))
7448
- } else if (this.#hasDispose || this.#hasDisposeAfter) {
7449
- if (this.#hasDispose) {
7450
- this.#dispose?.(v, k, reason)
7451
- }
7452
- if (this.#hasDisposeAfter) {
7453
- this.#disposed?.push([v, k, reason])
7454
- }
7455
- }
7456
- this.#keyMap.delete(k)
7457
- this.#keyList[index] = undefined
7458
- this.#valList[index] = undefined
7459
- if (index === this.#tail) {
7460
- this.#tail = this.#prev[index]
7461
- } else if (index === this.#head) {
7462
- this.#head = this.#next[index]
7463
- } else {
7464
- const pi = this.#prev[index]
7465
- this.#next[pi] = this.#next[index]
7466
- const ni = this.#next[index]
7467
- this.#prev[ni] = this.#prev[index]
7468
- }
7469
- this.#size--
7470
- this.#free.push(index)
7471
- }
5798
+ match(f, partial = this.partial) {
5799
+ this.debug('match', f, this.pattern)
5800
+ // short-circuit in the case of busted things.
5801
+ // comments, etc.
5802
+ if (this.comment) {
5803
+ return false
7472
5804
  }
7473
- }
7474
- if (this.#hasDisposeAfter && this.#disposed?.length) {
7475
- const dt = this.#disposed
7476
- let task
7477
- while ((task = dt?.shift())) {
7478
- this.#disposeAfter?.(...task)
5805
+ if (this.empty) {
5806
+ return f === ''
7479
5807
  }
7480
- }
7481
- return deleted
7482
- }
7483
- /**
7484
- * Clear the cache entirely, throwing away all values.
7485
- */
7486
- clear() {
7487
- return this.#clear('delete')
7488
- }
7489
- #clear(reason) {
7490
- for (const index of this.#rindexes({
7491
- allowStale: true
7492
- })) {
7493
- const v = this.#valList[index]
7494
- if (this.#isBackgroundFetch(v)) {
7495
- v.__abortController.abort(new Error('deleted'))
7496
- } else {
7497
- const k = this.#keyList[index]
7498
- if (this.#hasDispose) {
7499
- this.#dispose?.(v, k, reason)
5808
+ if (f === '/' && partial) {
5809
+ return true
5810
+ }
5811
+ const options = this.options
5812
+ // windows: need to use /, not \
5813
+ if (this.isWindows) {
5814
+ f = f.split('\\').join('/')
5815
+ }
5816
+ // treat the test path as a set of pathparts.
5817
+ const ff = this.slashSplit(f)
5818
+ this.debug(this.pattern, 'split', ff)
5819
+ // just ONE of the pattern sets in this.set needs to match
5820
+ // in order for it to be valid. If negating, then just one
5821
+ // match means that we have failed.
5822
+ // Either way, return on the first hit.
5823
+ const set = this.set
5824
+ this.debug(this.pattern, 'set', set)
5825
+ // Find the basename of the path by looking for the last non-empty segment
5826
+ let filename = ff[ff.length - 1]
5827
+ if (!filename) {
5828
+ for (let i = ff.length - 2; !filename && i >= 0; i--) {
5829
+ filename = ff[i]
7500
5830
  }
7501
- if (this.#hasDisposeAfter) {
7502
- this.#disposed?.push([v, k, reason])
5831
+ }
5832
+ for (let i = 0; i < set.length; i++) {
5833
+ const pattern = set[i]
5834
+ let file = ff
5835
+ if (options.matchBase && pattern.length === 1) {
5836
+ file = [filename]
5837
+ }
5838
+ const hit = this.matchOne(file, pattern, partial)
5839
+ if (hit) {
5840
+ if (options.flipNegate) {
5841
+ return true
5842
+ }
5843
+ return !this.negate
7503
5844
  }
7504
5845
  }
5846
+ // didn't get any hits. this is success if it's a negative
5847
+ // pattern, failure otherwise.
5848
+ if (options.flipNegate) {
5849
+ return false
5850
+ }
5851
+ return this.negate
7505
5852
  }
7506
- this.#keyMap.clear()
7507
- this.#valList.fill(undefined)
7508
- this.#keyList.fill(undefined)
7509
- if (this.#ttls && this.#starts) {
7510
- this.#ttls.fill(0)
7511
- this.#starts.fill(0)
5853
+ static defaults(def) {
5854
+ return exports.minimatch.defaults(def).Minimatch
7512
5855
  }
7513
- if (this.#sizes) {
7514
- this.#sizes.fill(0)
5856
+ }
5857
+ exports.Minimatch = Minimatch
5858
+ /* c8 ignore start */
5859
+ const ast_js_2 = requireAst()
5860
+ Object.defineProperty(exports, 'AST', {
5861
+ enumerable: true,
5862
+ get: function () {
5863
+ return ast_js_2.AST
7515
5864
  }
7516
- this.#head = 0
7517
- this.#tail = 0
7518
- this.#free.length = 0
7519
- this.#calculatedSize = 0
7520
- this.#size = 0
7521
- if (this.#hasDisposeAfter && this.#disposed) {
7522
- const dt = this.#disposed
7523
- let task
7524
- while ((task = dt?.shift())) {
7525
- this.#disposeAfter?.(...task)
7526
- }
5865
+ })
5866
+ const escape_js_2 = require_escape$1()
5867
+ Object.defineProperty(exports, 'escape', {
5868
+ enumerable: true,
5869
+ get: function () {
5870
+ return escape_js_2.escape
7527
5871
  }
7528
- }
7529
- }
7530
- commonjs$2.LRUCache = LRUCache
7531
- return commonjs$2
5872
+ })
5873
+ const unescape_js_2 = require_unescape()
5874
+ Object.defineProperty(exports, 'unescape', {
5875
+ enumerable: true,
5876
+ get: function () {
5877
+ return unescape_js_2.unescape
5878
+ }
5879
+ })
5880
+ /* c8 ignore stop */
5881
+ exports.minimatch.AST = ast_js_1.AST
5882
+ exports.minimatch.Minimatch = Minimatch
5883
+ exports.minimatch.escape = escape_js_1.escape
5884
+ exports.minimatch.unescape = unescape_js_1.unescape
5885
+ })(commonjs$3)
5886
+ return commonjs$3
7532
5887
  }
7533
5888
 
5889
+ const glob = {}
5890
+
5891
+ const commonjs$2 = {}
5892
+
7534
5893
  const commonjs$1 = {}
7535
5894
 
7536
5895
  let hasRequiredCommonjs$3
@@ -8674,7 +7033,7 @@ function requireCommonjs$3() {
8674
7033
  let hasRequiredCommonjs$2
8675
7034
  function requireCommonjs$2() {
8676
7035
  if (hasRequiredCommonjs$2) {
8677
- return commonjs$3
7036
+ return commonjs$2
8678
7037
  }
8679
7038
  hasRequiredCommonjs$2 = 1
8680
7039
  const __createBinding =
@@ -8731,22 +7090,22 @@ function requireCommonjs$2() {
8731
7090
  __setModuleDefault(result, mod)
8732
7091
  return result
8733
7092
  }
8734
- Object.defineProperty(commonjs$3, '__esModule', {
7093
+ Object.defineProperty(commonjs$2, '__esModule', {
8735
7094
  value: true
8736
7095
  })
8737
- commonjs$3.PathScurry =
8738
- commonjs$3.Path =
8739
- commonjs$3.PathScurryDarwin =
8740
- commonjs$3.PathScurryPosix =
8741
- commonjs$3.PathScurryWin32 =
8742
- commonjs$3.PathScurryBase =
8743
- commonjs$3.PathPosix =
8744
- commonjs$3.PathWin32 =
8745
- commonjs$3.PathBase =
8746
- commonjs$3.ChildrenCache =
8747
- commonjs$3.ResolveCache =
7096
+ commonjs$2.PathScurry =
7097
+ commonjs$2.Path =
7098
+ commonjs$2.PathScurryDarwin =
7099
+ commonjs$2.PathScurryPosix =
7100
+ commonjs$2.PathScurryWin32 =
7101
+ commonjs$2.PathScurryBase =
7102
+ commonjs$2.PathPosix =
7103
+ commonjs$2.PathWin32 =
7104
+ commonjs$2.PathBase =
7105
+ commonjs$2.ChildrenCache =
7106
+ commonjs$2.ResolveCache =
8748
7107
  void 0
8749
- const lru_cache_1 = /*@__PURE__*/ requireCommonjs$4()
7108
+ const lru_cache_1 = /*@__PURE__*/ requireCommonjs$5()
8750
7109
  const node_path_1 = require$$2$2
8751
7110
  const node_url_1 = require$$0$3
8752
7111
  const fs_1 = require$$0$2
@@ -8862,7 +7221,7 @@ function requireCommonjs$2() {
8862
7221
  })
8863
7222
  }
8864
7223
  }
8865
- commonjs$3.ResolveCache = ResolveCache
7224
+ commonjs$2.ResolveCache = ResolveCache
8866
7225
  // In order to prevent blowing out the js heap by allocating hundreds of
8867
7226
  // thousands of Path entries when walking extremely large trees, the "children"
8868
7227
  // in this tree are represented by storing an array of Path entries in an
@@ -8887,7 +7246,7 @@ function requireCommonjs$2() {
8887
7246
  })
8888
7247
  }
8889
7248
  }
8890
- commonjs$3.ChildrenCache = ChildrenCache
7249
+ commonjs$2.ChildrenCache = ChildrenCache
8891
7250
  const setAsCwd = Symbol('PathScurry setAsCwd')
8892
7251
  /**
8893
7252
  * Path objects are sort of like a super-powered
@@ -9961,7 +8320,7 @@ function requireCommonjs$2() {
9961
8320
  }
9962
8321
  }
9963
8322
  }
9964
- commonjs$3.PathBase = PathBase
8323
+ commonjs$2.PathBase = PathBase
9965
8324
  /**
9966
8325
  * Path class used on win32 systems
9967
8326
  *
@@ -10037,7 +8396,7 @@ function requireCommonjs$2() {
10037
8396
  return rootPath === compare
10038
8397
  }
10039
8398
  }
10040
- commonjs$3.PathWin32 = PathWin32
8399
+ commonjs$2.PathWin32 = PathWin32
10041
8400
  /**
10042
8401
  * Path class used on all posix systems.
10043
8402
  *
@@ -10088,7 +8447,7 @@ function requireCommonjs$2() {
10088
8447
  )
10089
8448
  }
10090
8449
  }
10091
- commonjs$3.PathPosix = PathPosix
8450
+ commonjs$2.PathPosix = PathPosix
10092
8451
  /**
10093
8452
  * The base class for all PathScurry classes, providing the interface for path
10094
8453
  * resolution and filesystem operations.
@@ -10736,7 +9095,7 @@ function requireCommonjs$2() {
10736
9095
  this.cwd[setAsCwd](oldCwd)
10737
9096
  }
10738
9097
  }
10739
- commonjs$3.PathScurryBase = PathScurryBase
9098
+ commonjs$2.PathScurryBase = PathScurryBase
10740
9099
  /**
10741
9100
  * Windows implementation of {@link PathScurryBase}
10742
9101
  *
@@ -10793,7 +9152,7 @@ function requireCommonjs$2() {
10793
9152
  )
10794
9153
  }
10795
9154
  }
10796
- commonjs$3.PathScurryWin32 = PathScurryWin32
9155
+ commonjs$2.PathScurryWin32 = PathScurryWin32
10797
9156
  /**
10798
9157
  * {@link PathScurryBase} implementation for all posix systems other than Darwin.
10799
9158
  *
@@ -10843,7 +9202,7 @@ function requireCommonjs$2() {
10843
9202
  return p.startsWith('/')
10844
9203
  }
10845
9204
  }
10846
- commonjs$3.PathScurryPosix = PathScurryPosix
9205
+ commonjs$2.PathScurryPosix = PathScurryPosix
10847
9206
  /**
10848
9207
  * {@link PathScurryBase} implementation for Darwin (macOS) systems.
10849
9208
  *
@@ -10861,26 +9220,26 @@ function requireCommonjs$2() {
10861
9220
  })
10862
9221
  }
10863
9222
  }
10864
- commonjs$3.PathScurryDarwin = PathScurryDarwin
9223
+ commonjs$2.PathScurryDarwin = PathScurryDarwin
10865
9224
  /**
10866
9225
  * Default {@link PathBase} implementation for the current platform.
10867
9226
  *
10868
9227
  * {@link PathWin32} on Windows systems, {@link PathPosix} on all others.
10869
9228
  */
10870
- commonjs$3.Path = process.platform === 'win32' ? PathWin32 : PathPosix
9229
+ commonjs$2.Path = process.platform === 'win32' ? PathWin32 : PathPosix
10871
9230
  /**
10872
9231
  * Default {@link PathScurryBase} implementation for the current platform.
10873
9232
  *
10874
9233
  * {@link PathScurryWin32} on Windows systems, {@link PathScurryDarwin} on
10875
9234
  * Darwin (macOS) systems, {@link PathScurryPosix} on all others.
10876
9235
  */
10877
- commonjs$3.PathScurry =
9236
+ commonjs$2.PathScurry =
10878
9237
  process.platform === 'win32'
10879
9238
  ? PathScurryWin32
10880
9239
  : process.platform === 'darwin'
10881
9240
  ? PathScurryDarwin
10882
9241
  : PathScurryPosix
10883
- return commonjs$3
9242
+ return commonjs$2
10884
9243
  }
10885
9244
 
10886
9245
  const pattern = {}
@@ -10896,7 +9255,7 @@ function requirePattern() {
10896
9255
  value: true
10897
9256
  })
10898
9257
  pattern.Pattern = void 0
10899
- const minimatch_1 = requireCommonjs$5()
9258
+ const minimatch_1 = requireCommonjs$4()
10900
9259
  const isPatternList = pl => pl.length >= 1
10901
9260
  const isGlobList = gl => gl.length >= 1
10902
9261
  /**
@@ -11134,7 +9493,7 @@ function requireIgnore() {
11134
9493
  value: true
11135
9494
  })
11136
9495
  ignore.Ignore = void 0
11137
- const minimatch_1 = requireCommonjs$5()
9496
+ const minimatch_1 = requireCommonjs$4()
11138
9497
  const pattern_js_1 = requirePattern()
11139
9498
  const defaultPlatform =
11140
9499
  typeof process === 'object' &&
@@ -11276,7 +9635,7 @@ function requireProcessor() {
11276
9635
  processor.MatchRecord =
11277
9636
  processor.HasWalkedCache =
11278
9637
  void 0
11279
- const minimatch_1 = requireCommonjs$5()
9638
+ const minimatch_1 = requireCommonjs$4()
11280
9639
  /**
11281
9640
  * A cache of which patterns have been processed for a given Path
11282
9641
  */
@@ -12021,7 +10380,7 @@ function requireGlob() {
12021
10380
  value: true
12022
10381
  })
12023
10382
  glob.Glob = void 0
12024
- const minimatch_1 = requireCommonjs$5()
10383
+ const minimatch_1 = requireCommonjs$4()
12025
10384
  const node_url_1 = require$$0$3
12026
10385
  const path_scurry_1 = requireCommonjs$2()
12027
10386
  const pattern_js_1 = requirePattern()
@@ -12292,7 +10651,7 @@ function requireHasMagic() {
12292
10651
  value: true
12293
10652
  })
12294
10653
  hasMagic.hasMagic = void 0
12295
- const minimatch_1 = requireCommonjs$5()
10654
+ const minimatch_1 = requireCommonjs$4()
12296
10655
  /**
12297
10656
  * Return true if the patterns provided contain any magic glob characters,
12298
10657
  * given the options provided.
@@ -12322,7 +10681,7 @@ function requireHasMagic() {
12322
10681
  let hasRequiredCommonjs$1
12323
10682
  function requireCommonjs$1() {
12324
10683
  if (hasRequiredCommonjs$1) {
12325
- return commonjs$7
10684
+ return commonjs$4
12326
10685
  }
12327
10686
  hasRequiredCommonjs$1 = 1
12328
10687
  ;(function (exports) {
@@ -12346,10 +10705,10 @@ function requireCommonjs$1() {
12346
10705
  exports.globSync = globSync
12347
10706
  exports.globIterateSync = globIterateSync
12348
10707
  exports.globIterate = globIterate
12349
- const minimatch_1 = requireCommonjs$5()
10708
+ const minimatch_1 = requireCommonjs$4()
12350
10709
  const glob_js_1 = requireGlob()
12351
10710
  const has_magic_js_1 = requireHasMagic()
12352
- const minimatch_2 = requireCommonjs$5()
10711
+ const minimatch_2 = requireCommonjs$4()
12353
10712
  Object.defineProperty(exports, 'escape', {
12354
10713
  enumerable: true,
12355
10714
  get: function () {
@@ -12432,8 +10791,8 @@ function requireCommonjs$1() {
12432
10791
  unescape: minimatch_1.unescape
12433
10792
  })
12434
10793
  exports.glob.glob = exports.glob
12435
- })(commonjs$7)
12436
- return commonjs$7
10794
+ })(commonjs$4)
10795
+ return commonjs$4
12437
10796
  }
12438
10797
 
12439
10798
  const require$$1$1 = [
@@ -12482,12 +10841,15 @@ const require$$1$1 = [
12482
10841
  'Artistic-1.0-Perl',
12483
10842
  'Artistic-1.0-cl8',
12484
10843
  'Artistic-2.0',
10844
+ 'Artistic-dist',
10845
+ 'Aspell-RU',
12485
10846
  'BSD-1-Clause',
12486
10847
  'BSD-2-Clause',
12487
10848
  'BSD-2-Clause-Darwin',
12488
10849
  'BSD-2-Clause-Patent',
12489
10850
  'BSD-2-Clause-Views',
12490
10851
  'BSD-2-Clause-first-lines',
10852
+ 'BSD-2-Clause-pkgconf-disclaimer',
12491
10853
  'BSD-3-Clause',
12492
10854
  'BSD-3-Clause-Attribution',
12493
10855
  'BSD-3-Clause-Clear',
@@ -12628,6 +10990,7 @@ const require$$1$1 = [
12628
10990
  'Cornell-Lossless-JPEG',
12629
10991
  'Cronyx',
12630
10992
  'Crossword',
10993
+ 'CryptoSwift',
12631
10994
  'CrystalStacker',
12632
10995
  'Cube',
12633
10996
  'D-FSL-1.0',
@@ -12638,6 +11001,7 @@ const require$$1$1 = [
12638
11001
  'DRL-1.0',
12639
11002
  'DRL-1.1',
12640
11003
  'DSDP',
11004
+ 'DocBook-DTD',
12641
11005
  'DocBook-Schema',
12642
11006
  'DocBook-Stylesheet',
12643
11007
  'DocBook-XML',
@@ -12663,7 +11027,10 @@ const require$$1$1 = [
12663
11027
  'FSFAP-no-warranty-disclaimer',
12664
11028
  'FSFUL',
12665
11029
  'FSFULLR',
11030
+ 'FSFULLRSD',
12666
11031
  'FSFULLRWD',
11032
+ 'FSL-1.1-ALv2',
11033
+ 'FSL-1.1-MIT',
12667
11034
  'FTL',
12668
11035
  'Fair',
12669
11036
  'Ferguson-Twofish',
@@ -12699,11 +11066,13 @@ const require$$1$1 = [
12699
11066
  'GPL-2.0-or-later',
12700
11067
  'GPL-3.0-only',
12701
11068
  'GPL-3.0-or-later',
11069
+ 'Game-Programming-Gems',
12702
11070
  'Giftware',
12703
11071
  'Glide',
12704
11072
  'Glulxe',
12705
11073
  'Graphics-Gems',
12706
11074
  'Gutmann',
11075
+ 'HDF5',
12707
11076
  'HIDAPI',
12708
11077
  'HP-1986',
12709
11078
  'HP-1989',
@@ -12849,6 +11218,7 @@ const require$$1$1 = [
12849
11218
  'NPL-1.1',
12850
11219
  'NPOSL-3.0',
12851
11220
  'NRL',
11221
+ 'NTIA-PD',
12852
11222
  'NTP',
12853
11223
  'NTP-0',
12854
11224
  'Naumen',
@@ -12951,11 +11321,13 @@ const require$$1$1 = [
12951
11321
  'SMLNJ',
12952
11322
  'SMPPL',
12953
11323
  'SNIA',
11324
+ 'SOFA',
12954
11325
  'SPL-1.0',
12955
11326
  'SSH-OpenSSH',
12956
11327
  'SSH-short',
12957
11328
  'SSLeay-standalone',
12958
11329
  'SSPL-1.0',
11330
+ 'SUL-1.0',
12959
11331
  'SWL',
12960
11332
  'Saxpath',
12961
11333
  'SchemeReport',
@@ -13001,6 +11373,8 @@ const require$$1$1 = [
13001
11373
  'Unicode-TOU',
13002
11374
  'UnixCrypt',
13003
11375
  'Unlicense',
11376
+ 'Unlicense-libtelnet',
11377
+ 'Unlicense-libwhirlpool',
13004
11378
  'VOSTROM',
13005
11379
  'VSL-1.0',
13006
11380
  'Vim',
@@ -13054,6 +11428,8 @@ const require$$1$1 = [
13054
11428
  'gtkbook',
13055
11429
  'hdparm',
13056
11430
  'iMatix',
11431
+ 'jove',
11432
+ 'libpng-1.6.35',
13057
11433
  'libpng-2.0',
13058
11434
  'libselinux-1.0',
13059
11435
  'libtiff',
@@ -13061,10 +11437,12 @@ const require$$1$1 = [
13061
11437
  'lsof',
13062
11438
  'magaz',
13063
11439
  'mailprio',
11440
+ 'man2html',
13064
11441
  'metamail',
13065
11442
  'mpi-permissive',
13066
11443
  'mpich2',
13067
11444
  'mplus',
11445
+ 'ngrep',
13068
11446
  'pkgconf',
13069
11447
  'pnmstitch',
13070
11448
  'psfrag',
@@ -13185,276 +11563,6 @@ const require$$2 = [
13185
11563
  'x11vnc-openssl-exception'
13186
11564
  ]
13187
11565
 
13188
- let scan$1
13189
- let hasRequiredScan$1
13190
- function requireScan$1() {
13191
- if (hasRequiredScan$1) {
13192
- return scan$1
13193
- }
13194
- hasRequiredScan$1 = 1
13195
- const licenses = [].concat(require$$1$1).concat(require$$1)
13196
- const exceptions = require$$2
13197
- scan$1 = function (source) {
13198
- let index = 0
13199
- function hasMore() {
13200
- return index < source.length
13201
- }
13202
-
13203
- // `value` can be a regexp or a string.
13204
- // If it is recognized, the matching source string is returned and
13205
- // the index is incremented. Otherwise `undefined` is returned.
13206
- function read(value) {
13207
- if (value instanceof RegExp) {
13208
- const chars = source.slice(index)
13209
- const match = chars.match(value)
13210
- if (match) {
13211
- index += match[0].length
13212
- return match[0]
13213
- }
13214
- } else {
13215
- if (source.indexOf(value, index) === index) {
13216
- index += value.length
13217
- return value
13218
- }
13219
- }
13220
- }
13221
- function skipWhitespace() {
13222
- read(/[ ]*/)
13223
- }
13224
- function operator() {
13225
- let string
13226
- const possibilities = ['WITH', 'AND', 'OR', '(', ')', ':', '+']
13227
- for (let i = 0; i < possibilities.length; i++) {
13228
- string = read(possibilities[i])
13229
- if (string) {
13230
- break
13231
- }
13232
- }
13233
- if (string === '+' && index > 1 && source[index - 2] === ' ') {
13234
- throw new Error('Space before `+`')
13235
- }
13236
- return (
13237
- string && {
13238
- type: 'OPERATOR',
13239
- string: string
13240
- }
13241
- )
13242
- }
13243
- function idstring() {
13244
- return read(/[A-Za-z0-9-.]+/)
13245
- }
13246
- function expectIdstring() {
13247
- const string = idstring()
13248
- if (!string) {
13249
- throw new Error('Expected idstring at offset ' + index)
13250
- }
13251
- return string
13252
- }
13253
- function documentRef() {
13254
- if (read('DocumentRef-')) {
13255
- const string = expectIdstring()
13256
- return {
13257
- type: 'DOCUMENTREF',
13258
- string: string
13259
- }
13260
- }
13261
- }
13262
- function licenseRef() {
13263
- if (read('LicenseRef-')) {
13264
- const string = expectIdstring()
13265
- return {
13266
- type: 'LICENSEREF',
13267
- string: string
13268
- }
13269
- }
13270
- }
13271
- function identifier() {
13272
- const begin = index
13273
- const string = idstring()
13274
- if (licenses.indexOf(string) !== -1) {
13275
- return {
13276
- type: 'LICENSE',
13277
- string: string
13278
- }
13279
- } else if (exceptions.indexOf(string) !== -1) {
13280
- return {
13281
- type: 'EXCEPTION',
13282
- string: string
13283
- }
13284
- }
13285
- index = begin
13286
- }
13287
-
13288
- // Tries to read the next token. Returns `undefined` if no token is
13289
- // recognized.
13290
- function parseToken() {
13291
- // Ordering matters
13292
- return operator() || documentRef() || licenseRef() || identifier()
13293
- }
13294
- const tokens = []
13295
- while (hasMore()) {
13296
- skipWhitespace()
13297
- if (!hasMore()) {
13298
- break
13299
- }
13300
- const token = parseToken()
13301
- if (!token) {
13302
- throw new Error('Unexpected `' + source[index] + '` at offset ' + index)
13303
- }
13304
- tokens.push(token)
13305
- }
13306
- return tokens
13307
- }
13308
- return scan$1
13309
- }
13310
-
13311
- let parse$1
13312
- let hasRequiredParse$1
13313
- function requireParse$1() {
13314
- if (hasRequiredParse$1) {
13315
- return parse$1
13316
- }
13317
- hasRequiredParse$1 = 1
13318
-
13319
- // The ABNF grammar in the spec is totally ambiguous.
13320
- //
13321
- // This parser follows the operator precedence defined in the
13322
- // `Order of Precedence and Parentheses` section.
13323
-
13324
- parse$1 = function (tokens) {
13325
- let index = 0
13326
- function hasMore() {
13327
- return index < tokens.length
13328
- }
13329
- function token() {
13330
- return hasMore() ? tokens[index] : null
13331
- }
13332
- function next() {
13333
- if (!hasMore()) {
13334
- throw new Error()
13335
- }
13336
- index++
13337
- }
13338
- function parseOperator(operator) {
13339
- const t = token()
13340
- if (t && t.type === 'OPERATOR' && operator === t.string) {
13341
- next()
13342
- return t.string
13343
- }
13344
- }
13345
- function parseWith() {
13346
- if (parseOperator('WITH')) {
13347
- const t = token()
13348
- if (t && t.type === 'EXCEPTION') {
13349
- next()
13350
- return t.string
13351
- }
13352
- throw new Error('Expected exception after `WITH`')
13353
- }
13354
- }
13355
- function parseLicenseRef() {
13356
- // TODO: Actually, everything is concatenated into one string
13357
- // for backward-compatibility but it could be better to return
13358
- // a nice structure.
13359
- const begin = index
13360
- let string = ''
13361
- let t = token()
13362
- if (t.type === 'DOCUMENTREF') {
13363
- next()
13364
- string += 'DocumentRef-' + t.string + ':'
13365
- if (!parseOperator(':')) {
13366
- throw new Error('Expected `:` after `DocumentRef-...`')
13367
- }
13368
- }
13369
- t = token()
13370
- if (t.type === 'LICENSEREF') {
13371
- next()
13372
- string += 'LicenseRef-' + t.string
13373
- return {
13374
- license: string
13375
- }
13376
- }
13377
- index = begin
13378
- }
13379
- function parseLicense() {
13380
- const t = token()
13381
- if (t && t.type === 'LICENSE') {
13382
- next()
13383
- const node = {
13384
- license: t.string
13385
- }
13386
- if (parseOperator('+')) {
13387
- node.plus = true
13388
- }
13389
- const exception = parseWith()
13390
- if (exception) {
13391
- node.exception = exception
13392
- }
13393
- return node
13394
- }
13395
- }
13396
- function parseParenthesizedExpression() {
13397
- const left = parseOperator('(')
13398
- if (!left) {
13399
- return
13400
- }
13401
- const expr = parseExpression()
13402
- if (!parseOperator(')')) {
13403
- throw new Error('Expected `)`')
13404
- }
13405
- return expr
13406
- }
13407
- function parseAtom() {
13408
- return (
13409
- parseParenthesizedExpression() || parseLicenseRef() || parseLicense()
13410
- )
13411
- }
13412
- function makeBinaryOpParser(operator, nextParser) {
13413
- return function parseBinaryOp() {
13414
- const left = nextParser()
13415
- if (!left) {
13416
- return
13417
- }
13418
- if (!parseOperator(operator)) {
13419
- return left
13420
- }
13421
- const right = parseBinaryOp()
13422
- if (!right) {
13423
- throw new Error('Expected expression')
13424
- }
13425
- return {
13426
- left: left,
13427
- conjunction: operator.toLowerCase(),
13428
- right: right
13429
- }
13430
- }
13431
- }
13432
- const parseAnd = makeBinaryOpParser('AND', parseAtom)
13433
- const parseExpression = makeBinaryOpParser('OR', parseAnd)
13434
- const node = parseExpression()
13435
- if (!node || hasMore()) {
13436
- throw new Error('Syntax error')
13437
- }
13438
- return node
13439
- }
13440
- return parse$1
13441
- }
13442
-
13443
- let spdxExpressionParse$1
13444
- let hasRequiredSpdxExpressionParse$1
13445
- function requireSpdxExpressionParse$1() {
13446
- if (hasRequiredSpdxExpressionParse$1) {
13447
- return spdxExpressionParse$1
13448
- }
13449
- hasRequiredSpdxExpressionParse$1 = 1
13450
- const scan = requireScan$1()
13451
- const parse = requireParse$1()
13452
- spdxExpressionParse$1 = function (source) {
13453
- return parse(scan(source))
13454
- }
13455
- return spdxExpressionParse$1
13456
- }
13457
-
13458
11566
  let scan
13459
11567
  let hasRequiredScan
13460
11568
  function requireScan() {
@@ -14146,7 +12254,7 @@ function requireValidateNpmPackageLicense() {
14146
12254
  return validateNpmPackageLicense
14147
12255
  }
14148
12256
  hasRequiredValidateNpmPackageLicense = 1
14149
- const parse = requireSpdxExpressionParse$1()
12257
+ const parse = requireSpdxExpressionParse()
14150
12258
  const correct = requireSpdxCorrect()
14151
12259
  const genericWarning =
14152
12260
  'license should be ' +
@@ -17716,7 +15824,7 @@ function requireDiff() {
17716
15824
  return diff_1
17717
15825
  }
17718
15826
  hasRequiredDiff = 1
17719
- const parse = requireParse$2()
15827
+ const parse = requireParse$1()
17720
15828
  const diff = (version1, version2) => {
17721
15829
  const v1 = parse(version1, null, true)
17722
15830
  const v2 = parse(version2, null, true)
@@ -17815,7 +15923,7 @@ function requirePrerelease() {
17815
15923
  return prerelease_1
17816
15924
  }
17817
15925
  hasRequiredPrerelease = 1
17818
- const parse = requireParse$2()
15926
+ const parse = requireParse$1()
17819
15927
  const prerelease = (version, options) => {
17820
15928
  const parsed = parse(version, options)
17821
15929
  return parsed && parsed.prerelease.length ? parsed.prerelease : null
@@ -18046,7 +16154,7 @@ function requireCoerce() {
18046
16154
  }
18047
16155
  hasRequiredCoerce = 1
18048
16156
  const SemVer = requireSemver$1()
18049
- const parse = requireParse$2()
16157
+ const parse = requireParse$1()
18050
16158
  const { safeRe: re, t } = requireRe()
18051
16159
  const coerce = (version, options) => {
18052
16160
  if (version instanceof SemVer) {
@@ -19471,7 +17579,7 @@ function requireSemver() {
19471
17579
  const constants = requireConstants()
19472
17580
  const SemVer = requireSemver$1()
19473
17581
  const identifiers = requireIdentifiers()
19474
- const parse = requireParse$2()
17582
+ const parse = requireParse$1()
19475
17583
  const valid = requireValid$1()
19476
17584
  const clean = requireClean()
19477
17585
  const inc = requireInc()
@@ -21280,12 +19388,12 @@ function requireDevEngines() {
21280
19388
  wanted === null ||
21281
19389
  Array.isArray(wanted)
21282
19390
  ) {
21283
- throw new Error(`Invalid non-object value for devEngines`)
19391
+ throw new Error(`Invalid non-object value for "devEngines"`)
21284
19392
  }
21285
19393
  const errors = []
21286
19394
  for (const engine of Object.keys(wanted)) {
21287
19395
  if (!recognizedEngines.includes(engine)) {
21288
- throw new Error(`Invalid property "${engine}"`)
19396
+ throw new Error(`Invalid property "devEngines.${engine}"`)
21289
19397
  }
21290
19398
  const dependencyAsAuthored = wanted[engine]
21291
19399
  const dependencies = [dependencyAsAuthored].flat()
@@ -21312,7 +19420,7 @@ function requireDevEngines() {
21312
19420
  if (onFail === 'download') {
21313
19421
  onFail = 'error'
21314
19422
  }
21315
- const err = Object.assign(new Error(`Invalid engine "${engine}"`), {
19423
+ const err = Object.assign(new Error(`Invalid devEngines.${engine}`), {
21316
19424
  errors: depErrors,
21317
19425
  engine,
21318
19426
  isWarn: onFail === 'warn',