@rollup/plugin-node-resolve 13.0.3 → 13.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/index.js +181 -94
- package/dist/es/index.js +181 -94
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cjs/index.js
CHANGED
@@ -35,6 +35,10 @@ async function fileExists(filePath) {
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
|
38
|
+
async function resolveSymlink(path) {
|
39
|
+
return (await fileExists(path)) ? realpath(path) : path;
|
40
|
+
}
|
41
|
+
|
38
42
|
const onError = (error) => {
|
39
43
|
if (error.code === 'ENOENT') {
|
40
44
|
return false;
|
@@ -312,8 +316,8 @@ class InvalidConfigurationError extends ResolveError {
|
|
312
316
|
}
|
313
317
|
|
314
318
|
class InvalidModuleSpecifierError extends ResolveError {
|
315
|
-
constructor(context, internal) {
|
316
|
-
super(createErrorMsg(context, internal));
|
319
|
+
constructor(context, internal, reason) {
|
320
|
+
super(createErrorMsg(context, reason, internal));
|
317
321
|
}
|
318
322
|
}
|
319
323
|
|
@@ -540,7 +544,7 @@ async function resolvePackageImports({
|
|
540
544
|
}
|
541
545
|
|
542
546
|
if (importSpecifier === '#' || importSpecifier.startsWith('#/')) {
|
543
|
-
throw new InvalidModuleSpecifierError(context, 'Invalid import specifier.');
|
547
|
+
throw new InvalidModuleSpecifierError(context, true, 'Invalid import specifier.');
|
544
548
|
}
|
545
549
|
|
546
550
|
return resolvePackageImportsExports(context, {
|
@@ -571,11 +575,8 @@ async function getPackageJson(importer, pkgName, resolveOptions, moduleDirectori
|
|
571
575
|
}
|
572
576
|
}
|
573
577
|
|
574
|
-
async function
|
575
|
-
importer,
|
578
|
+
async function resolveIdClassic({
|
576
579
|
importSpecifier,
|
577
|
-
exportConditions,
|
578
|
-
warn,
|
579
580
|
packageInfoCache,
|
580
581
|
extensions,
|
581
582
|
mainFields,
|
@@ -622,8 +623,38 @@ async function resolveId({
|
|
622
623
|
};
|
623
624
|
|
624
625
|
let location;
|
626
|
+
try {
|
627
|
+
location = await resolveImportPath(importSpecifier, resolveOptions);
|
628
|
+
} catch (error) {
|
629
|
+
if (error.code !== 'MODULE_NOT_FOUND') {
|
630
|
+
throw error;
|
631
|
+
}
|
632
|
+
return null;
|
633
|
+
}
|
625
634
|
|
626
|
-
|
635
|
+
return {
|
636
|
+
location: preserveSymlinks ? location : await resolveSymlink(location),
|
637
|
+
hasModuleSideEffects,
|
638
|
+
hasPackageEntry,
|
639
|
+
packageBrowserField,
|
640
|
+
packageInfo
|
641
|
+
};
|
642
|
+
}
|
643
|
+
|
644
|
+
async function resolveWithExportMap({
|
645
|
+
importer,
|
646
|
+
importSpecifier,
|
647
|
+
exportConditions,
|
648
|
+
packageInfoCache,
|
649
|
+
extensions,
|
650
|
+
mainFields,
|
651
|
+
preserveSymlinks,
|
652
|
+
useBrowserOverrides,
|
653
|
+
baseDir,
|
654
|
+
moduleDirectories,
|
655
|
+
rootDir,
|
656
|
+
ignoreSideEffectsForRoot
|
657
|
+
}) {
|
627
658
|
if (importSpecifier.startsWith('#')) {
|
628
659
|
// this is a package internal import, resolve using package imports field
|
629
660
|
const resolveResult = await resolvePackageImports({
|
@@ -631,12 +662,9 @@ async function resolveId({
|
|
631
662
|
importer,
|
632
663
|
moduleDirs: moduleDirectories,
|
633
664
|
conditions: exportConditions,
|
634
|
-
resolveId(id, parent) {
|
635
|
-
return
|
665
|
+
resolveId(id /* , parent*/) {
|
666
|
+
return resolveIdClassic({
|
636
667
|
importSpecifier: id,
|
637
|
-
importer: parent,
|
638
|
-
exportConditions,
|
639
|
-
warn,
|
640
668
|
packageInfoCache,
|
641
669
|
extensions,
|
642
670
|
mainFields,
|
@@ -647,71 +675,91 @@ async function resolveId({
|
|
647
675
|
});
|
648
676
|
}
|
649
677
|
});
|
650
|
-
|
651
|
-
|
678
|
+
|
679
|
+
const location = url.fileURLToPath(resolveResult);
|
680
|
+
return {
|
681
|
+
location: preserveSymlinks ? location : await resolveSymlink(location),
|
682
|
+
hasModuleSideEffects: () => null,
|
683
|
+
hasPackageEntry: true,
|
684
|
+
packageBrowserField: false,
|
685
|
+
// eslint-disable-next-line no-undefined
|
686
|
+
packageInfo: undefined
|
687
|
+
};
|
688
|
+
}
|
689
|
+
|
690
|
+
const pkgName = getPackageName(importSpecifier);
|
691
|
+
if (pkgName) {
|
652
692
|
// it's a bare import, find the package.json and resolve using package exports if available
|
693
|
+
let hasModuleSideEffects = () => null;
|
694
|
+
let hasPackageEntry = true;
|
695
|
+
let packageBrowserField = false;
|
696
|
+
let packageInfo;
|
697
|
+
|
698
|
+
const filter = (pkg, pkgPath) => {
|
699
|
+
const info = getPackageInfo({
|
700
|
+
cache: packageInfoCache,
|
701
|
+
extensions,
|
702
|
+
pkg,
|
703
|
+
pkgPath,
|
704
|
+
mainFields,
|
705
|
+
preserveSymlinks,
|
706
|
+
useBrowserOverrides,
|
707
|
+
rootDir,
|
708
|
+
ignoreSideEffectsForRoot
|
709
|
+
});
|
710
|
+
|
711
|
+
({ packageInfo, hasModuleSideEffects, hasPackageEntry, packageBrowserField } = info);
|
712
|
+
|
713
|
+
return info.cachedPkg;
|
714
|
+
};
|
715
|
+
|
716
|
+
const resolveOptions = {
|
717
|
+
basedir: baseDir,
|
718
|
+
readFile: readCachedFile,
|
719
|
+
isFile: isFileCached,
|
720
|
+
isDirectory: isDirCached,
|
721
|
+
extensions,
|
722
|
+
includeCoreModules: false,
|
723
|
+
moduleDirectory: moduleDirectories,
|
724
|
+
preserveSymlinks,
|
725
|
+
packageFilter: filter
|
726
|
+
};
|
727
|
+
|
653
728
|
const result = await getPackageJson(importer, pkgName, resolveOptions, moduleDirectories);
|
654
729
|
|
655
730
|
if (result && result.pkgJson.exports) {
|
656
|
-
const { pkgJson, pkgJsonPath
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
731
|
+
const { pkgJson, pkgJsonPath } = result;
|
732
|
+
const subpath =
|
733
|
+
pkgName === importSpecifier ? '.' : `.${importSpecifier.substring(pkgName.length)}`;
|
734
|
+
const pkgDr = pkgJsonPath.replace('package.json', '');
|
735
|
+
const pkgURL = url.pathToFileURL(pkgDr);
|
736
|
+
|
737
|
+
const context = {
|
738
|
+
importer,
|
739
|
+
importSpecifier,
|
740
|
+
moduleDirs: moduleDirectories,
|
741
|
+
pkgURL,
|
742
|
+
pkgJsonPath,
|
743
|
+
conditions: exportConditions
|
744
|
+
};
|
745
|
+
const resolvedPackageExport = await resolvePackageExports(context, subpath, pkgJson.exports);
|
746
|
+
const location = url.fileURLToPath(resolvedPackageExport);
|
747
|
+
if (location) {
|
748
|
+
return {
|
749
|
+
location: preserveSymlinks ? location : await resolveSymlink(location),
|
750
|
+
hasModuleSideEffects,
|
751
|
+
hasPackageEntry,
|
752
|
+
packageBrowserField,
|
753
|
+
packageInfo
|
669
754
|
};
|
670
|
-
const resolvedPackageExport = await resolvePackageExports(
|
671
|
-
context,
|
672
|
-
subpath,
|
673
|
-
pkgJson.exports
|
674
|
-
);
|
675
|
-
location = url.fileURLToPath(resolvedPackageExport);
|
676
|
-
} catch (error) {
|
677
|
-
if (error instanceof ResolveError) {
|
678
|
-
return error;
|
679
|
-
}
|
680
|
-
throw error;
|
681
755
|
}
|
682
756
|
}
|
683
757
|
}
|
684
758
|
|
685
|
-
|
686
|
-
// package has no imports or exports, use classic node resolve
|
687
|
-
try {
|
688
|
-
location = await resolveImportPath(importSpecifier, resolveOptions);
|
689
|
-
} catch (error) {
|
690
|
-
if (error.code !== 'MODULE_NOT_FOUND') {
|
691
|
-
throw error;
|
692
|
-
}
|
693
|
-
return null;
|
694
|
-
}
|
695
|
-
}
|
696
|
-
|
697
|
-
if (!preserveSymlinks) {
|
698
|
-
if (await fileExists(location)) {
|
699
|
-
location = await realpath(location);
|
700
|
-
}
|
701
|
-
}
|
702
|
-
|
703
|
-
return {
|
704
|
-
location,
|
705
|
-
hasModuleSideEffects,
|
706
|
-
hasPackageEntry,
|
707
|
-
packageBrowserField,
|
708
|
-
packageInfo
|
709
|
-
};
|
759
|
+
return null;
|
710
760
|
}
|
711
761
|
|
712
|
-
|
713
|
-
// successfully, or the error that resulted from the last attempted module resolution.
|
714
|
-
async function resolveImportSpecifiers({
|
762
|
+
async function resolveWithClassic({
|
715
763
|
importer,
|
716
764
|
importSpecifierList,
|
717
765
|
exportConditions,
|
@@ -726,11 +774,9 @@ async function resolveImportSpecifiers({
|
|
726
774
|
rootDir,
|
727
775
|
ignoreSideEffectsForRoot
|
728
776
|
}) {
|
729
|
-
let lastResolveError;
|
730
|
-
|
731
777
|
for (let i = 0; i < importSpecifierList.length; i++) {
|
732
778
|
// eslint-disable-next-line no-await-in-loop
|
733
|
-
const result = await
|
779
|
+
const result = await resolveIdClassic({
|
734
780
|
importer,
|
735
781
|
importSpecifier: importSpecifierList[i],
|
736
782
|
exportConditions,
|
@@ -746,20 +792,75 @@ async function resolveImportSpecifiers({
|
|
746
792
|
ignoreSideEffectsForRoot
|
747
793
|
});
|
748
794
|
|
749
|
-
if (result
|
750
|
-
lastResolveError = result;
|
751
|
-
} else if (result) {
|
795
|
+
if (result) {
|
752
796
|
return result;
|
753
797
|
}
|
754
798
|
}
|
755
799
|
|
756
|
-
if (lastResolveError) {
|
757
|
-
// only log the last failed resolve error
|
758
|
-
warn(lastResolveError);
|
759
|
-
}
|
760
800
|
return null;
|
761
801
|
}
|
762
802
|
|
803
|
+
// Resolves to the module if found or `null`.
|
804
|
+
// The first import specificer will first be attempted with the exports algorithm.
|
805
|
+
// If this is unsuccesful because export maps are not being used, then all of `importSpecifierList`
|
806
|
+
// will be tried with the classic resolution algorithm
|
807
|
+
async function resolveImportSpecifiers({
|
808
|
+
importer,
|
809
|
+
importSpecifierList,
|
810
|
+
exportConditions,
|
811
|
+
warn,
|
812
|
+
packageInfoCache,
|
813
|
+
extensions,
|
814
|
+
mainFields,
|
815
|
+
preserveSymlinks,
|
816
|
+
useBrowserOverrides,
|
817
|
+
baseDir,
|
818
|
+
moduleDirectories,
|
819
|
+
rootDir,
|
820
|
+
ignoreSideEffectsForRoot
|
821
|
+
}) {
|
822
|
+
try {
|
823
|
+
const exportMapRes = await resolveWithExportMap({
|
824
|
+
importer,
|
825
|
+
importSpecifier: importSpecifierList[0],
|
826
|
+
exportConditions,
|
827
|
+
packageInfoCache,
|
828
|
+
extensions,
|
829
|
+
mainFields,
|
830
|
+
preserveSymlinks,
|
831
|
+
useBrowserOverrides,
|
832
|
+
baseDir,
|
833
|
+
moduleDirectories,
|
834
|
+
rootDir,
|
835
|
+
ignoreSideEffectsForRoot
|
836
|
+
});
|
837
|
+
if (exportMapRes) return exportMapRes;
|
838
|
+
} catch (error) {
|
839
|
+
if (error instanceof ResolveError) {
|
840
|
+
warn(error);
|
841
|
+
return null;
|
842
|
+
}
|
843
|
+
throw error;
|
844
|
+
}
|
845
|
+
|
846
|
+
// package has no imports or exports, use classic node resolve
|
847
|
+
return resolveWithClassic({
|
848
|
+
importer,
|
849
|
+
importSpecifierList,
|
850
|
+
exportConditions,
|
851
|
+
warn,
|
852
|
+
packageInfoCache,
|
853
|
+
extensions,
|
854
|
+
mainFields,
|
855
|
+
preserveSymlinks,
|
856
|
+
useBrowserOverrides,
|
857
|
+
baseDir,
|
858
|
+
moduleDirectories,
|
859
|
+
rootDir,
|
860
|
+
ignoreSideEffectsForRoot
|
861
|
+
});
|
862
|
+
}
|
863
|
+
|
763
864
|
function handleDeprecatedOptions(opts) {
|
764
865
|
const warnings = [];
|
765
866
|
|
@@ -919,30 +1020,17 @@ function nodeResolve(opts = {}) {
|
|
919
1020
|
return false;
|
920
1021
|
}
|
921
1022
|
|
922
|
-
const importSpecifierList = [];
|
1023
|
+
const importSpecifierList = [importee];
|
923
1024
|
|
924
1025
|
if (importer === undefined && !importee[0].match(/^\.?\.?\//)) {
|
925
1026
|
// For module graph roots (i.e. when importer is undefined), we
|
926
1027
|
// need to handle 'path fragments` like `foo/bar` that are commonly
|
927
1028
|
// found in rollup config files. If importee doesn't look like a
|
928
1029
|
// relative or absolute path, we make it relative and attempt to
|
929
|
-
// resolve it.
|
930
|
-
// got it.
|
1030
|
+
// resolve it.
|
931
1031
|
importSpecifierList.push(`./${importee}`);
|
932
1032
|
}
|
933
1033
|
|
934
|
-
const importeeIsBuiltin = builtins.has(importee);
|
935
|
-
|
936
|
-
if (importeeIsBuiltin) {
|
937
|
-
// The `resolve` library will not resolve packages with the same
|
938
|
-
// name as a node built-in module. If we're resolving something
|
939
|
-
// that's a builtin, and we don't prefer to find built-ins, we
|
940
|
-
// first try to look up a local module with that name. If we don't
|
941
|
-
// find anything, we resolve the builtin which just returns back
|
942
|
-
// the built-in's name.
|
943
|
-
importSpecifierList.push(`${importee}/`);
|
944
|
-
}
|
945
|
-
|
946
1034
|
// TypeScript files may import '.js' to refer to either '.ts' or '.tsx'
|
947
1035
|
if (importer && importee.endsWith('.js')) {
|
948
1036
|
for (const ext of ['.ts', '.tsx']) {
|
@@ -952,8 +1040,6 @@ function nodeResolve(opts = {}) {
|
|
952
1040
|
}
|
953
1041
|
}
|
954
1042
|
|
955
|
-
importSpecifierList.push(importee);
|
956
|
-
|
957
1043
|
const warn = (...args) => context.warn(...args);
|
958
1044
|
const isRequire =
|
959
1045
|
opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire;
|
@@ -978,6 +1064,7 @@ function nodeResolve(opts = {}) {
|
|
978
1064
|
ignoreSideEffectsForRoot
|
979
1065
|
});
|
980
1066
|
|
1067
|
+
const importeeIsBuiltin = builtins.has(importee);
|
981
1068
|
const resolved =
|
982
1069
|
importeeIsBuiltin && preferBuiltins
|
983
1070
|
? {
|
package/dist/es/index.js
CHANGED
@@ -22,6 +22,10 @@ async function fileExists(filePath) {
|
|
22
22
|
}
|
23
23
|
}
|
24
24
|
|
25
|
+
async function resolveSymlink(path) {
|
26
|
+
return (await fileExists(path)) ? realpath(path) : path;
|
27
|
+
}
|
28
|
+
|
25
29
|
const onError = (error) => {
|
26
30
|
if (error.code === 'ENOENT') {
|
27
31
|
return false;
|
@@ -299,8 +303,8 @@ class InvalidConfigurationError extends ResolveError {
|
|
299
303
|
}
|
300
304
|
|
301
305
|
class InvalidModuleSpecifierError extends ResolveError {
|
302
|
-
constructor(context, internal) {
|
303
|
-
super(createErrorMsg(context, internal));
|
306
|
+
constructor(context, internal, reason) {
|
307
|
+
super(createErrorMsg(context, reason, internal));
|
304
308
|
}
|
305
309
|
}
|
306
310
|
|
@@ -527,7 +531,7 @@ async function resolvePackageImports({
|
|
527
531
|
}
|
528
532
|
|
529
533
|
if (importSpecifier === '#' || importSpecifier.startsWith('#/')) {
|
530
|
-
throw new InvalidModuleSpecifierError(context, 'Invalid import specifier.');
|
534
|
+
throw new InvalidModuleSpecifierError(context, true, 'Invalid import specifier.');
|
531
535
|
}
|
532
536
|
|
533
537
|
return resolvePackageImportsExports(context, {
|
@@ -558,11 +562,8 @@ async function getPackageJson(importer, pkgName, resolveOptions, moduleDirectori
|
|
558
562
|
}
|
559
563
|
}
|
560
564
|
|
561
|
-
async function
|
562
|
-
importer,
|
565
|
+
async function resolveIdClassic({
|
563
566
|
importSpecifier,
|
564
|
-
exportConditions,
|
565
|
-
warn,
|
566
567
|
packageInfoCache,
|
567
568
|
extensions,
|
568
569
|
mainFields,
|
@@ -609,8 +610,38 @@ async function resolveId({
|
|
609
610
|
};
|
610
611
|
|
611
612
|
let location;
|
613
|
+
try {
|
614
|
+
location = await resolveImportPath(importSpecifier, resolveOptions);
|
615
|
+
} catch (error) {
|
616
|
+
if (error.code !== 'MODULE_NOT_FOUND') {
|
617
|
+
throw error;
|
618
|
+
}
|
619
|
+
return null;
|
620
|
+
}
|
612
621
|
|
613
|
-
|
622
|
+
return {
|
623
|
+
location: preserveSymlinks ? location : await resolveSymlink(location),
|
624
|
+
hasModuleSideEffects,
|
625
|
+
hasPackageEntry,
|
626
|
+
packageBrowserField,
|
627
|
+
packageInfo
|
628
|
+
};
|
629
|
+
}
|
630
|
+
|
631
|
+
async function resolveWithExportMap({
|
632
|
+
importer,
|
633
|
+
importSpecifier,
|
634
|
+
exportConditions,
|
635
|
+
packageInfoCache,
|
636
|
+
extensions,
|
637
|
+
mainFields,
|
638
|
+
preserveSymlinks,
|
639
|
+
useBrowserOverrides,
|
640
|
+
baseDir,
|
641
|
+
moduleDirectories,
|
642
|
+
rootDir,
|
643
|
+
ignoreSideEffectsForRoot
|
644
|
+
}) {
|
614
645
|
if (importSpecifier.startsWith('#')) {
|
615
646
|
// this is a package internal import, resolve using package imports field
|
616
647
|
const resolveResult = await resolvePackageImports({
|
@@ -618,12 +649,9 @@ async function resolveId({
|
|
618
649
|
importer,
|
619
650
|
moduleDirs: moduleDirectories,
|
620
651
|
conditions: exportConditions,
|
621
|
-
resolveId(id, parent) {
|
622
|
-
return
|
652
|
+
resolveId(id /* , parent*/) {
|
653
|
+
return resolveIdClassic({
|
623
654
|
importSpecifier: id,
|
624
|
-
importer: parent,
|
625
|
-
exportConditions,
|
626
|
-
warn,
|
627
655
|
packageInfoCache,
|
628
656
|
extensions,
|
629
657
|
mainFields,
|
@@ -634,71 +662,91 @@ async function resolveId({
|
|
634
662
|
});
|
635
663
|
}
|
636
664
|
});
|
637
|
-
|
638
|
-
|
665
|
+
|
666
|
+
const location = fileURLToPath(resolveResult);
|
667
|
+
return {
|
668
|
+
location: preserveSymlinks ? location : await resolveSymlink(location),
|
669
|
+
hasModuleSideEffects: () => null,
|
670
|
+
hasPackageEntry: true,
|
671
|
+
packageBrowserField: false,
|
672
|
+
// eslint-disable-next-line no-undefined
|
673
|
+
packageInfo: undefined
|
674
|
+
};
|
675
|
+
}
|
676
|
+
|
677
|
+
const pkgName = getPackageName(importSpecifier);
|
678
|
+
if (pkgName) {
|
639
679
|
// it's a bare import, find the package.json and resolve using package exports if available
|
680
|
+
let hasModuleSideEffects = () => null;
|
681
|
+
let hasPackageEntry = true;
|
682
|
+
let packageBrowserField = false;
|
683
|
+
let packageInfo;
|
684
|
+
|
685
|
+
const filter = (pkg, pkgPath) => {
|
686
|
+
const info = getPackageInfo({
|
687
|
+
cache: packageInfoCache,
|
688
|
+
extensions,
|
689
|
+
pkg,
|
690
|
+
pkgPath,
|
691
|
+
mainFields,
|
692
|
+
preserveSymlinks,
|
693
|
+
useBrowserOverrides,
|
694
|
+
rootDir,
|
695
|
+
ignoreSideEffectsForRoot
|
696
|
+
});
|
697
|
+
|
698
|
+
({ packageInfo, hasModuleSideEffects, hasPackageEntry, packageBrowserField } = info);
|
699
|
+
|
700
|
+
return info.cachedPkg;
|
701
|
+
};
|
702
|
+
|
703
|
+
const resolveOptions = {
|
704
|
+
basedir: baseDir,
|
705
|
+
readFile: readCachedFile,
|
706
|
+
isFile: isFileCached,
|
707
|
+
isDirectory: isDirCached,
|
708
|
+
extensions,
|
709
|
+
includeCoreModules: false,
|
710
|
+
moduleDirectory: moduleDirectories,
|
711
|
+
preserveSymlinks,
|
712
|
+
packageFilter: filter
|
713
|
+
};
|
714
|
+
|
640
715
|
const result = await getPackageJson(importer, pkgName, resolveOptions, moduleDirectories);
|
641
716
|
|
642
717
|
if (result && result.pkgJson.exports) {
|
643
|
-
const { pkgJson, pkgJsonPath
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
718
|
+
const { pkgJson, pkgJsonPath } = result;
|
719
|
+
const subpath =
|
720
|
+
pkgName === importSpecifier ? '.' : `.${importSpecifier.substring(pkgName.length)}`;
|
721
|
+
const pkgDr = pkgJsonPath.replace('package.json', '');
|
722
|
+
const pkgURL = pathToFileURL(pkgDr);
|
723
|
+
|
724
|
+
const context = {
|
725
|
+
importer,
|
726
|
+
importSpecifier,
|
727
|
+
moduleDirs: moduleDirectories,
|
728
|
+
pkgURL,
|
729
|
+
pkgJsonPath,
|
730
|
+
conditions: exportConditions
|
731
|
+
};
|
732
|
+
const resolvedPackageExport = await resolvePackageExports(context, subpath, pkgJson.exports);
|
733
|
+
const location = fileURLToPath(resolvedPackageExport);
|
734
|
+
if (location) {
|
735
|
+
return {
|
736
|
+
location: preserveSymlinks ? location : await resolveSymlink(location),
|
737
|
+
hasModuleSideEffects,
|
738
|
+
hasPackageEntry,
|
739
|
+
packageBrowserField,
|
740
|
+
packageInfo
|
656
741
|
};
|
657
|
-
const resolvedPackageExport = await resolvePackageExports(
|
658
|
-
context,
|
659
|
-
subpath,
|
660
|
-
pkgJson.exports
|
661
|
-
);
|
662
|
-
location = fileURLToPath(resolvedPackageExport);
|
663
|
-
} catch (error) {
|
664
|
-
if (error instanceof ResolveError) {
|
665
|
-
return error;
|
666
|
-
}
|
667
|
-
throw error;
|
668
742
|
}
|
669
743
|
}
|
670
744
|
}
|
671
745
|
|
672
|
-
|
673
|
-
// package has no imports or exports, use classic node resolve
|
674
|
-
try {
|
675
|
-
location = await resolveImportPath(importSpecifier, resolveOptions);
|
676
|
-
} catch (error) {
|
677
|
-
if (error.code !== 'MODULE_NOT_FOUND') {
|
678
|
-
throw error;
|
679
|
-
}
|
680
|
-
return null;
|
681
|
-
}
|
682
|
-
}
|
683
|
-
|
684
|
-
if (!preserveSymlinks) {
|
685
|
-
if (await fileExists(location)) {
|
686
|
-
location = await realpath(location);
|
687
|
-
}
|
688
|
-
}
|
689
|
-
|
690
|
-
return {
|
691
|
-
location,
|
692
|
-
hasModuleSideEffects,
|
693
|
-
hasPackageEntry,
|
694
|
-
packageBrowserField,
|
695
|
-
packageInfo
|
696
|
-
};
|
746
|
+
return null;
|
697
747
|
}
|
698
748
|
|
699
|
-
|
700
|
-
// successfully, or the error that resulted from the last attempted module resolution.
|
701
|
-
async function resolveImportSpecifiers({
|
749
|
+
async function resolveWithClassic({
|
702
750
|
importer,
|
703
751
|
importSpecifierList,
|
704
752
|
exportConditions,
|
@@ -713,11 +761,9 @@ async function resolveImportSpecifiers({
|
|
713
761
|
rootDir,
|
714
762
|
ignoreSideEffectsForRoot
|
715
763
|
}) {
|
716
|
-
let lastResolveError;
|
717
|
-
|
718
764
|
for (let i = 0; i < importSpecifierList.length; i++) {
|
719
765
|
// eslint-disable-next-line no-await-in-loop
|
720
|
-
const result = await
|
766
|
+
const result = await resolveIdClassic({
|
721
767
|
importer,
|
722
768
|
importSpecifier: importSpecifierList[i],
|
723
769
|
exportConditions,
|
@@ -733,20 +779,75 @@ async function resolveImportSpecifiers({
|
|
733
779
|
ignoreSideEffectsForRoot
|
734
780
|
});
|
735
781
|
|
736
|
-
if (result
|
737
|
-
lastResolveError = result;
|
738
|
-
} else if (result) {
|
782
|
+
if (result) {
|
739
783
|
return result;
|
740
784
|
}
|
741
785
|
}
|
742
786
|
|
743
|
-
if (lastResolveError) {
|
744
|
-
// only log the last failed resolve error
|
745
|
-
warn(lastResolveError);
|
746
|
-
}
|
747
787
|
return null;
|
748
788
|
}
|
749
789
|
|
790
|
+
// Resolves to the module if found or `null`.
|
791
|
+
// The first import specificer will first be attempted with the exports algorithm.
|
792
|
+
// If this is unsuccesful because export maps are not being used, then all of `importSpecifierList`
|
793
|
+
// will be tried with the classic resolution algorithm
|
794
|
+
async function resolveImportSpecifiers({
|
795
|
+
importer,
|
796
|
+
importSpecifierList,
|
797
|
+
exportConditions,
|
798
|
+
warn,
|
799
|
+
packageInfoCache,
|
800
|
+
extensions,
|
801
|
+
mainFields,
|
802
|
+
preserveSymlinks,
|
803
|
+
useBrowserOverrides,
|
804
|
+
baseDir,
|
805
|
+
moduleDirectories,
|
806
|
+
rootDir,
|
807
|
+
ignoreSideEffectsForRoot
|
808
|
+
}) {
|
809
|
+
try {
|
810
|
+
const exportMapRes = await resolveWithExportMap({
|
811
|
+
importer,
|
812
|
+
importSpecifier: importSpecifierList[0],
|
813
|
+
exportConditions,
|
814
|
+
packageInfoCache,
|
815
|
+
extensions,
|
816
|
+
mainFields,
|
817
|
+
preserveSymlinks,
|
818
|
+
useBrowserOverrides,
|
819
|
+
baseDir,
|
820
|
+
moduleDirectories,
|
821
|
+
rootDir,
|
822
|
+
ignoreSideEffectsForRoot
|
823
|
+
});
|
824
|
+
if (exportMapRes) return exportMapRes;
|
825
|
+
} catch (error) {
|
826
|
+
if (error instanceof ResolveError) {
|
827
|
+
warn(error);
|
828
|
+
return null;
|
829
|
+
}
|
830
|
+
throw error;
|
831
|
+
}
|
832
|
+
|
833
|
+
// package has no imports or exports, use classic node resolve
|
834
|
+
return resolveWithClassic({
|
835
|
+
importer,
|
836
|
+
importSpecifierList,
|
837
|
+
exportConditions,
|
838
|
+
warn,
|
839
|
+
packageInfoCache,
|
840
|
+
extensions,
|
841
|
+
mainFields,
|
842
|
+
preserveSymlinks,
|
843
|
+
useBrowserOverrides,
|
844
|
+
baseDir,
|
845
|
+
moduleDirectories,
|
846
|
+
rootDir,
|
847
|
+
ignoreSideEffectsForRoot
|
848
|
+
});
|
849
|
+
}
|
850
|
+
|
750
851
|
function handleDeprecatedOptions(opts) {
|
751
852
|
const warnings = [];
|
752
853
|
|
@@ -906,30 +1007,17 @@ function nodeResolve(opts = {}) {
|
|
906
1007
|
return false;
|
907
1008
|
}
|
908
1009
|
|
909
|
-
const importSpecifierList = [];
|
1010
|
+
const importSpecifierList = [importee];
|
910
1011
|
|
911
1012
|
if (importer === undefined && !importee[0].match(/^\.?\.?\//)) {
|
912
1013
|
// For module graph roots (i.e. when importer is undefined), we
|
913
1014
|
// need to handle 'path fragments` like `foo/bar` that are commonly
|
914
1015
|
// found in rollup config files. If importee doesn't look like a
|
915
1016
|
// relative or absolute path, we make it relative and attempt to
|
916
|
-
// resolve it.
|
917
|
-
// got it.
|
1017
|
+
// resolve it.
|
918
1018
|
importSpecifierList.push(`./${importee}`);
|
919
1019
|
}
|
920
1020
|
|
921
|
-
const importeeIsBuiltin = builtins.has(importee);
|
922
|
-
|
923
|
-
if (importeeIsBuiltin) {
|
924
|
-
// The `resolve` library will not resolve packages with the same
|
925
|
-
// name as a node built-in module. If we're resolving something
|
926
|
-
// that's a builtin, and we don't prefer to find built-ins, we
|
927
|
-
// first try to look up a local module with that name. If we don't
|
928
|
-
// find anything, we resolve the builtin which just returns back
|
929
|
-
// the built-in's name.
|
930
|
-
importSpecifierList.push(`${importee}/`);
|
931
|
-
}
|
932
|
-
|
933
1021
|
// TypeScript files may import '.js' to refer to either '.ts' or '.tsx'
|
934
1022
|
if (importer && importee.endsWith('.js')) {
|
935
1023
|
for (const ext of ['.ts', '.tsx']) {
|
@@ -939,8 +1027,6 @@ function nodeResolve(opts = {}) {
|
|
939
1027
|
}
|
940
1028
|
}
|
941
1029
|
|
942
|
-
importSpecifierList.push(importee);
|
943
|
-
|
944
1030
|
const warn = (...args) => context.warn(...args);
|
945
1031
|
const isRequire =
|
946
1032
|
opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire;
|
@@ -965,6 +1051,7 @@ function nodeResolve(opts = {}) {
|
|
965
1051
|
ignoreSideEffectsForRoot
|
966
1052
|
});
|
967
1053
|
|
1054
|
+
const importeeIsBuiltin = builtins.has(importee);
|
968
1055
|
const resolved =
|
969
1056
|
importeeIsBuiltin && preferBuiltins
|
970
1057
|
? {
|