@rollup/plugin-node-resolve 13.0.1 → 13.0.5
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 +32 -0
- package/README.md +1 -1
- package/dist/cjs/index.js +190 -105
- package/dist/es/index.js +190 -105
- package/package.json +9 -8
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,37 @@
|
|
1
1
|
# @rollup/plugin-node-resolve ChangeLog
|
2
2
|
|
3
|
+
## v13.0.5
|
4
|
+
|
5
|
+
_2021-09-21_
|
6
|
+
|
7
|
+
### Updates
|
8
|
+
|
9
|
+
- docs: fix readme heading depth (#999)
|
10
|
+
|
11
|
+
## v13.0.4
|
12
|
+
|
13
|
+
_2021-07-24_
|
14
|
+
|
15
|
+
### Bugfixes
|
16
|
+
|
17
|
+
- fix: Fix bug where JS import was converted to a TS import, resulting in an error when using export maps (#921)
|
18
|
+
|
19
|
+
## v13.0.3
|
20
|
+
|
21
|
+
_2021-07-24_
|
22
|
+
|
23
|
+
### Bugfixes
|
24
|
+
|
25
|
+
- fix: handle browser-mapped paths correctly in nested contexts (#920)
|
26
|
+
|
27
|
+
## v13.0.2
|
28
|
+
|
29
|
+
_2021-07-15_
|
30
|
+
|
31
|
+
### Bugfixes
|
32
|
+
|
33
|
+
- fix: handle "package.json" being in path (#927)
|
34
|
+
|
3
35
|
## v13.0.1
|
4
36
|
|
5
37
|
_2021-07-15_
|
package/README.md
CHANGED
@@ -159,7 +159,7 @@ Specifies the root directory from which to resolve modules. Typically used when
|
|
159
159
|
rootDir: path.join(process.cwd(), '..')
|
160
160
|
```
|
161
161
|
|
162
|
-
|
162
|
+
### `ignoreSideEffectsForRoot`
|
163
163
|
|
164
164
|
If you use the `sideEffects` property in the package.json, by default this is respected for files in the root package. Set to `true` to ignore the `sideEffects` configuration for the root package.
|
165
165
|
|
package/dist/cjs/index.js
CHANGED
@@ -21,19 +21,24 @@ var isModule__default = /*#__PURE__*/_interopDefaultLegacy(isModule);
|
|
21
21
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
22
22
|
var resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve);
|
23
23
|
|
24
|
-
|
24
|
+
util.promisify(fs__default['default'].access);
|
25
25
|
const readFile$1 = util.promisify(fs__default['default'].readFile);
|
26
26
|
const realpath = util.promisify(fs__default['default'].realpath);
|
27
27
|
const stat = util.promisify(fs__default['default'].stat);
|
28
|
-
|
28
|
+
|
29
|
+
async function fileExists(filePath) {
|
29
30
|
try {
|
30
|
-
await
|
31
|
-
return
|
31
|
+
const res = await stat(filePath);
|
32
|
+
return res.isFile();
|
32
33
|
} catch {
|
33
34
|
return false;
|
34
35
|
}
|
35
36
|
}
|
36
37
|
|
38
|
+
async function resolveSymlink(path) {
|
39
|
+
return (await fileExists(path)) ? realpath(path) : path;
|
40
|
+
}
|
41
|
+
|
37
42
|
const onError = (error) => {
|
38
43
|
if (error.code === 'ENOENT') {
|
39
44
|
return false;
|
@@ -251,8 +256,6 @@ function normalizeInput(input) {
|
|
251
256
|
|
252
257
|
/* eslint-disable no-await-in-loop */
|
253
258
|
|
254
|
-
const fileExists = util.promisify(fs__default['default'].exists);
|
255
|
-
|
256
259
|
function isModuleDir(current, moduleDirs) {
|
257
260
|
return moduleDirs.some((dir) => current.endsWith(dir));
|
258
261
|
}
|
@@ -313,8 +316,8 @@ class InvalidConfigurationError extends ResolveError {
|
|
313
316
|
}
|
314
317
|
|
315
318
|
class InvalidModuleSpecifierError extends ResolveError {
|
316
|
-
constructor(context, internal) {
|
317
|
-
super(createErrorMsg(context, internal));
|
319
|
+
constructor(context, internal, reason) {
|
320
|
+
super(createErrorMsg(context, reason, internal));
|
318
321
|
}
|
319
322
|
}
|
320
323
|
|
@@ -541,7 +544,7 @@ async function resolvePackageImports({
|
|
541
544
|
}
|
542
545
|
|
543
546
|
if (importSpecifier === '#' || importSpecifier.startsWith('#/')) {
|
544
|
-
throw new InvalidModuleSpecifierError(context, 'Invalid import specifier.');
|
547
|
+
throw new InvalidModuleSpecifierError(context, true, 'Invalid import specifier.');
|
545
548
|
}
|
546
549
|
|
547
550
|
return resolvePackageImportsExports(context, {
|
@@ -566,17 +569,14 @@ async function getPackageJson(importer, pkgName, resolveOptions, moduleDirectori
|
|
566
569
|
try {
|
567
570
|
const pkgJsonPath = await resolveImportPath(`${pkgName}/package.json`, resolveOptions);
|
568
571
|
const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf-8'));
|
569
|
-
return { pkgJsonPath, pkgJson };
|
572
|
+
return { pkgJsonPath, pkgJson, pkgPath: path.dirname(pkgJsonPath) };
|
570
573
|
} catch (_) {
|
571
574
|
return null;
|
572
575
|
}
|
573
576
|
}
|
574
577
|
|
575
|
-
async function
|
576
|
-
importer,
|
578
|
+
async function resolveIdClassic({
|
577
579
|
importSpecifier,
|
578
|
-
exportConditions,
|
579
|
-
warn,
|
580
580
|
packageInfoCache,
|
581
581
|
extensions,
|
582
582
|
mainFields,
|
@@ -623,8 +623,38 @@ async function resolveId({
|
|
623
623
|
};
|
624
624
|
|
625
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
|
+
}
|
626
634
|
|
627
|
-
|
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
|
+
}) {
|
628
658
|
if (importSpecifier.startsWith('#')) {
|
629
659
|
// this is a package internal import, resolve using package imports field
|
630
660
|
const resolveResult = await resolvePackageImports({
|
@@ -632,12 +662,9 @@ async function resolveId({
|
|
632
662
|
importer,
|
633
663
|
moduleDirs: moduleDirectories,
|
634
664
|
conditions: exportConditions,
|
635
|
-
resolveId(id, parent) {
|
636
|
-
return
|
665
|
+
resolveId(id /* , parent*/) {
|
666
|
+
return resolveIdClassic({
|
637
667
|
importSpecifier: id,
|
638
|
-
importer: parent,
|
639
|
-
exportConditions,
|
640
|
-
warn,
|
641
668
|
packageInfoCache,
|
642
669
|
extensions,
|
643
670
|
mainFields,
|
@@ -648,72 +675,91 @@ async function resolveId({
|
|
648
675
|
});
|
649
676
|
}
|
650
677
|
});
|
651
|
-
|
652
|
-
|
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) {
|
653
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
|
+
|
654
728
|
const result = await getPackageJson(importer, pkgName, resolveOptions, moduleDirectories);
|
655
729
|
|
656
730
|
if (result && result.pkgJson.exports) {
|
657
731
|
const { pkgJson, pkgJsonPath } = result;
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
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
|
671
754
|
};
|
672
|
-
const resolvedPackageExport = await resolvePackageExports(
|
673
|
-
context,
|
674
|
-
subpath,
|
675
|
-
pkgJson.exports
|
676
|
-
);
|
677
|
-
location = url.fileURLToPath(resolvedPackageExport);
|
678
|
-
} catch (error) {
|
679
|
-
if (error instanceof ResolveError) {
|
680
|
-
return error;
|
681
|
-
}
|
682
|
-
throw error;
|
683
755
|
}
|
684
756
|
}
|
685
757
|
}
|
686
758
|
|
687
|
-
|
688
|
-
// package has no imports or exports, use classic node resolve
|
689
|
-
try {
|
690
|
-
location = await resolveImportPath(importSpecifier, resolveOptions);
|
691
|
-
} catch (error) {
|
692
|
-
if (error.code !== 'MODULE_NOT_FOUND') {
|
693
|
-
throw error;
|
694
|
-
}
|
695
|
-
return null;
|
696
|
-
}
|
697
|
-
}
|
698
|
-
|
699
|
-
if (!preserveSymlinks) {
|
700
|
-
if (await exists(location)) {
|
701
|
-
location = await realpath(location);
|
702
|
-
}
|
703
|
-
}
|
704
|
-
|
705
|
-
return {
|
706
|
-
location,
|
707
|
-
hasModuleSideEffects,
|
708
|
-
hasPackageEntry,
|
709
|
-
packageBrowserField,
|
710
|
-
packageInfo
|
711
|
-
};
|
759
|
+
return null;
|
712
760
|
}
|
713
761
|
|
714
|
-
|
715
|
-
// successfully, or the error that resulted from the last attempted module resolution.
|
716
|
-
async function resolveImportSpecifiers({
|
762
|
+
async function resolveWithClassic({
|
717
763
|
importer,
|
718
764
|
importSpecifierList,
|
719
765
|
exportConditions,
|
@@ -728,11 +774,9 @@ async function resolveImportSpecifiers({
|
|
728
774
|
rootDir,
|
729
775
|
ignoreSideEffectsForRoot
|
730
776
|
}) {
|
731
|
-
let lastResolveError;
|
732
|
-
|
733
777
|
for (let i = 0; i < importSpecifierList.length; i++) {
|
734
778
|
// eslint-disable-next-line no-await-in-loop
|
735
|
-
const result = await
|
779
|
+
const result = await resolveIdClassic({
|
736
780
|
importer,
|
737
781
|
importSpecifier: importSpecifierList[i],
|
738
782
|
exportConditions,
|
@@ -748,20 +792,75 @@ async function resolveImportSpecifiers({
|
|
748
792
|
ignoreSideEffectsForRoot
|
749
793
|
});
|
750
794
|
|
751
|
-
if (result
|
752
|
-
lastResolveError = result;
|
753
|
-
} else if (result) {
|
795
|
+
if (result) {
|
754
796
|
return result;
|
755
797
|
}
|
756
798
|
}
|
757
799
|
|
758
|
-
if (lastResolveError) {
|
759
|
-
// only log the last failed resolve error
|
760
|
-
warn(lastResolveError);
|
761
|
-
}
|
762
800
|
return null;
|
763
801
|
}
|
764
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
|
+
|
765
864
|
function handleDeprecatedOptions(opts) {
|
766
865
|
const warnings = [];
|
767
866
|
|
@@ -888,7 +987,7 @@ function nodeResolve(opts = {}) {
|
|
888
987
|
return { id: ES6_BROWSER_EMPTY };
|
889
988
|
}
|
890
989
|
const browserImportee =
|
891
|
-
browser[importee] ||
|
990
|
+
(importee[0] !== '.' && browser[importee]) ||
|
892
991
|
browser[resolvedImportee] ||
|
893
992
|
browser[`${resolvedImportee}.js`] ||
|
894
993
|
browser[`${resolvedImportee}.json`];
|
@@ -921,30 +1020,17 @@ function nodeResolve(opts = {}) {
|
|
921
1020
|
return false;
|
922
1021
|
}
|
923
1022
|
|
924
|
-
const importSpecifierList = [];
|
1023
|
+
const importSpecifierList = [importee];
|
925
1024
|
|
926
1025
|
if (importer === undefined && !importee[0].match(/^\.?\.?\//)) {
|
927
1026
|
// For module graph roots (i.e. when importer is undefined), we
|
928
1027
|
// need to handle 'path fragments` like `foo/bar` that are commonly
|
929
1028
|
// found in rollup config files. If importee doesn't look like a
|
930
1029
|
// relative or absolute path, we make it relative and attempt to
|
931
|
-
// resolve it.
|
932
|
-
// got it.
|
1030
|
+
// resolve it.
|
933
1031
|
importSpecifierList.push(`./${importee}`);
|
934
1032
|
}
|
935
1033
|
|
936
|
-
const importeeIsBuiltin = builtins.has(importee);
|
937
|
-
|
938
|
-
if (importeeIsBuiltin) {
|
939
|
-
// The `resolve` library will not resolve packages with the same
|
940
|
-
// name as a node built-in module. If we're resolving something
|
941
|
-
// that's a builtin, and we don't prefer to find built-ins, we
|
942
|
-
// first try to look up a local module with that name. If we don't
|
943
|
-
// find anything, we resolve the builtin which just returns back
|
944
|
-
// the built-in's name.
|
945
|
-
importSpecifierList.push(`${importee}/`);
|
946
|
-
}
|
947
|
-
|
948
1034
|
// TypeScript files may import '.js' to refer to either '.ts' or '.tsx'
|
949
1035
|
if (importer && importee.endsWith('.js')) {
|
950
1036
|
for (const ext of ['.ts', '.tsx']) {
|
@@ -954,8 +1040,6 @@ function nodeResolve(opts = {}) {
|
|
954
1040
|
}
|
955
1041
|
}
|
956
1042
|
|
957
|
-
importSpecifierList.push(importee);
|
958
|
-
|
959
1043
|
const warn = (...args) => context.warn(...args);
|
960
1044
|
const isRequire =
|
961
1045
|
opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire;
|
@@ -980,6 +1064,7 @@ function nodeResolve(opts = {}) {
|
|
980
1064
|
ignoreSideEffectsForRoot
|
981
1065
|
});
|
982
1066
|
|
1067
|
+
const importeeIsBuiltin = builtins.has(importee);
|
983
1068
|
const resolved =
|
984
1069
|
importeeIsBuiltin && preferBuiltins
|
985
1070
|
? {
|
@@ -1007,8 +1092,8 @@ function nodeResolve(opts = {}) {
|
|
1007
1092
|
}
|
1008
1093
|
|
1009
1094
|
if (hasPackageEntry && !preserveSymlinks) {
|
1010
|
-
const
|
1011
|
-
if (
|
1095
|
+
const exists = await fileExists(location);
|
1096
|
+
if (exists) {
|
1012
1097
|
location = await realpath(location);
|
1013
1098
|
}
|
1014
1099
|
}
|
@@ -1028,7 +1113,7 @@ function nodeResolve(opts = {}) {
|
|
1028
1113
|
}
|
1029
1114
|
}
|
1030
1115
|
|
1031
|
-
if (options.modulesOnly && (await
|
1116
|
+
if (options.modulesOnly && (await fileExists(location))) {
|
1032
1117
|
const code = await readFile$1(location, 'utf-8');
|
1033
1118
|
if (isModule__default['default'](code)) {
|
1034
1119
|
return {
|
package/dist/es/index.js
CHANGED
@@ -8,19 +8,24 @@ import { pathToFileURL, fileURLToPath } from 'url';
|
|
8
8
|
import resolve$1 from 'resolve';
|
9
9
|
import { createFilter } from '@rollup/pluginutils';
|
10
10
|
|
11
|
-
|
11
|
+
promisify(fs.access);
|
12
12
|
const readFile$1 = promisify(fs.readFile);
|
13
13
|
const realpath = promisify(fs.realpath);
|
14
14
|
const stat = promisify(fs.stat);
|
15
|
-
|
15
|
+
|
16
|
+
async function fileExists(filePath) {
|
16
17
|
try {
|
17
|
-
await
|
18
|
-
return
|
18
|
+
const res = await stat(filePath);
|
19
|
+
return res.isFile();
|
19
20
|
} catch {
|
20
21
|
return false;
|
21
22
|
}
|
22
23
|
}
|
23
24
|
|
25
|
+
async function resolveSymlink(path) {
|
26
|
+
return (await fileExists(path)) ? realpath(path) : path;
|
27
|
+
}
|
28
|
+
|
24
29
|
const onError = (error) => {
|
25
30
|
if (error.code === 'ENOENT') {
|
26
31
|
return false;
|
@@ -238,8 +243,6 @@ function normalizeInput(input) {
|
|
238
243
|
|
239
244
|
/* eslint-disable no-await-in-loop */
|
240
245
|
|
241
|
-
const fileExists = promisify(fs.exists);
|
242
|
-
|
243
246
|
function isModuleDir(current, moduleDirs) {
|
244
247
|
return moduleDirs.some((dir) => current.endsWith(dir));
|
245
248
|
}
|
@@ -300,8 +303,8 @@ class InvalidConfigurationError extends ResolveError {
|
|
300
303
|
}
|
301
304
|
|
302
305
|
class InvalidModuleSpecifierError extends ResolveError {
|
303
|
-
constructor(context, internal) {
|
304
|
-
super(createErrorMsg(context, internal));
|
306
|
+
constructor(context, internal, reason) {
|
307
|
+
super(createErrorMsg(context, reason, internal));
|
305
308
|
}
|
306
309
|
}
|
307
310
|
|
@@ -528,7 +531,7 @@ async function resolvePackageImports({
|
|
528
531
|
}
|
529
532
|
|
530
533
|
if (importSpecifier === '#' || importSpecifier.startsWith('#/')) {
|
531
|
-
throw new InvalidModuleSpecifierError(context, 'Invalid import specifier.');
|
534
|
+
throw new InvalidModuleSpecifierError(context, true, 'Invalid import specifier.');
|
532
535
|
}
|
533
536
|
|
534
537
|
return resolvePackageImportsExports(context, {
|
@@ -553,17 +556,14 @@ async function getPackageJson(importer, pkgName, resolveOptions, moduleDirectori
|
|
553
556
|
try {
|
554
557
|
const pkgJsonPath = await resolveImportPath(`${pkgName}/package.json`, resolveOptions);
|
555
558
|
const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf-8'));
|
556
|
-
return { pkgJsonPath, pkgJson };
|
559
|
+
return { pkgJsonPath, pkgJson, pkgPath: dirname(pkgJsonPath) };
|
557
560
|
} catch (_) {
|
558
561
|
return null;
|
559
562
|
}
|
560
563
|
}
|
561
564
|
|
562
|
-
async function
|
563
|
-
importer,
|
565
|
+
async function resolveIdClassic({
|
564
566
|
importSpecifier,
|
565
|
-
exportConditions,
|
566
|
-
warn,
|
567
567
|
packageInfoCache,
|
568
568
|
extensions,
|
569
569
|
mainFields,
|
@@ -610,8 +610,38 @@ async function resolveId({
|
|
610
610
|
};
|
611
611
|
|
612
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
|
+
}
|
613
621
|
|
614
|
-
|
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
|
+
}) {
|
615
645
|
if (importSpecifier.startsWith('#')) {
|
616
646
|
// this is a package internal import, resolve using package imports field
|
617
647
|
const resolveResult = await resolvePackageImports({
|
@@ -619,12 +649,9 @@ async function resolveId({
|
|
619
649
|
importer,
|
620
650
|
moduleDirs: moduleDirectories,
|
621
651
|
conditions: exportConditions,
|
622
|
-
resolveId(id, parent) {
|
623
|
-
return
|
652
|
+
resolveId(id /* , parent*/) {
|
653
|
+
return resolveIdClassic({
|
624
654
|
importSpecifier: id,
|
625
|
-
importer: parent,
|
626
|
-
exportConditions,
|
627
|
-
warn,
|
628
655
|
packageInfoCache,
|
629
656
|
extensions,
|
630
657
|
mainFields,
|
@@ -635,72 +662,91 @@ async function resolveId({
|
|
635
662
|
});
|
636
663
|
}
|
637
664
|
});
|
638
|
-
|
639
|
-
|
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) {
|
640
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
|
+
|
641
715
|
const result = await getPackageJson(importer, pkgName, resolveOptions, moduleDirectories);
|
642
716
|
|
643
717
|
if (result && result.pkgJson.exports) {
|
644
718
|
const { pkgJson, pkgJsonPath } = result;
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
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
|
658
741
|
};
|
659
|
-
const resolvedPackageExport = await resolvePackageExports(
|
660
|
-
context,
|
661
|
-
subpath,
|
662
|
-
pkgJson.exports
|
663
|
-
);
|
664
|
-
location = fileURLToPath(resolvedPackageExport);
|
665
|
-
} catch (error) {
|
666
|
-
if (error instanceof ResolveError) {
|
667
|
-
return error;
|
668
|
-
}
|
669
|
-
throw error;
|
670
742
|
}
|
671
743
|
}
|
672
744
|
}
|
673
745
|
|
674
|
-
|
675
|
-
// package has no imports or exports, use classic node resolve
|
676
|
-
try {
|
677
|
-
location = await resolveImportPath(importSpecifier, resolveOptions);
|
678
|
-
} catch (error) {
|
679
|
-
if (error.code !== 'MODULE_NOT_FOUND') {
|
680
|
-
throw error;
|
681
|
-
}
|
682
|
-
return null;
|
683
|
-
}
|
684
|
-
}
|
685
|
-
|
686
|
-
if (!preserveSymlinks) {
|
687
|
-
if (await exists(location)) {
|
688
|
-
location = await realpath(location);
|
689
|
-
}
|
690
|
-
}
|
691
|
-
|
692
|
-
return {
|
693
|
-
location,
|
694
|
-
hasModuleSideEffects,
|
695
|
-
hasPackageEntry,
|
696
|
-
packageBrowserField,
|
697
|
-
packageInfo
|
698
|
-
};
|
746
|
+
return null;
|
699
747
|
}
|
700
748
|
|
701
|
-
|
702
|
-
// successfully, or the error that resulted from the last attempted module resolution.
|
703
|
-
async function resolveImportSpecifiers({
|
749
|
+
async function resolveWithClassic({
|
704
750
|
importer,
|
705
751
|
importSpecifierList,
|
706
752
|
exportConditions,
|
@@ -715,11 +761,9 @@ async function resolveImportSpecifiers({
|
|
715
761
|
rootDir,
|
716
762
|
ignoreSideEffectsForRoot
|
717
763
|
}) {
|
718
|
-
let lastResolveError;
|
719
|
-
|
720
764
|
for (let i = 0; i < importSpecifierList.length; i++) {
|
721
765
|
// eslint-disable-next-line no-await-in-loop
|
722
|
-
const result = await
|
766
|
+
const result = await resolveIdClassic({
|
723
767
|
importer,
|
724
768
|
importSpecifier: importSpecifierList[i],
|
725
769
|
exportConditions,
|
@@ -735,20 +779,75 @@ async function resolveImportSpecifiers({
|
|
735
779
|
ignoreSideEffectsForRoot
|
736
780
|
});
|
737
781
|
|
738
|
-
if (result
|
739
|
-
lastResolveError = result;
|
740
|
-
} else if (result) {
|
782
|
+
if (result) {
|
741
783
|
return result;
|
742
784
|
}
|
743
785
|
}
|
744
786
|
|
745
|
-
if (lastResolveError) {
|
746
|
-
// only log the last failed resolve error
|
747
|
-
warn(lastResolveError);
|
748
|
-
}
|
749
787
|
return null;
|
750
788
|
}
|
751
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
|
+
|
752
851
|
function handleDeprecatedOptions(opts) {
|
753
852
|
const warnings = [];
|
754
853
|
|
@@ -875,7 +974,7 @@ function nodeResolve(opts = {}) {
|
|
875
974
|
return { id: ES6_BROWSER_EMPTY };
|
876
975
|
}
|
877
976
|
const browserImportee =
|
878
|
-
browser[importee] ||
|
977
|
+
(importee[0] !== '.' && browser[importee]) ||
|
879
978
|
browser[resolvedImportee] ||
|
880
979
|
browser[`${resolvedImportee}.js`] ||
|
881
980
|
browser[`${resolvedImportee}.json`];
|
@@ -908,30 +1007,17 @@ function nodeResolve(opts = {}) {
|
|
908
1007
|
return false;
|
909
1008
|
}
|
910
1009
|
|
911
|
-
const importSpecifierList = [];
|
1010
|
+
const importSpecifierList = [importee];
|
912
1011
|
|
913
1012
|
if (importer === undefined && !importee[0].match(/^\.?\.?\//)) {
|
914
1013
|
// For module graph roots (i.e. when importer is undefined), we
|
915
1014
|
// need to handle 'path fragments` like `foo/bar` that are commonly
|
916
1015
|
// found in rollup config files. If importee doesn't look like a
|
917
1016
|
// relative or absolute path, we make it relative and attempt to
|
918
|
-
// resolve it.
|
919
|
-
// got it.
|
1017
|
+
// resolve it.
|
920
1018
|
importSpecifierList.push(`./${importee}`);
|
921
1019
|
}
|
922
1020
|
|
923
|
-
const importeeIsBuiltin = builtins.has(importee);
|
924
|
-
|
925
|
-
if (importeeIsBuiltin) {
|
926
|
-
// The `resolve` library will not resolve packages with the same
|
927
|
-
// name as a node built-in module. If we're resolving something
|
928
|
-
// that's a builtin, and we don't prefer to find built-ins, we
|
929
|
-
// first try to look up a local module with that name. If we don't
|
930
|
-
// find anything, we resolve the builtin which just returns back
|
931
|
-
// the built-in's name.
|
932
|
-
importSpecifierList.push(`${importee}/`);
|
933
|
-
}
|
934
|
-
|
935
1021
|
// TypeScript files may import '.js' to refer to either '.ts' or '.tsx'
|
936
1022
|
if (importer && importee.endsWith('.js')) {
|
937
1023
|
for (const ext of ['.ts', '.tsx']) {
|
@@ -941,8 +1027,6 @@ function nodeResolve(opts = {}) {
|
|
941
1027
|
}
|
942
1028
|
}
|
943
1029
|
|
944
|
-
importSpecifierList.push(importee);
|
945
|
-
|
946
1030
|
const warn = (...args) => context.warn(...args);
|
947
1031
|
const isRequire =
|
948
1032
|
opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire;
|
@@ -967,6 +1051,7 @@ function nodeResolve(opts = {}) {
|
|
967
1051
|
ignoreSideEffectsForRoot
|
968
1052
|
});
|
969
1053
|
|
1054
|
+
const importeeIsBuiltin = builtins.has(importee);
|
970
1055
|
const resolved =
|
971
1056
|
importeeIsBuiltin && preferBuiltins
|
972
1057
|
? {
|
@@ -994,8 +1079,8 @@ function nodeResolve(opts = {}) {
|
|
994
1079
|
}
|
995
1080
|
|
996
1081
|
if (hasPackageEntry && !preserveSymlinks) {
|
997
|
-
const
|
998
|
-
if (
|
1082
|
+
const exists = await fileExists(location);
|
1083
|
+
if (exists) {
|
999
1084
|
location = await realpath(location);
|
1000
1085
|
}
|
1001
1086
|
}
|
@@ -1015,7 +1100,7 @@ function nodeResolve(opts = {}) {
|
|
1015
1100
|
}
|
1016
1101
|
}
|
1017
1102
|
|
1018
|
-
if (options.modulesOnly && (await
|
1103
|
+
if (options.modulesOnly && (await fileExists(location))) {
|
1019
1104
|
const code = await readFile$1(location, 'utf-8');
|
1020
1105
|
if (isModule(code)) {
|
1021
1106
|
return {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rollup/plugin-node-resolve",
|
3
|
-
"version": "13.0.
|
3
|
+
"version": "13.0.5",
|
4
4
|
"publishConfig": {
|
5
5
|
"access": "public"
|
6
6
|
},
|
@@ -25,15 +25,16 @@
|
|
25
25
|
},
|
26
26
|
"scripts": {
|
27
27
|
"build": "rollup -c",
|
28
|
-
"ci:coverage": "nyc pnpm
|
29
|
-
"ci:lint": "pnpm
|
28
|
+
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
|
29
|
+
"ci:lint": "pnpm build && pnpm lint",
|
30
30
|
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
|
31
|
-
"ci:test": "pnpm
|
31
|
+
"ci:test": "pnpm test -- --verbose && pnpm test:ts",
|
32
32
|
"prebuild": "del-cli dist",
|
33
|
-
"prepare": "pnpm
|
34
|
-
"
|
35
|
-
"pretest": "pnpm
|
36
|
-
"
|
33
|
+
"prepare": "if [ ! -d 'dist' ]; then pnpm build; fi",
|
34
|
+
"prerelease": "pnpm build",
|
35
|
+
"pretest": "pnpm build",
|
36
|
+
"release": "pnpm plugin:release --workspace-root -- --pkg $npm_package_name",
|
37
|
+
"test": "ava && pnpm test:ts",
|
37
38
|
"test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
|
38
39
|
},
|
39
40
|
"files": [
|