ccdeck 3.50.0 → 3.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +2 -0
  2. package/THIRD_PARTY_NOTICES.md +28 -0
  3. package/dist/web/assets/BrowserWatchModal-CRqdEVdh.js +1 -0
  4. package/dist/web/assets/IntegrationModal-BDzEIGSM.js +7 -0
  5. package/dist/web/assets/RadioPanel-BJlsCpnN.js +1 -0
  6. package/dist/web/assets/TrafficRadar-BGxw-hlO.js +8 -0
  7. package/dist/web/assets/UsageHistoryModal-C_WBpNIp.js +1 -0
  8. package/dist/web/assets/app-B53fC4gE.js +358 -0
  9. package/dist/web/assets/app-Co1HNGP8.css +1 -0
  10. package/dist/web/assets/{index-DSIUCKoe.js → index-D9nJhUJR.js} +1 -1
  11. package/dist/web/index.html +3 -3
  12. package/node_modules/bare-addon-resolve/LICENSE +201 -0
  13. package/node_modules/bare-addon-resolve/README.md +226 -0
  14. package/node_modules/bare-addon-resolve/index.d.ts +100 -0
  15. package/node_modules/bare-addon-resolve/index.js +531 -0
  16. package/node_modules/bare-addon-resolve/lib/errors.d.ts +16 -0
  17. package/node_modules/bare-addon-resolve/lib/errors.js +21 -0
  18. package/node_modules/bare-addon-resolve/package.json +57 -0
  19. package/node_modules/bare-module-resolve/LICENSE +201 -0
  20. package/node_modules/bare-module-resolve/README.md +322 -0
  21. package/node_modules/bare-module-resolve/index.d.ts +171 -0
  22. package/node_modules/bare-module-resolve/index.js +899 -0
  23. package/node_modules/bare-module-resolve/lib/errors.d.ts +31 -0
  24. package/node_modules/bare-module-resolve/lib/errors.js +37 -0
  25. package/node_modules/bare-module-resolve/package.json +56 -0
  26. package/node_modules/bare-semver/LICENSE +201 -0
  27. package/node_modules/bare-semver/README.md +147 -0
  28. package/node_modules/bare-semver/index.d.ts +61 -0
  29. package/node_modules/bare-semver/index.js +13 -0
  30. package/node_modules/bare-semver/lib/comparator.js +37 -0
  31. package/node_modules/bare-semver/lib/constants.js +7 -0
  32. package/node_modules/bare-semver/lib/errors.js +22 -0
  33. package/node_modules/bare-semver/lib/range.js +256 -0
  34. package/node_modules/bare-semver/lib/version.js +240 -0
  35. package/node_modules/bare-semver/package.json +43 -0
  36. package/node_modules/fs-native-extensions/CMakeLists.txt +118 -0
  37. package/node_modules/fs-native-extensions/LICENSE +201 -0
  38. package/node_modules/fs-native-extensions/README.md +160 -0
  39. package/node_modules/fs-native-extensions/binding.c +1825 -0
  40. package/node_modules/fs-native-extensions/binding.js +3 -0
  41. package/node_modules/fs-native-extensions/include/fs-ext.h +193 -0
  42. package/node_modules/fs-native-extensions/index.js +356 -0
  43. package/node_modules/fs-native-extensions/package.json +72 -0
  44. package/node_modules/fs-native-extensions/prebuilds/android-arm/fs-native-extensions.bare +0 -0
  45. package/node_modules/fs-native-extensions/prebuilds/android-arm/fs-native-extensions.node +0 -0
  46. package/node_modules/fs-native-extensions/prebuilds/android-arm64/fs-native-extensions.bare +0 -0
  47. package/node_modules/fs-native-extensions/prebuilds/android-arm64/fs-native-extensions.node +0 -0
  48. package/node_modules/fs-native-extensions/prebuilds/android-ia32/fs-native-extensions.bare +0 -0
  49. package/node_modules/fs-native-extensions/prebuilds/android-ia32/fs-native-extensions.node +0 -0
  50. package/node_modules/fs-native-extensions/prebuilds/android-x64/fs-native-extensions.bare +0 -0
  51. package/node_modules/fs-native-extensions/prebuilds/android-x64/fs-native-extensions.node +0 -0
  52. package/node_modules/fs-native-extensions/prebuilds/darwin-arm64/fs-native-extensions.bare +0 -0
  53. package/node_modules/fs-native-extensions/prebuilds/darwin-arm64/fs-native-extensions.node +0 -0
  54. package/node_modules/fs-native-extensions/prebuilds/darwin-x64/fs-native-extensions.bare +0 -0
  55. package/node_modules/fs-native-extensions/prebuilds/darwin-x64/fs-native-extensions.node +0 -0
  56. package/node_modules/fs-native-extensions/prebuilds/ios-arm64/fs-native-extensions.bare +0 -0
  57. package/node_modules/fs-native-extensions/prebuilds/ios-arm64-simulator/fs-native-extensions.bare +0 -0
  58. package/node_modules/fs-native-extensions/prebuilds/ios-x64-simulator/fs-native-extensions.bare +0 -0
  59. package/node_modules/fs-native-extensions/prebuilds/linux-arm64/fs-native-extensions.bare +0 -0
  60. package/node_modules/fs-native-extensions/prebuilds/linux-arm64/fs-native-extensions.node +0 -0
  61. package/node_modules/fs-native-extensions/prebuilds/linux-x64/fs-native-extensions.bare +0 -0
  62. package/node_modules/fs-native-extensions/prebuilds/linux-x64/fs-native-extensions.node +0 -0
  63. package/node_modules/fs-native-extensions/prebuilds/win32-arm64/fs-native-extensions.bare +0 -0
  64. package/node_modules/fs-native-extensions/prebuilds/win32-arm64/fs-native-extensions.node +0 -0
  65. package/node_modules/fs-native-extensions/prebuilds/win32-x64/fs-native-extensions.bare +0 -0
  66. package/node_modules/fs-native-extensions/prebuilds/win32-x64/fs-native-extensions.node +0 -0
  67. package/node_modules/fs-native-extensions/src/apple.c +197 -0
  68. package/node_modules/fs-native-extensions/src/linux.c +146 -0
  69. package/node_modules/fs-native-extensions/src/platform.h +51 -0
  70. package/node_modules/fs-native-extensions/src/posix.c +33 -0
  71. package/node_modules/fs-native-extensions/src/shared.c +397 -0
  72. package/node_modules/fs-native-extensions/src/win32/nt.h +226 -0
  73. package/node_modules/fs-native-extensions/src/win32.c +531 -0
  74. package/node_modules/require-addon/LICENSE +201 -0
  75. package/node_modules/require-addon/README.md +19 -0
  76. package/node_modules/require-addon/lib/bare.js +1 -0
  77. package/node_modules/require-addon/lib/default.js +7 -0
  78. package/node_modules/require-addon/lib/node.js +79 -0
  79. package/node_modules/require-addon/package.json +64 -0
  80. package/node_modules/which-runtime/LICENSE +201 -0
  81. package/node_modules/which-runtime/README.md +29 -0
  82. package/node_modules/which-runtime/index.js +36 -0
  83. package/node_modules/which-runtime/package.json +32 -0
  84. package/package.json +9 -2
  85. package/release-notes.json +33 -0
  86. package/src/server/integrations/jira-comment.mjs +37 -0
  87. package/src/server/integrations/jira-move.mjs +37 -11
  88. package/src/server/integrations/jira-transition.mjs +43 -0
  89. package/src/server/integrations/jira-write-guard.mjs +218 -0
  90. package/src/server/integrations/jira.mjs +16 -0
  91. package/src/server/integrations/routes.mjs +70 -7
  92. package/src/server/static-cache.mjs +34 -16
  93. package/src/server/traffic-radar-wire.mjs +6 -0
  94. package/dist/web/assets/BrowserWatchModal-CSckhvRP.js +0 -1
  95. package/dist/web/assets/IntegrationModal-CT8_QnAx.js +0 -7
  96. package/dist/web/assets/RadioPanel-D3JLkVYu.js +0 -1
  97. package/dist/web/assets/TrafficRadar-Cuk5tXfL.js +0 -8
  98. package/dist/web/assets/UsageHistoryModal-DiEH73iz.js +0 -1
  99. package/dist/web/assets/app-BRaZrImF.js +0 -321
  100. package/dist/web/assets/app-DfGYllmZ.css +0 -1
@@ -0,0 +1,899 @@
1
+ const { satisfies } = require('bare-semver')
2
+ const errors = require('./lib/errors')
3
+
4
+ module.exports = exports = function resolve(specifier, parentURL, opts, readPackage) {
5
+ if (typeof opts === 'function') {
6
+ readPackage = opts
7
+ opts = {}
8
+ } else if (typeof readPackage !== 'function') {
9
+ readPackage = defaultReadPackage
10
+ }
11
+
12
+ return {
13
+ *[Symbol.iterator]() {
14
+ const generator = exports.module(specifier, parentURL, opts)
15
+
16
+ let next = generator.next()
17
+
18
+ while (next.done !== true) {
19
+ const value = next.value
20
+
21
+ if (value.package) {
22
+ next = generator.next(readPackage(value.package))
23
+ } else {
24
+ next = generator.next(yield value.resolution)
25
+ }
26
+ }
27
+
28
+ return next.value
29
+ },
30
+
31
+ async *[Symbol.asyncIterator]() {
32
+ const generator = exports.module(specifier, parentURL, opts)
33
+
34
+ let next = generator.next()
35
+
36
+ while (next.done !== true) {
37
+ const value = next.value
38
+
39
+ if (value.package) {
40
+ next = generator.next(await readPackage(value.package))
41
+ } else {
42
+ next = generator.next(yield value.resolution)
43
+ }
44
+ }
45
+
46
+ return next.value
47
+ }
48
+ }
49
+ }
50
+
51
+ function defaultReadPackage() {
52
+ return null
53
+ }
54
+
55
+ // No resolution candidate was yielded
56
+ const UNRESOLVED = 0x0
57
+ // At least 1 resolution candidate was yielded
58
+ const YIELDED = 0x1
59
+ // At least 1 resolution candidate was yielded and resolved
60
+ const RESOLVED = YIELDED | 0x2
61
+ // A resolution cycle was detected
62
+ const CYCLIC = 0x4
63
+
64
+ exports.constants = {
65
+ UNRESOLVED,
66
+ YIELDED,
67
+ RESOLVED,
68
+ CYCLIC
69
+ }
70
+
71
+ exports.module = function* (specifier, parentURL, opts = {}) {
72
+ const { resolutions = null, imports = null } = opts
73
+
74
+ if (exports.startsWithWindowsDriveLetter(specifier)) {
75
+ specifier = '/' + specifier
76
+ }
77
+
78
+ let status
79
+
80
+ if (resolutions) {
81
+ status = yield* exports.preresolved(specifier, resolutions, parentURL, opts)
82
+
83
+ if (status) return status
84
+ }
85
+
86
+ status = yield* exports.url(specifier, parentURL, opts)
87
+
88
+ if (status) return status
89
+
90
+ status = yield* exports.packageImports(specifier, parentURL, opts)
91
+
92
+ if (status) return status
93
+
94
+ if (
95
+ specifier === '.' ||
96
+ specifier === '..' ||
97
+ specifier[0] === '/' ||
98
+ specifier[0] === '\\' ||
99
+ specifier.startsWith('./') ||
100
+ specifier.startsWith('.\\') ||
101
+ specifier.startsWith('../') ||
102
+ specifier.startsWith('..\\')
103
+ ) {
104
+ if (imports) {
105
+ status = yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts)
106
+
107
+ if (status) return status
108
+ }
109
+
110
+ status = yield* exports.deferred(specifier, opts)
111
+
112
+ if (status) return status
113
+
114
+ status = yield* exports.file(specifier, parentURL, false, opts)
115
+
116
+ if (status === RESOLVED) return status
117
+
118
+ const yielded = (status & YIELDED) !== 0
119
+
120
+ status = yield* exports.directory(specifier, parentURL, opts)
121
+
122
+ if (yielded) status |= YIELDED
123
+
124
+ return status
125
+ }
126
+
127
+ return yield* exports.package(specifier, parentURL, opts)
128
+ }
129
+
130
+ exports.url = function* (url, parentURL, opts = {}) {
131
+ const { imports = null, deferredProtocol = 'deferred:', resolutions = null } = opts
132
+
133
+ let resolution
134
+ try {
135
+ resolution = new URL(url)
136
+ } catch {
137
+ return UNRESOLVED
138
+ }
139
+
140
+ if (imports) {
141
+ const status = yield* exports.packageImportsExports(
142
+ resolution.href,
143
+ imports,
144
+ parentURL,
145
+ true,
146
+ opts
147
+ )
148
+
149
+ if (status && (status & CYCLIC) === 0) return status
150
+ }
151
+
152
+ if (resolution.protocol === deferredProtocol) {
153
+ const specifier = resolution.pathname
154
+
155
+ if (resolutions) {
156
+ const imports = resolutions[parentURL.href]
157
+
158
+ if (typeof imports === 'object' && imports !== null) {
159
+ opts = {
160
+ ...opts,
161
+ resolutions: { ...resolutions, [parentURL.href]: { ...imports, [specifier]: null } }
162
+ }
163
+ }
164
+ }
165
+
166
+ return yield* exports.module(specifier, parentURL, opts)
167
+ }
168
+
169
+ if (resolution.protocol === 'node:') {
170
+ const specifier = resolution.pathname
171
+
172
+ if (
173
+ specifier === '.' ||
174
+ specifier === '..' ||
175
+ specifier[0] === '/' ||
176
+ specifier.startsWith('./') ||
177
+ specifier.startsWith('../')
178
+ ) {
179
+ throw errors.INVALID_MODULE_SPECIFIER(`Module specifier '${url}' is not a valid package name`)
180
+ }
181
+
182
+ return yield* exports.package(specifier, parentURL, opts)
183
+ }
184
+
185
+ const resolved = yield { resolution }
186
+
187
+ return resolved ? RESOLVED : YIELDED
188
+ }
189
+
190
+ exports.preresolved = function* (specifier, resolutions, parentURL, opts = {}) {
191
+ const imports = resolutions[parentURL.href]
192
+
193
+ if (typeof imports === 'object' && imports !== null) {
194
+ return yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts)
195
+ }
196
+
197
+ return UNRESOLVED
198
+ }
199
+
200
+ exports.deferred = function* (specifier, opts = {}) {
201
+ const { deferredProtocol = 'deferred:', defer = [] } = opts
202
+
203
+ if (defer.includes(specifier)) {
204
+ const resolved = yield { resolution: new URL(deferredProtocol + specifier) }
205
+
206
+ return resolved ? RESOLVED : YIELDED
207
+ }
208
+
209
+ return UNRESOLVED
210
+ }
211
+
212
+ exports.package = function* (packageSpecifier, parentURL, opts = {}) {
213
+ const { builtins = [] } = opts
214
+
215
+ if (packageSpecifier === '') {
216
+ throw errors.INVALID_MODULE_SPECIFIER(
217
+ `Module specifier '${packageSpecifier}' is not a valid package name`
218
+ )
219
+ }
220
+
221
+ let packageName
222
+
223
+ if (packageSpecifier[0] !== '@') {
224
+ packageName = packageSpecifier.split('/', 1).join()
225
+ } else {
226
+ if (!packageSpecifier.includes('/')) {
227
+ throw errors.INVALID_MODULE_SPECIFIER(
228
+ `Module specifier '${packageSpecifier}' is not a valid package name`
229
+ )
230
+ }
231
+
232
+ packageName = packageSpecifier.split('/', 2).join('/')
233
+ }
234
+
235
+ if (packageName[0] === '.' || packageName.includes('\\') || packageName.includes('%')) {
236
+ throw errors.INVALID_MODULE_SPECIFIER(
237
+ `Module specifier '${packageSpecifier}' is not a valid package name`
238
+ )
239
+ }
240
+
241
+ let status
242
+
243
+ status = yield* exports.builtinTarget(packageSpecifier, null, builtins, opts)
244
+
245
+ if (status) return status
246
+
247
+ status = yield* exports.deferred(packageSpecifier, opts)
248
+
249
+ if (status) return status
250
+
251
+ let packageSubpath = '.' + packageSpecifier.substring(packageName.length)
252
+
253
+ status = yield* exports.packageSelf(packageName, packageSubpath, parentURL, opts)
254
+
255
+ if (status) return status
256
+
257
+ parentURL = new URL(parentURL.href)
258
+
259
+ for (const packageURL of exports.lookupPackageRoot(packageName, parentURL)) {
260
+ const info = yield { package: packageURL }
261
+
262
+ if (info) {
263
+ if (info.engines) exports.validateEngines(packageURL, info.engines, opts)
264
+
265
+ if (info.exports) {
266
+ return yield* exports.packageExports(packageURL, packageSubpath, info.exports, opts)
267
+ }
268
+
269
+ if (packageSubpath === '.') {
270
+ if (typeof info.main === 'string' && info.main !== '') {
271
+ packageSubpath = info.main
272
+ } else {
273
+ return yield* exports.file('index', packageURL, true, opts)
274
+ }
275
+ }
276
+
277
+ status = yield* exports.file(packageSubpath, packageURL, false, opts)
278
+
279
+ if (status === RESOLVED) return status
280
+
281
+ const yielded = (status & YIELDED) !== 0
282
+
283
+ status = yield* exports.directory(packageSubpath, packageURL, opts)
284
+
285
+ if (yielded) status |= YIELDED
286
+
287
+ return status
288
+ }
289
+ }
290
+
291
+ return UNRESOLVED
292
+ }
293
+
294
+ exports.packageSelf = function* (packageName, packageSubpath, parentURL, opts = {}) {
295
+ for (const packageURL of exports.lookupPackageScope(parentURL, opts)) {
296
+ const info = yield { package: packageURL }
297
+
298
+ if (info) {
299
+ if (info.name !== packageName) return false
300
+
301
+ if (info.exports) {
302
+ return yield* exports.packageExports(packageURL, packageSubpath, info.exports, opts)
303
+ }
304
+
305
+ if (packageSubpath === '.') {
306
+ if (typeof info.main === 'string' && info.main !== '') {
307
+ packageSubpath = info.main
308
+ } else {
309
+ return yield* exports.file('index', packageURL, true, opts)
310
+ }
311
+ }
312
+
313
+ let status = yield* exports.file(packageSubpath, packageURL, false, opts)
314
+
315
+ if (status === RESOLVED) return status
316
+
317
+ const yielded = (status & YIELDED) !== 0
318
+
319
+ status = yield* exports.directory(packageSubpath, packageURL, opts)
320
+
321
+ if (yielded) status |= YIELDED
322
+
323
+ return status
324
+ }
325
+ }
326
+
327
+ return UNRESOLVED
328
+ }
329
+
330
+ exports.packageExports = function* (packageURL, subpath, packageExports, opts = {}) {
331
+ if (
332
+ typeof packageExports === 'object' &&
333
+ packageExports !== null &&
334
+ !Array.isArray(packageExports)
335
+ ) {
336
+ const keys = Object.keys(packageExports)
337
+
338
+ const relative = keys.filter((key) => key.startsWith('.')).length
339
+
340
+ if (relative !== 0 && relative !== keys.length) {
341
+ throw errors.INVALID_PACKAGE_CONFIGURATION(
342
+ `"exports" in '${packageURL}' cannot contain some keys starting with '.' and some not`
343
+ )
344
+ }
345
+ }
346
+
347
+ if (subpath === '.') {
348
+ let mainExport
349
+
350
+ if (typeof packageExports === 'string' || Array.isArray(packageExports)) {
351
+ mainExport = packageExports
352
+ } else if (typeof packageExports === 'object' && packageExports !== null) {
353
+ const keys = Object.keys(packageExports)
354
+
355
+ if (keys.some((key) => key.startsWith('.'))) {
356
+ if ('.' in packageExports) mainExport = packageExports['.']
357
+ } else {
358
+ mainExport = packageExports
359
+ }
360
+ }
361
+
362
+ if (mainExport) {
363
+ const status = yield* exports.packageTarget(packageURL, mainExport, null, false, opts)
364
+
365
+ if (status) return status
366
+ }
367
+ } else if (typeof packageExports === 'object' && packageExports !== null) {
368
+ const keys = Object.keys(packageExports)
369
+
370
+ if (keys.every((key) => key.startsWith('.'))) {
371
+ const status = yield* exports.packageImportsExports(
372
+ subpath,
373
+ packageExports,
374
+ packageURL,
375
+ false,
376
+ opts
377
+ )
378
+
379
+ if (status) return status
380
+ }
381
+ }
382
+
383
+ throw errors.PACKAGE_PATH_NOT_EXPORTED(
384
+ `Package subpath '${subpath}' is not defined by "exports" in '${packageURL}'`
385
+ )
386
+ }
387
+
388
+ exports.packageImports = function* (specifier, parentURL, opts = {}) {
389
+ const { imports = null } = opts
390
+
391
+ if (specifier === '#' || specifier.startsWith('#/')) {
392
+ throw errors.INVALID_MODULE_SPECIFIER(
393
+ `Module specifier '${specifier}' is not a valid internal imports specifier`
394
+ )
395
+ }
396
+
397
+ for (const packageURL of exports.lookupPackageScope(parentURL, opts)) {
398
+ const info = yield { package: packageURL }
399
+
400
+ if (info) {
401
+ if (info.imports) {
402
+ const status = yield* exports.packageImportsExports(
403
+ specifier,
404
+ info.imports,
405
+ packageURL,
406
+ true,
407
+ opts
408
+ )
409
+
410
+ if (status) return status
411
+ }
412
+
413
+ if (specifier.startsWith('#')) {
414
+ throw errors.PACKAGE_IMPORT_NOT_DEFINED(
415
+ `Package import specifier '${specifier}' is not defined by "imports" in '${packageURL}'`
416
+ )
417
+ }
418
+
419
+ break
420
+ }
421
+ }
422
+
423
+ if (imports) {
424
+ const status = yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts)
425
+
426
+ if (status) return status
427
+ }
428
+
429
+ return UNRESOLVED
430
+ }
431
+
432
+ exports.packageImportsExports = function* (
433
+ matchKey,
434
+ matchObject,
435
+ packageURL,
436
+ isImports,
437
+ opts = {}
438
+ ) {
439
+ if (matchKey in matchObject && !matchKey.includes('*')) {
440
+ const target = matchObject[matchKey]
441
+
442
+ return yield* exports.packageTarget(packageURL, target, null, isImports, opts)
443
+ }
444
+
445
+ const expansionKeys = Object.keys(matchObject)
446
+ .filter((key) => key.includes('*'))
447
+ .sort(exports.patternKeyCompare)
448
+
449
+ for (const expansionKey of expansionKeys) {
450
+ const patternIndex = expansionKey.indexOf('*')
451
+ const patternBase = expansionKey.substring(0, patternIndex)
452
+
453
+ if (matchKey.startsWith(patternBase) && matchKey !== patternBase) {
454
+ const patternTrailer = expansionKey.substring(patternIndex + 1)
455
+
456
+ if (
457
+ patternTrailer === '' ||
458
+ (matchKey.endsWith(patternTrailer) && matchKey.length >= expansionKey.length)
459
+ ) {
460
+ const target = matchObject[expansionKey]
461
+
462
+ const patternMatch = matchKey.substring(
463
+ patternBase.length,
464
+ matchKey.length - patternTrailer.length
465
+ )
466
+
467
+ return yield* exports.packageTarget(packageURL, target, patternMatch, isImports, opts)
468
+ }
469
+ }
470
+ }
471
+
472
+ return UNRESOLVED
473
+ }
474
+
475
+ exports.validateEngines = function validateEngines(packageURL, packageEngines, opts = {}) {
476
+ const { engines = {} } = opts
477
+
478
+ for (const [engine, range] of Object.entries(packageEngines)) {
479
+ if (engine in engines) {
480
+ const version = engines[engine]
481
+
482
+ if (!satisfies(version, range)) {
483
+ throw errors.UNSUPPORTED_ENGINE(
484
+ `Package not compatible with engine '${engine}' ${version}, requires range '${range}' defined by "engines" in '${packageURL}'`
485
+ )
486
+ }
487
+ }
488
+ }
489
+ }
490
+
491
+ exports.patternKeyCompare = function patternKeyCompare(keyA, keyB) {
492
+ const patternIndexA = keyA.indexOf('*')
493
+ const patternIndexB = keyB.indexOf('*')
494
+ const baseLengthA = patternIndexA === -1 ? keyA.length : patternIndexA + 1
495
+ const baseLengthB = patternIndexB === -1 ? keyB.length : patternIndexB + 1
496
+ if (baseLengthA > baseLengthB) return -1
497
+ if (baseLengthB > baseLengthA) return 1
498
+ if (patternIndexA === -1) return 1
499
+ if (patternIndexB === -1) return -1
500
+ if (keyA.length > keyB.length) return -1
501
+ if (keyB.length > keyA.length) return 1
502
+ return 0
503
+ }
504
+
505
+ exports.packageTarget = function* (packageURL, target, patternMatch, isImports, opts = {}) {
506
+ const { conditions = [], matchedConditions = [], matchedTargets = [] } = opts
507
+
508
+ opts = { ...opts, matchedConditions, matchedTargets }
509
+
510
+ if (typeof target === 'string') {
511
+ if (!target.startsWith('./') && !isImports) {
512
+ throw errors.INVALID_PACKAGE_TARGET(
513
+ `Invalid target '${target}' defined by "exports" in '${packageURL}'`
514
+ )
515
+ }
516
+
517
+ if (patternMatch !== null) {
518
+ target = target.replaceAll('*', patternMatch)
519
+ }
520
+
521
+ if (matchedTargets.includes(target)) return CYCLIC
522
+
523
+ matchedTargets.push(target)
524
+
525
+ let status = yield* exports.url(target, packageURL, opts)
526
+
527
+ if (status || URL.canParse(target)) {
528
+ matchedTargets.pop()
529
+
530
+ return status
531
+ }
532
+
533
+ if (
534
+ target === '.' ||
535
+ target === '..' ||
536
+ target[0] === '/' ||
537
+ target.startsWith('./') ||
538
+ target.startsWith('../')
539
+ ) {
540
+ if (hasOpaquePath(packageURL)) {
541
+ matchedTargets.pop()
542
+
543
+ return UNRESOLVED
544
+ }
545
+
546
+ const resolved = yield { resolution: new URL(target, packageURL) }
547
+
548
+ matchedTargets.pop()
549
+
550
+ return resolved ? RESOLVED : YIELDED
551
+ }
552
+
553
+ status = yield* exports.package(target, packageURL, opts)
554
+
555
+ matchedTargets.pop()
556
+
557
+ return status
558
+ }
559
+
560
+ if (Array.isArray(target)) {
561
+ let status = UNRESOLVED
562
+
563
+ for (const targetValue of target) {
564
+ status |= yield* exports.packageTarget(packageURL, targetValue, patternMatch, isImports, opts)
565
+
566
+ if (status === RESOLVED) return status
567
+ }
568
+
569
+ return status
570
+ }
571
+
572
+ if (typeof target === 'object' && target !== null) {
573
+ let status = UNRESOLVED
574
+
575
+ for (const [condition, targetValue, subset] of exports.conditionMatches(
576
+ target,
577
+ conditions,
578
+ opts
579
+ )) {
580
+ matchedConditions.push(condition)
581
+
582
+ status |= yield* exports.packageTarget(packageURL, targetValue, patternMatch, isImports, {
583
+ ...opts,
584
+ conditions: subset
585
+ })
586
+
587
+ matchedConditions.pop()
588
+ }
589
+
590
+ return status
591
+ }
592
+
593
+ return UNRESOLVED
594
+ }
595
+
596
+ exports.builtinTarget = function* (packageSpecifier, packageVersion, target, opts = {}) {
597
+ const { builtinProtocol = 'builtin:', conditions = [], matchedConditions = [] } = opts
598
+
599
+ opts = { ...opts, matchedConditions }
600
+
601
+ if (typeof target === 'string') {
602
+ const targetParts = target.split('@')
603
+
604
+ let targetName
605
+ let targetVersion
606
+
607
+ if (target[0] !== '@') {
608
+ targetName = targetParts[0]
609
+ targetVersion = targetParts[1] || null
610
+ } else {
611
+ targetName = targetParts.slice(0, 2).join('@')
612
+ targetVersion = targetParts[2] || null
613
+ }
614
+
615
+ if (packageSpecifier === targetName) {
616
+ if (packageVersion === null && targetVersion === null) {
617
+ const resolved = yield {
618
+ resolution: new URL(builtinProtocol + packageSpecifier)
619
+ }
620
+
621
+ return resolved ? RESOLVED : YIELDED
622
+ }
623
+
624
+ let version = null
625
+
626
+ if (packageVersion === null) {
627
+ version = targetVersion
628
+ } else if (targetVersion === null || packageVersion === targetVersion) {
629
+ version = packageVersion
630
+ }
631
+
632
+ if (version !== null) {
633
+ const resolved = yield {
634
+ resolution: new URL(builtinProtocol + packageSpecifier + '@' + version)
635
+ }
636
+
637
+ return resolved ? RESOLVED : YIELDED
638
+ }
639
+ }
640
+
641
+ return UNRESOLVED
642
+ }
643
+
644
+ if (Array.isArray(target)) {
645
+ let status = UNRESOLVED
646
+
647
+ for (const targetValue of target) {
648
+ status |= yield* exports.builtinTarget(packageSpecifier, packageVersion, targetValue, opts)
649
+
650
+ if (status === RESOLVED) return status
651
+ }
652
+
653
+ return status
654
+ }
655
+
656
+ if (typeof target === 'object' && target !== null) {
657
+ let status = UNRESOLVED
658
+
659
+ for (const [condition, targetValue, subset] of exports.conditionMatches(
660
+ target,
661
+ conditions,
662
+ opts
663
+ )) {
664
+ matchedConditions.push(condition)
665
+
666
+ status |= yield* exports.builtinTarget(packageSpecifier, packageVersion, targetValue, {
667
+ ...opts,
668
+ conditions: subset
669
+ })
670
+
671
+ matchedConditions.pop()
672
+ }
673
+
674
+ return status
675
+ }
676
+
677
+ return UNRESOLVED
678
+ }
679
+
680
+ exports.conditionMatches = function* conditionMatches(target, conditions, opts = {}) {
681
+ if (conditions.every((condition) => typeof condition === 'string')) {
682
+ const keys = Object.keys(target)
683
+
684
+ for (const condition of keys) {
685
+ if (condition === 'default' || conditions.includes(condition)) {
686
+ yield [condition, target[condition], conditions]
687
+
688
+ return true
689
+ }
690
+ }
691
+
692
+ return false
693
+ }
694
+
695
+ let yielded = false
696
+
697
+ for (const subset of conditions) {
698
+ if (yield* conditionMatches(target, subset, opts)) {
699
+ yielded = true
700
+ }
701
+ }
702
+
703
+ return yielded
704
+ }
705
+
706
+ exports.lookupPackageRoot = function* (packageName, parentURL) {
707
+ if (hasOpaquePath(parentURL)) return null
708
+
709
+ parentURL = new URL(parentURL.href)
710
+
711
+ do {
712
+ const packageURL = new URL('node_modules/' + packageName + '/', parentURL)
713
+
714
+ const info = yield new URL('package.json', packageURL)
715
+
716
+ if (info) return info
717
+
718
+ parentURL.pathname = parentURL.pathname.substring(0, parentURL.pathname.lastIndexOf('/'))
719
+
720
+ if (
721
+ parentURL.pathname.length === 3 &&
722
+ exports.isWindowsDriveLetter(parentURL.pathname.substring(1))
723
+ ) {
724
+ break
725
+ }
726
+ } while (parentURL.pathname !== '' && parentURL.pathname !== '/')
727
+
728
+ return null
729
+ }
730
+
731
+ exports.lookupPackageScope = function* lookupPackageScope(scopeURL, opts = {}) {
732
+ const { resolutions = null } = opts
733
+
734
+ if (resolutions) {
735
+ for (const { resolution } of exports.preresolved('#package', resolutions, scopeURL, opts)) {
736
+ if (resolution) return yield resolution
737
+ }
738
+ }
739
+
740
+ if (hasOpaquePath(scopeURL)) return null
741
+
742
+ scopeURL = new URL(scopeURL.href)
743
+
744
+ do {
745
+ if (scopeURL.pathname.endsWith('/node_modules')) break
746
+
747
+ const info = yield new URL('package.json', scopeURL)
748
+
749
+ if (info) return info
750
+
751
+ scopeURL.pathname = scopeURL.pathname.substring(0, scopeURL.pathname.lastIndexOf('/'))
752
+
753
+ if (
754
+ scopeURL.pathname.length === 3 &&
755
+ exports.isWindowsDriveLetter(scopeURL.pathname.substring(1))
756
+ ) {
757
+ break
758
+ }
759
+ } while (scopeURL.pathname !== '' && scopeURL.pathname !== '/')
760
+
761
+ return null
762
+ }
763
+
764
+ exports.file = function* (filename, parentURL, isIndex, opts = {}) {
765
+ if (
766
+ filename === '.' ||
767
+ filename === '..' ||
768
+ filename[filename.length - 1] === '/' ||
769
+ filename[filename.length - 1] === '\\'
770
+ ) {
771
+ return UNRESOLVED
772
+ }
773
+
774
+ if (hasOpaquePath(parentURL)) return UNRESOLVED
775
+
776
+ if (parentURL.protocol === 'file:' && /%2f|%5c/i.test(filename)) {
777
+ throw errors.INVALID_MODULE_SPECIFIER(`Module specifier '${filename}' is invalid`)
778
+ }
779
+
780
+ const { extensions = [] } = opts
781
+
782
+ let status = UNRESOLVED
783
+
784
+ if (!isIndex) {
785
+ if (yield { resolution: new URL(filename, parentURL) }) {
786
+ return RESOLVED
787
+ }
788
+
789
+ status = YIELDED
790
+ }
791
+
792
+ for (const ext of extensions) {
793
+ if (filename.endsWith(ext)) continue
794
+
795
+ if (yield { resolution: new URL(filename + ext, parentURL) }) {
796
+ return RESOLVED
797
+ }
798
+
799
+ status = YIELDED
800
+ }
801
+
802
+ return status
803
+ }
804
+
805
+ exports.directory = function* (dirname, parentURL, opts = {}) {
806
+ const { directories = false } = opts
807
+
808
+ if (hasOpaquePath(parentURL)) return UNRESOLVED
809
+
810
+ let directoryURL
811
+
812
+ if (dirname[dirname.length - 1] === '/' || dirname[dirname.length - 1] === '\\') {
813
+ directoryURL = new URL(dirname, parentURL)
814
+ } else {
815
+ directoryURL = new URL(dirname + '/', parentURL)
816
+ }
817
+
818
+ let yielded = false
819
+
820
+ if (directories) {
821
+ if (yield { resolution: directoryURL }) return RESOLVED
822
+
823
+ yielded = true
824
+ }
825
+
826
+ const info = yield { package: new URL('package.json', directoryURL) }
827
+
828
+ if (info) {
829
+ if (info.exports) {
830
+ let status = yield* exports.packageExports(directoryURL, '.', info.exports, opts)
831
+
832
+ if (yielded) status |= YIELDED
833
+
834
+ return status
835
+ }
836
+
837
+ if (typeof info.main === 'string' && info.main !== '') {
838
+ let status = yield* exports.file(info.main, directoryURL, false, opts)
839
+
840
+ if (status === RESOLVED) return status
841
+
842
+ if ((status & YIELDED) !== 0) yielded = true
843
+
844
+ status = yield* exports.directory(info.main, directoryURL, opts)
845
+
846
+ if (yielded) status |= YIELDED
847
+
848
+ return status
849
+ }
850
+ }
851
+
852
+ let status = yield* exports.file('index', directoryURL, true, opts)
853
+
854
+ if (yielded) status |= YIELDED
855
+
856
+ return status
857
+ }
858
+
859
+ // https://url.spec.whatwg.org/#url-opaque-path
860
+ function hasOpaquePath(url) {
861
+ return url.pathname[0] !== '/'
862
+ }
863
+
864
+ // https://infra.spec.whatwg.org/#ascii-upper-alpha
865
+ function isASCIIUpperAlpha(c) {
866
+ return c >= 0x41 && c <= 0x5a
867
+ }
868
+
869
+ // https://infra.spec.whatwg.org/#ascii-lower-alpha
870
+ function isASCIILowerAlpha(c) {
871
+ return c >= 0x61 && c <= 0x7a
872
+ }
873
+
874
+ // https://infra.spec.whatwg.org/#ascii-alpha
875
+ function isASCIIAlpha(c) {
876
+ return isASCIIUpperAlpha(c) || isASCIILowerAlpha(c)
877
+ }
878
+
879
+ // https://url.spec.whatwg.org/#windows-drive-letter
880
+ exports.isWindowsDriveLetter = function isWindowsDriveLetter(input) {
881
+ return (
882
+ input.length >= 2 &&
883
+ isASCIIAlpha(input.charCodeAt(0)) &&
884
+ (input.charCodeAt(1) === 0x3a || input.charCodeAt(1) === 0x7c)
885
+ )
886
+ }
887
+
888
+ // https://url.spec.whatwg.org/#start-with-a-windows-drive-letter
889
+ exports.startsWithWindowsDriveLetter = function startsWithWindowsDriveLetter(input) {
890
+ return (
891
+ input.length >= 2 &&
892
+ exports.isWindowsDriveLetter(input) &&
893
+ (input.length === 2 ||
894
+ input.charCodeAt(2) === 0x2f ||
895
+ input.charCodeAt(2) === 0x5c ||
896
+ input.charCodeAt(2) === 0x3f ||
897
+ input.charCodeAt(2) === 0x23)
898
+ )
899
+ }