@@ -343,8 +343,8 @@ function finalizeResolution(resolved, base, preserveSymlinks) { |
343 | 343 | * @param {URL} packageJSONUrl |
344 | 344 | * @param {string | URL | undefined} base |
345 | 345 | */ |
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( |
348 | 348 | specifier, packageJSONUrl && fileURLToPath(new URL('.', packageJSONUrl)), |
349 | 349 | fileURLToPath(base)); |
350 | 350 | } |
@@ -354,8 +354,8 @@ function throwImportNotDefined(specifier, packageJSONUrl, base) { |
354 | 354 | * @param {URL} packageJSONUrl |
355 | 355 | * @param {string | URL | undefined} base |
356 | 356 | */ |
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( |
359 | 359 | fileURLToPath(new URL('.', packageJSONUrl)), subpath, |
360 | 360 | base && fileURLToPath(base)); |
361 | 361 | } |
@@ -376,14 +376,14 @@ function throwInvalidSubpath(request, match, packageJSONUrl, internal, base) { |
376 | 376 | base && fileURLToPath(base)); |
377 | 377 | } |
378 | 378 |
|
379 | | -function throwInvalidPackageTarget( |
| 379 | +function invalidPackageTarget( |
380 | 380 | subpath, target, packageJSONUrl, internal, base) { |
381 | 381 | if (typeof target === 'object' && target !== null) { |
382 | 382 | target = JSONStringify(target, null, ''); |
383 | 383 | } else { |
384 | 384 | target = `${target}`; |
385 | 385 | } |
386 | | - throw new ERR_INVALID_PACKAGE_TARGET( |
| 386 | + return new ERR_INVALID_PACKAGE_TARGET( |
387 | 387 | fileURLToPath(new URL('.', packageJSONUrl)), subpath, target, |
388 | 388 | internal, base && fileURLToPath(base)); |
389 | 389 | } |
@@ -393,6 +393,19 @@ const deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o |
393 | 393 | const invalidPackageNameRegEx = /^\.|%|\\/; |
394 | 394 | const patternRegEx = /\*/g; |
395 | 395 |
|
| 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 | + */ |
396 | 409 | function resolvePackageTargetString( |
397 | 410 | target, |
398 | 411 | subpath, |
@@ -406,7 +419,7 @@ function resolvePackageTargetString( |
406 | 419 | ) { |
407 | 420 |
|
408 | 421 | if (subpath !== '' && !pattern && target[target.length - 1] !== '/') |
409 | | - throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base); |
| 422 | + throw invalidPackageTarget(match, target, packageJSONUrl, internal, base); |
410 | 423 |
|
411 | 424 | if (!StringPrototypeStartsWith(target, './')) { |
412 | 425 | if (internal && !StringPrototypeStartsWith(target, '../') && |
@@ -426,7 +439,7 @@ function resolvePackageTargetString( |
426 | 439 | exportTarget, packageJSONUrl, conditions); |
427 | 440 | } |
428 | 441 | } |
429 | | - throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base); |
| 442 | + throw invalidPackageTarget(match, target, packageJSONUrl, internal, base); |
430 | 443 | } |
431 | 444 |
|
432 | 445 | if (RegExpPrototypeExec(invalidSegmentRegEx, StringPrototypeSlice(target, 2)) !== null) { |
@@ -441,7 +454,7 @@ function resolvePackageTargetString( |
441 | 454 | emitInvalidSegmentDeprecation(resolvedTarget, request, match, packageJSONUrl, internal, base, true); |
442 | 455 | } |
443 | 456 | } else { |
444 | | - throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base); |
| 457 | + throw invalidPackageTarget(match, target, packageJSONUrl, internal, base); |
445 | 458 | } |
446 | 459 | } |
447 | 460 |
|
@@ -450,7 +463,7 @@ function resolvePackageTargetString( |
450 | 463 | const packagePath = new URL('.', packageJSONUrl).pathname; |
451 | 464 |
|
452 | 465 | if (!StringPrototypeStartsWith(resolvedPath, packagePath)) |
453 | | - throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base); |
| 466 | + throw invalidPackageTarget(match, target, packageJSONUrl, internal, base); |
454 | 467 |
|
455 | 468 | if (subpath === '') return resolved; |
456 | 469 |
|
@@ -487,6 +500,19 @@ function isArrayIndex(key) { |
487 | 500 | return keyNum >= 0 && keyNum < 0xFFFF_FFFF; |
488 | 501 | } |
489 | 502 |
|
| 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 | + */ |
490 | 516 | function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath, |
491 | 517 | base, pattern, internal, isPathMap, conditions) { |
492 | 518 | if (typeof target === 'string') { |
@@ -551,8 +577,8 @@ function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath, |
551 | 577 | } else if (target === null) { |
552 | 578 | return null; |
553 | 579 | } |
554 | | - throwInvalidPackageTarget(packageSubpath, target, packageJSONUrl, internal, |
555 | | - base); |
| 580 | + throw invalidPackageTarget(packageSubpath, target, packageJSONUrl, internal, |
| 581 | + base); |
556 | 582 | } |
557 | 583 |
|
558 | 584 | /** |
@@ -609,7 +635,7 @@ function packageExportsResolve( |
609 | 635 | ); |
610 | 636 |
|
611 | 637 | if (resolveResult == null) { |
612 | | - throwExportsNotFound(packageSubpath, packageJSONUrl, base); |
| 638 | + throw exportsNotFound(packageSubpath, packageJSONUrl, base); |
613 | 639 | } |
614 | 640 |
|
615 | 641 | return resolveResult; |
@@ -660,12 +686,12 @@ function packageExportsResolve( |
660 | 686 | conditions); |
661 | 687 |
|
662 | 688 | if (resolveResult == null) { |
663 | | - throwExportsNotFound(packageSubpath, packageJSONUrl, base); |
| 689 | + throw exportsNotFound(packageSubpath, packageJSONUrl, base); |
664 | 690 | } |
665 | 691 | return resolveResult; |
666 | 692 | } |
667 | 693 |
|
668 | | - throwExportsNotFound(packageSubpath, packageJSONUrl, base); |
| 694 | + throw exportsNotFound(packageSubpath, packageJSONUrl, base); |
669 | 695 | } |
670 | 696 |
|
671 | 697 | function patternKeyCompare(a, b) { |
@@ -745,7 +771,7 @@ function packageImportsResolve(name, base, conditions) { |
745 | 771 | } |
746 | 772 | } |
747 | 773 | } |
748 | | - throwImportNotDefined(name, packageJSONUrl, base); |
| 774 | + throw importNotDefined(name, packageJSONUrl, base); |
749 | 775 | } |
750 | 776 |
|
751 | 777 | /** |
|