@@ -342,8 +342,8 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
342
342
* @param {URL } packageJSONUrl
343
343
* @param {string | URL | undefined } base
344
344
*/
345
- function throwImportNotDefined ( specifier , packageJSONUrl , base ) {
346
- throw new ERR_PACKAGE_IMPORT_NOT_DEFINED (
345
+ function importNotDefined ( specifier , packageJSONUrl , base ) {
346
+ return new ERR_PACKAGE_IMPORT_NOT_DEFINED (
347
347
specifier , packageJSONUrl && fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) ,
348
348
fileURLToPath ( base ) ) ;
349
349
}
@@ -353,8 +353,8 @@ function throwImportNotDefined(specifier, packageJSONUrl, base) {
353
353
* @param {URL } packageJSONUrl
354
354
* @param {string | URL | undefined } base
355
355
*/
356
- function throwExportsNotFound ( subpath , packageJSONUrl , base ) {
357
- throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
356
+ function exportsNotFound ( subpath , packageJSONUrl , base ) {
357
+ return new ERR_PACKAGE_PATH_NOT_EXPORTED (
358
358
fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) , subpath ,
359
359
base && fileURLToPath ( base ) ) ;
360
360
}
@@ -375,14 +375,14 @@ function throwInvalidSubpath(request, match, packageJSONUrl, internal, base) {
375
375
base && fileURLToPath ( base ) ) ;
376
376
}
377
377
378
- function throwInvalidPackageTarget (
378
+ function invalidPackageTarget (
379
379
subpath , target , packageJSONUrl , internal , base ) {
380
380
if ( typeof target === 'object' && target !== null ) {
381
381
target = JSONStringify ( target , null , '' ) ;
382
382
} else {
383
383
target = `${ target } ` ;
384
384
}
385
- throw new ERR_INVALID_PACKAGE_TARGET (
385
+ return new ERR_INVALID_PACKAGE_TARGET (
386
386
fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) , subpath , target ,
387
387
internal , base && fileURLToPath ( base ) ) ;
388
388
}
@@ -392,6 +392,19 @@ const deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o
392
392
const invalidPackageNameRegEx = / ^ \. | % | \\ / ;
393
393
const patternRegEx = / \* / g;
394
394
395
+ /**
396
+ *
397
+ * @param {string } target
398
+ * @param {* } subpath
399
+ * @param {* } match
400
+ * @param {* } packageJSONUrl
401
+ * @param {* } base
402
+ * @param {* } pattern
403
+ * @param {* } internal
404
+ * @param {* } isPathMap
405
+ * @param {* } conditions
406
+ * @returns {URL }
407
+ */
395
408
function resolvePackageTargetString (
396
409
target ,
397
410
subpath ,
@@ -405,7 +418,7 @@ function resolvePackageTargetString(
405
418
) {
406
419
407
420
if ( subpath !== '' && ! pattern && target [ target . length - 1 ] !== '/' )
408
- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
421
+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
409
422
410
423
if ( ! StringPrototypeStartsWith ( target , './' ) ) {
411
424
if ( internal && ! StringPrototypeStartsWith ( target , '../' ) &&
@@ -425,7 +438,7 @@ function resolvePackageTargetString(
425
438
exportTarget , packageJSONUrl , conditions ) ;
426
439
}
427
440
}
428
- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
441
+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
429
442
}
430
443
431
444
if ( RegExpPrototypeExec ( invalidSegmentRegEx , StringPrototypeSlice ( target , 2 ) ) !== null ) {
@@ -440,7 +453,7 @@ function resolvePackageTargetString(
440
453
emitInvalidSegmentDeprecation ( resolvedTarget , request , match , packageJSONUrl , internal , base , true ) ;
441
454
}
442
455
} else {
443
- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
456
+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
444
457
}
445
458
}
446
459
@@ -449,7 +462,7 @@ function resolvePackageTargetString(
449
462
const packagePath = new URL ( '.' , packageJSONUrl ) . pathname ;
450
463
451
464
if ( ! StringPrototypeStartsWith ( resolvedPath , packagePath ) )
452
- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
465
+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
453
466
454
467
if ( subpath === '' ) return resolved ;
455
468
@@ -486,6 +499,19 @@ function isArrayIndex(key) {
486
499
return keyNum >= 0 && keyNum < 0xFFFF_FFFF ;
487
500
}
488
501
502
+ /**
503
+ *
504
+ * @param {* } packageJSONUrl
505
+ * @param {string|[string] } target
506
+ * @param {* } subpath
507
+ * @param {* } packageSubpath
508
+ * @param {* } base
509
+ * @param {* } pattern
510
+ * @param {* } internal
511
+ * @param {* } isPathMap
512
+ * @param {* } conditions
513
+ * @returns {URL|null }
514
+ */
489
515
function resolvePackageTarget ( packageJSONUrl , target , subpath , packageSubpath ,
490
516
base , pattern , internal , isPathMap , conditions ) {
491
517
if ( typeof target === 'string' ) {
@@ -550,8 +576,8 @@ function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath,
550
576
} else if ( target === null ) {
551
577
return null ;
552
578
}
553
- throwInvalidPackageTarget ( packageSubpath , target , packageJSONUrl , internal ,
554
- base ) ;
579
+ throw invalidPackageTarget ( packageSubpath , target , packageJSONUrl , internal ,
580
+ base ) ;
555
581
}
556
582
557
583
/**
@@ -608,7 +634,7 @@ function packageExportsResolve(
608
634
) ;
609
635
610
636
if ( resolveResult == null ) {
611
- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
637
+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
612
638
}
613
639
614
640
return resolveResult ;
@@ -659,12 +685,12 @@ function packageExportsResolve(
659
685
conditions ) ;
660
686
661
687
if ( resolveResult == null ) {
662
- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
688
+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
663
689
}
664
690
return resolveResult ;
665
691
}
666
692
667
- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
693
+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
668
694
}
669
695
670
696
function patternKeyCompare ( a , b ) {
@@ -744,7 +770,7 @@ function packageImportsResolve(name, base, conditions) {
744
770
}
745
771
}
746
772
}
747
- throwImportNotDefined ( name , packageJSONUrl , base ) ;
773
+ throw importNotDefined ( name , packageJSONUrl , base ) ;
748
774
}
749
775
750
776
/**
0 commit comments