@@ -343,8 +343,8 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
343343 * @param {URL } packageJSONUrl
344344 * @param {string | URL | undefined } base
345345 */
346- function throwImportNotDefined ( specifier , packageJSONUrl , base ) {
347- throw new ERR_PACKAGE_IMPORT_NOT_DEFINED (
346+ function importNotDefined ( specifier , packageJSONUrl , base ) {
347+ return new ERR_PACKAGE_IMPORT_NOT_DEFINED (
348348 specifier , packageJSONUrl && fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) ,
349349 fileURLToPath ( base ) ) ;
350350}
@@ -354,8 +354,8 @@ function throwImportNotDefined(specifier, packageJSONUrl, base) {
354354 * @param {URL } packageJSONUrl
355355 * @param {string | URL | undefined } base
356356 */
357- function throwExportsNotFound ( subpath , packageJSONUrl , base ) {
358- throw new ERR_PACKAGE_PATH_NOT_EXPORTED (
357+ function exportsNotFound ( subpath , packageJSONUrl , base ) {
358+ return new ERR_PACKAGE_PATH_NOT_EXPORTED (
359359 fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) , subpath ,
360360 base && fileURLToPath ( base ) ) ;
361361}
@@ -376,14 +376,14 @@ function throwInvalidSubpath(request, match, packageJSONUrl, internal, base) {
376376 base && fileURLToPath ( base ) ) ;
377377}
378378
379- function throwInvalidPackageTarget (
379+ function invalidPackageTarget (
380380 subpath , target , packageJSONUrl , internal , base ) {
381381 if ( typeof target === 'object' && target !== null ) {
382382 target = JSONStringify ( target , null , '' ) ;
383383 } else {
384384 target = `${ target } ` ;
385385 }
386- throw new ERR_INVALID_PACKAGE_TARGET (
386+ return new ERR_INVALID_PACKAGE_TARGET (
387387 fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) , subpath , target ,
388388 internal , base && fileURLToPath ( base ) ) ;
389389}
@@ -393,6 +393,19 @@ const deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o
393393const invalidPackageNameRegEx = / ^ \. | % | \\ / ;
394394const patternRegEx = / \* / g;
395395
396+ /**
397+ *
398+ * @param {string } target
399+ * @param {* } subpath
400+ * @param {* } match
401+ * @param {* } packageJSONUrl
402+ * @param {* } base
403+ * @param {* } pattern
404+ * @param {* } internal
405+ * @param {* } isPathMap
406+ * @param {* } conditions
407+ * @returns {URL }
408+ */
396409function resolvePackageTargetString (
397410 target ,
398411 subpath ,
@@ -406,7 +419,7 @@ function resolvePackageTargetString(
406419) {
407420
408421 if ( subpath !== '' && ! pattern && target [ target . length - 1 ] !== '/' )
409- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
422+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
410423
411424 if ( ! StringPrototypeStartsWith ( target , './' ) ) {
412425 if ( internal && ! StringPrototypeStartsWith ( target , '../' ) &&
@@ -426,7 +439,7 @@ function resolvePackageTargetString(
426439 exportTarget , packageJSONUrl , conditions ) ;
427440 }
428441 }
429- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
442+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
430443 }
431444
432445 if ( RegExpPrototypeExec ( invalidSegmentRegEx , StringPrototypeSlice ( target , 2 ) ) !== null ) {
@@ -441,7 +454,7 @@ function resolvePackageTargetString(
441454 emitInvalidSegmentDeprecation ( resolvedTarget , request , match , packageJSONUrl , internal , base , true ) ;
442455 }
443456 } else {
444- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
457+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
445458 }
446459 }
447460
@@ -450,7 +463,7 @@ function resolvePackageTargetString(
450463 const packagePath = new URL ( '.' , packageJSONUrl ) . pathname ;
451464
452465 if ( ! StringPrototypeStartsWith ( resolvedPath , packagePath ) )
453- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
466+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
454467
455468 if ( subpath === '' ) return resolved ;
456469
@@ -487,6 +500,19 @@ function isArrayIndex(key) {
487500 return keyNum >= 0 && keyNum < 0xFFFF_FFFF ;
488501}
489502
503+ /**
504+ *
505+ * @param {* } packageJSONUrl
506+ * @param {string|[string] } target
507+ * @param {* } subpath
508+ * @param {* } packageSubpath
509+ * @param {* } base
510+ * @param {* } pattern
511+ * @param {* } internal
512+ * @param {* } isPathMap
513+ * @param {* } conditions
514+ * @returns {URL|null }
515+ */
490516function resolvePackageTarget ( packageJSONUrl , target , subpath , packageSubpath ,
491517 base , pattern , internal , isPathMap , conditions ) {
492518 if ( typeof target === 'string' ) {
@@ -551,8 +577,8 @@ function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath,
551577 } else if ( target === null ) {
552578 return null ;
553579 }
554- throwInvalidPackageTarget ( packageSubpath , target , packageJSONUrl , internal ,
555- base ) ;
580+ throw invalidPackageTarget ( packageSubpath , target , packageJSONUrl , internal ,
581+ base ) ;
556582}
557583
558584/**
@@ -609,7 +635,7 @@ function packageExportsResolve(
609635 ) ;
610636
611637 if ( resolveResult == null ) {
612- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
638+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
613639 }
614640
615641 return resolveResult ;
@@ -660,12 +686,12 @@ function packageExportsResolve(
660686 conditions ) ;
661687
662688 if ( resolveResult == null ) {
663- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
689+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
664690 }
665691 return resolveResult ;
666692 }
667693
668- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
694+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
669695}
670696
671697function patternKeyCompare ( a , b ) {
@@ -745,7 +771,7 @@ function packageImportsResolve(name, base, conditions) {
745771 }
746772 }
747773 }
748- throwImportNotDefined ( name , packageJSONUrl , base ) ;
774+ throw importNotDefined ( name , packageJSONUrl , base ) ;
749775}
750776
751777/**
0 commit comments