@@ -277,8 +277,8 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
277
277
* @param {URL } packageJSONUrl
278
278
* @param {string | URL | undefined } base
279
279
*/
280
- function throwImportNotDefined ( specifier , packageJSONUrl , base ) {
281
- throw new ERR_PACKAGE_IMPORT_NOT_DEFINED (
280
+ function importNotDefined ( specifier , packageJSONUrl , base ) {
281
+ return new ERR_PACKAGE_IMPORT_NOT_DEFINED (
282
282
specifier , packageJSONUrl && fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) ,
283
283
fileURLToPath ( base ) ) ;
284
284
}
@@ -288,8 +288,8 @@ function throwImportNotDefined(specifier, packageJSONUrl, base) {
288
288
* @param {URL } packageJSONUrl
289
289
* @param {string | URL | undefined } base
290
290
*/
291
- function throwExportsNotFound ( subpath , packageJSONUrl , base ) {
292
- throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
291
+ function exportsNotFound ( subpath , packageJSONUrl , base ) {
292
+ return new ERR_PACKAGE_PATH_NOT_EXPORTED (
293
293
fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) , subpath ,
294
294
base && fileURLToPath ( base ) ) ;
295
295
}
@@ -310,14 +310,14 @@ function throwInvalidSubpath(request, match, packageJSONUrl, internal, base) {
310
310
base && fileURLToPath ( base ) ) ;
311
311
}
312
312
313
- function throwInvalidPackageTarget (
313
+ function invalidPackageTarget (
314
314
subpath , target , packageJSONUrl , internal , base ) {
315
315
if ( typeof target === 'object' && target !== null ) {
316
316
target = JSONStringify ( target , null , '' ) ;
317
317
} else {
318
318
target = `${ target } ` ;
319
319
}
320
- throw new ERR_INVALID_PACKAGE_TARGET (
320
+ return new ERR_INVALID_PACKAGE_TARGET (
321
321
fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) , subpath , target ,
322
322
internal , base && fileURLToPath ( base ) ) ;
323
323
}
@@ -327,6 +327,19 @@ const deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o
327
327
const invalidPackageNameRegEx = / ^ \. | % | \\ / ;
328
328
const patternRegEx = / \* / g;
329
329
330
+ /**
331
+ *
332
+ * @param {string } target
333
+ * @param {* } subpath
334
+ * @param {* } match
335
+ * @param {* } packageJSONUrl
336
+ * @param {* } base
337
+ * @param {* } pattern
338
+ * @param {* } internal
339
+ * @param {* } isPathMap
340
+ * @param {* } conditions
341
+ * @returns {URL }
342
+ */
330
343
function resolvePackageTargetString (
331
344
target ,
332
345
subpath ,
@@ -340,7 +353,7 @@ function resolvePackageTargetString(
340
353
) {
341
354
342
355
if ( subpath !== '' && ! pattern && target [ target . length - 1 ] !== '/' )
343
- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
356
+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
344
357
345
358
if ( ! StringPrototypeStartsWith ( target , './' ) ) {
346
359
if ( internal && ! StringPrototypeStartsWith ( target , '../' ) &&
@@ -360,7 +373,7 @@ function resolvePackageTargetString(
360
373
exportTarget , packageJSONUrl , conditions ) ;
361
374
}
362
375
}
363
- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
376
+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
364
377
}
365
378
366
379
if ( RegExpPrototypeExec ( invalidSegmentRegEx , StringPrototypeSlice ( target , 2 ) ) !== null ) {
@@ -375,7 +388,7 @@ function resolvePackageTargetString(
375
388
emitInvalidSegmentDeprecation ( resolvedTarget , request , match , packageJSONUrl , internal , base , true ) ;
376
389
}
377
390
} else {
378
- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
391
+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
379
392
}
380
393
}
381
394
@@ -384,7 +397,7 @@ function resolvePackageTargetString(
384
397
const packagePath = new URL ( '.' , packageJSONUrl ) . pathname ;
385
398
386
399
if ( ! StringPrototypeStartsWith ( resolvedPath , packagePath ) )
387
- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
400
+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
388
401
389
402
if ( subpath === '' ) return resolved ;
390
403
@@ -421,6 +434,19 @@ function isArrayIndex(key) {
421
434
return keyNum >= 0 && keyNum < 0xFFFF_FFFF ;
422
435
}
423
436
437
+ /**
438
+ *
439
+ * @param {* } packageJSONUrl
440
+ * @param {string|[string] } target
441
+ * @param {* } subpath
442
+ * @param {* } packageSubpath
443
+ * @param {* } base
444
+ * @param {* } pattern
445
+ * @param {* } internal
446
+ * @param {* } isPathMap
447
+ * @param {* } conditions
448
+ * @returns {URL|null }
449
+ */
424
450
function resolvePackageTarget ( packageJSONUrl , target , subpath , packageSubpath ,
425
451
base , pattern , internal , isPathMap , conditions ) {
426
452
if ( typeof target === 'string' ) {
@@ -485,8 +511,8 @@ function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath,
485
511
} else if ( target === null ) {
486
512
return null ;
487
513
}
488
- throwInvalidPackageTarget ( packageSubpath , target , packageJSONUrl , internal ,
489
- base ) ;
514
+ throw invalidPackageTarget ( packageSubpath , target , packageJSONUrl , internal ,
515
+ base ) ;
490
516
}
491
517
492
518
/**
@@ -543,7 +569,7 @@ function packageExportsResolve(
543
569
) ;
544
570
545
571
if ( resolveResult == null ) {
546
- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
572
+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
547
573
}
548
574
549
575
return resolveResult ;
@@ -594,12 +620,12 @@ function packageExportsResolve(
594
620
conditions ) ;
595
621
596
622
if ( resolveResult == null ) {
597
- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
623
+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
598
624
}
599
625
return resolveResult ;
600
626
}
601
627
602
- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
628
+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
603
629
}
604
630
605
631
function patternKeyCompare ( a , b ) {
@@ -679,7 +705,7 @@ function packageImportsResolve(name, base, conditions) {
679
705
}
680
706
}
681
707
}
682
- throwImportNotDefined ( name , packageJSONUrl , base ) ;
708
+ throw importNotDefined ( name , packageJSONUrl , base ) ;
683
709
}
684
710
685
711
/**
0 commit comments