@@ -277,8 +277,8 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
277277 * @param {URL } packageJSONUrl
278278 * @param {string | URL | undefined } base
279279 */
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 (
282282 specifier , packageJSONUrl && fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) ,
283283 fileURLToPath ( base ) ) ;
284284}
@@ -288,8 +288,8 @@ function throwImportNotDefined(specifier, packageJSONUrl, base) {
288288 * @param {URL } packageJSONUrl
289289 * @param {string | URL | undefined } base
290290 */
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 (
293293 fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) , subpath ,
294294 base && fileURLToPath ( base ) ) ;
295295}
@@ -310,14 +310,14 @@ function throwInvalidSubpath(request, match, packageJSONUrl, internal, base) {
310310 base && fileURLToPath ( base ) ) ;
311311}
312312
313- function throwInvalidPackageTarget (
313+ function invalidPackageTarget (
314314 subpath , target , packageJSONUrl , internal , base ) {
315315 if ( typeof target === 'object' && target !== null ) {
316316 target = JSONStringify ( target , null , '' ) ;
317317 } else {
318318 target = `${ target } ` ;
319319 }
320- throw new ERR_INVALID_PACKAGE_TARGET (
320+ return new ERR_INVALID_PACKAGE_TARGET (
321321 fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) , subpath , target ,
322322 internal , base && fileURLToPath ( base ) ) ;
323323}
@@ -327,6 +327,19 @@ const deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o
327327const invalidPackageNameRegEx = / ^ \. | % | \\ / ;
328328const patternRegEx = / \* / g;
329329
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+ */
330343function resolvePackageTargetString (
331344 target ,
332345 subpath ,
@@ -340,7 +353,7 @@ function resolvePackageTargetString(
340353) {
341354
342355 if ( subpath !== '' && ! pattern && target [ target . length - 1 ] !== '/' )
343- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
356+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
344357
345358 if ( ! StringPrototypeStartsWith ( target , './' ) ) {
346359 if ( internal && ! StringPrototypeStartsWith ( target , '../' ) &&
@@ -360,7 +373,7 @@ function resolvePackageTargetString(
360373 exportTarget , packageJSONUrl , conditions ) ;
361374 }
362375 }
363- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
376+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
364377 }
365378
366379 if ( RegExpPrototypeExec ( invalidSegmentRegEx , StringPrototypeSlice ( target , 2 ) ) !== null ) {
@@ -375,7 +388,7 @@ function resolvePackageTargetString(
375388 emitInvalidSegmentDeprecation ( resolvedTarget , request , match , packageJSONUrl , internal , base , true ) ;
376389 }
377390 } else {
378- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
391+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
379392 }
380393 }
381394
@@ -384,7 +397,7 @@ function resolvePackageTargetString(
384397 const packagePath = new URL ( '.' , packageJSONUrl ) . pathname ;
385398
386399 if ( ! StringPrototypeStartsWith ( resolvedPath , packagePath ) )
387- throwInvalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
400+ throw invalidPackageTarget ( match , target , packageJSONUrl , internal , base ) ;
388401
389402 if ( subpath === '' ) return resolved ;
390403
@@ -421,6 +434,19 @@ function isArrayIndex(key) {
421434 return keyNum >= 0 && keyNum < 0xFFFF_FFFF ;
422435}
423436
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+ */
424450function resolvePackageTarget ( packageJSONUrl , target , subpath , packageSubpath ,
425451 base , pattern , internal , isPathMap , conditions ) {
426452 if ( typeof target === 'string' ) {
@@ -485,8 +511,8 @@ function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath,
485511 } else if ( target === null ) {
486512 return null ;
487513 }
488- throwInvalidPackageTarget ( packageSubpath , target , packageJSONUrl , internal ,
489- base ) ;
514+ throw invalidPackageTarget ( packageSubpath , target , packageJSONUrl , internal ,
515+ base ) ;
490516}
491517
492518/**
@@ -543,7 +569,7 @@ function packageExportsResolve(
543569 ) ;
544570
545571 if ( resolveResult == null ) {
546- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
572+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
547573 }
548574
549575 return resolveResult ;
@@ -594,12 +620,12 @@ function packageExportsResolve(
594620 conditions ) ;
595621
596622 if ( resolveResult == null ) {
597- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
623+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
598624 }
599625 return resolveResult ;
600626 }
601627
602- throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
628+ throw exportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
603629}
604630
605631function patternKeyCompare ( a , b ) {
@@ -679,7 +705,7 @@ function packageImportsResolve(name, base, conditions) {
679705 }
680706 }
681707 }
682- throwImportNotDefined ( name , packageJSONUrl , base ) ;
708+ throw importNotDefined ( name , packageJSONUrl , base ) ;
683709}
684710
685711/**
0 commit comments