@rollup/plugin-node-resolve 11.2.1 → 13.0.0
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 +24 -0
- package/README.md +1 -1
- package/dist/cjs/index.js +183 -168
- package/dist/es/index.js +183 -168
- package/package.json +8 -9
- package/types/index.d.ts +0 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# @rollup/plugin-node-resolve ChangeLog
|
2
2
|
|
3
|
+
## v13.0.0
|
4
|
+
|
5
|
+
_2021-05-04_
|
6
|
+
|
7
|
+
### Breaking Changes
|
8
|
+
|
9
|
+
- fix!: mark module as external if resolved module is external (#799)
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
- feat: Follow up to #843, refining exports and browser field interaction (#866)
|
14
|
+
|
15
|
+
## v12.0.0
|
16
|
+
|
17
|
+
_2021-05-04_
|
18
|
+
|
19
|
+
### Breaking Changes
|
20
|
+
|
21
|
+
- fix!: mark module as external if resolved module is external (#799)
|
22
|
+
|
23
|
+
### Features
|
24
|
+
|
25
|
+
- feat: Follow up to #843, refining exports and browser field interaction (#866)
|
26
|
+
|
3
27
|
## v11.2.1
|
4
28
|
|
5
29
|
_2021-03-26_
|
package/README.md
CHANGED
@@ -64,7 +64,7 @@ Setting this option will add extra conditions on top of the default conditions.
|
|
64
64
|
Type: `Boolean`<br>
|
65
65
|
Default: `false`
|
66
66
|
|
67
|
-
If `true`, instructs the plugin to use the
|
67
|
+
If `true`, instructs the plugin to use the browser module resolutions in `package.json` and adds `'browser'` to `exportConditions` if it is not present so browser conditionals in `exports` are applied. If `false`, any browser properties in package files will be ignored. Alternatively, a value of `'browser'` can be added to both the `mainFields` and `exportConditions` options, however this option takes precedence over `mainFields`.
|
68
68
|
|
69
69
|
> This option does not work when a package is using [package entrypoints](https://nodejs.org/api/packages.html#packages_package_entry_points)
|
70
70
|
|
package/dist/cjs/index.js
CHANGED
@@ -22,7 +22,7 @@ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
22
22
|
var resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve);
|
23
23
|
|
24
24
|
const access = util.promisify(fs__default['default'].access);
|
25
|
-
const readFile = util.promisify(fs__default['default'].readFile);
|
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
|
async function exists(filePath) {
|
@@ -86,7 +86,7 @@ const isFileCached = makeCache(async (file) => {
|
|
86
86
|
}
|
87
87
|
});
|
88
88
|
|
89
|
-
const readCachedFile = makeCache(readFile);
|
89
|
+
const readCachedFile = makeCache(readFile$1);
|
90
90
|
|
91
91
|
// returns the imported package name for bare module imports
|
92
92
|
function getPackageName(id) {
|
@@ -347,11 +347,11 @@ async function resolvePackageTarget(context, { target, subpath, pattern, interna
|
|
347
347
|
target.replace(/\*/g, subpath),
|
348
348
|
context.pkgURL.href
|
349
349
|
);
|
350
|
-
return result ? url.pathToFileURL(result.location) : null;
|
350
|
+
return result ? url.pathToFileURL(result.location).href : null;
|
351
351
|
}
|
352
352
|
|
353
353
|
const result = await context.resolveId(`${target}${subpath}`, context.pkgURL.href);
|
354
|
-
return result ? url.pathToFileURL(result.location) : null;
|
354
|
+
return result ? url.pathToFileURL(result.location).href : null;
|
355
355
|
}
|
356
356
|
throw new InvalidPackageTargetError(context, `Invalid mapping: "${target}".`);
|
357
357
|
}
|
@@ -552,7 +552,7 @@ async function resolvePackageImports({
|
|
552
552
|
}
|
553
553
|
|
554
554
|
const resolveImportPath = util.promisify(resolve__default['default']);
|
555
|
-
const readFile
|
555
|
+
const readFile = util.promisify(fs__default['default'].readFile);
|
556
556
|
|
557
557
|
async function getPackageJson(importer, pkgName, resolveOptions, moduleDirectories) {
|
558
558
|
if (importer) {
|
@@ -565,7 +565,7 @@ async function getPackageJson(importer, pkgName, resolveOptions, moduleDirectori
|
|
565
565
|
|
566
566
|
try {
|
567
567
|
const pkgJsonPath = await resolveImportPath(`${pkgName}/package.json`, resolveOptions);
|
568
|
-
const pkgJson = JSON.parse(await readFile
|
568
|
+
const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf-8'));
|
569
569
|
return { pkgJsonPath, pkgJson };
|
570
570
|
} catch (_) {
|
571
571
|
return null;
|
@@ -872,203 +872,218 @@ function nodeResolve(opts = {}) {
|
|
872
872
|
const browserMapCache = new Map();
|
873
873
|
let preserveSymlinks;
|
874
874
|
|
875
|
-
|
876
|
-
|
875
|
+
const doResolveId = async (context, importee, importer, opts) => {
|
876
|
+
// strip query params from import
|
877
|
+
const [importPath, params] = importee.split('?');
|
878
|
+
const importSuffix = `${params ? `?${params}` : ''}`;
|
879
|
+
importee = importPath;
|
877
880
|
|
878
|
-
|
879
|
-
rollupOptions = options;
|
881
|
+
const baseDir = !importer || dedupe(importee) ? rootDir : path.dirname(importer);
|
880
882
|
|
881
|
-
|
882
|
-
|
883
|
+
// https://github.com/defunctzombie/package-browser-field-spec
|
884
|
+
const browser = browserMapCache.get(importer);
|
885
|
+
if (useBrowserOverrides && browser) {
|
886
|
+
const resolvedImportee = path.resolve(baseDir, importee);
|
887
|
+
if (browser[importee] === false || browser[resolvedImportee] === false) {
|
888
|
+
return { id: ES6_BROWSER_EMPTY };
|
883
889
|
}
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
isDirCached.clear();
|
892
|
-
},
|
893
|
-
|
894
|
-
async resolveId(importee, importer, opts) {
|
895
|
-
if (importee === ES6_BROWSER_EMPTY) {
|
896
|
-
return importee;
|
890
|
+
const browserImportee =
|
891
|
+
browser[importee] ||
|
892
|
+
browser[resolvedImportee] ||
|
893
|
+
browser[`${resolvedImportee}.js`] ||
|
894
|
+
browser[`${resolvedImportee}.json`];
|
895
|
+
if (browserImportee) {
|
896
|
+
importee = browserImportee;
|
897
897
|
}
|
898
|
-
|
899
|
-
if (/\0/.test(importee)) return null;
|
898
|
+
}
|
900
899
|
|
901
|
-
|
902
|
-
|
900
|
+
const parts = importee.split(/[/\\]/);
|
901
|
+
let id = parts.shift();
|
902
|
+
let isRelativeImport = false;
|
903
|
+
|
904
|
+
if (id[0] === '@' && parts.length > 0) {
|
905
|
+
// scoped packages
|
906
|
+
id += `/${parts.shift()}`;
|
907
|
+
} else if (id[0] === '.') {
|
908
|
+
// an import relative to the parent dir of the importer
|
909
|
+
id = path.resolve(baseDir, importee);
|
910
|
+
isRelativeImport = true;
|
911
|
+
}
|
912
|
+
|
913
|
+
if (
|
914
|
+
!isRelativeImport &&
|
915
|
+
resolveOnly.length &&
|
916
|
+
!resolveOnly.some((pattern) => pattern.test(id))
|
917
|
+
) {
|
918
|
+
if (normalizeInput(rollupOptions.input).includes(importee)) {
|
919
|
+
return null;
|
903
920
|
}
|
921
|
+
return false;
|
922
|
+
}
|
904
923
|
|
905
|
-
|
906
|
-
const [importPath, params] = importee.split('?');
|
907
|
-
const importSuffix = `${params ? `?${params}` : ''}`;
|
908
|
-
importee = importPath;
|
924
|
+
const importSpecifierList = [];
|
909
925
|
|
910
|
-
|
926
|
+
if (importer === undefined && !importee[0].match(/^\.?\.?\//)) {
|
927
|
+
// For module graph roots (i.e. when importer is undefined), we
|
928
|
+
// need to handle 'path fragments` like `foo/bar` that are commonly
|
929
|
+
// found in rollup config files. If importee doesn't look like a
|
930
|
+
// relative or absolute path, we make it relative and attempt to
|
931
|
+
// resolve it. If we don't find anything, we try resolving it as we
|
932
|
+
// got it.
|
933
|
+
importSpecifierList.push(`./${importee}`);
|
934
|
+
}
|
911
935
|
|
912
|
-
|
913
|
-
const browser = browserMapCache.get(importer);
|
914
|
-
if (useBrowserOverrides && browser) {
|
915
|
-
const resolvedImportee = path.resolve(baseDir, importee);
|
916
|
-
if (browser[importee] === false || browser[resolvedImportee] === false) {
|
917
|
-
return ES6_BROWSER_EMPTY;
|
918
|
-
}
|
919
|
-
const browserImportee =
|
920
|
-
browser[importee] ||
|
921
|
-
browser[resolvedImportee] ||
|
922
|
-
browser[`${resolvedImportee}.js`] ||
|
923
|
-
browser[`${resolvedImportee}.json`];
|
924
|
-
if (browserImportee) {
|
925
|
-
importee = browserImportee;
|
926
|
-
}
|
927
|
-
}
|
936
|
+
const importeeIsBuiltin = builtins.has(importee);
|
928
937
|
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
}
|
937
|
-
|
938
|
-
id = path.resolve(baseDir, importee);
|
939
|
-
isRelativeImport = true;
|
940
|
-
}
|
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
|
+
}
|
941
947
|
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
if (normalizeInput(rollupOptions.input).includes(importee)) {
|
948
|
-
return null;
|
948
|
+
// TypeScript files may import '.js' to refer to either '.ts' or '.tsx'
|
949
|
+
if (importer && importee.endsWith('.js')) {
|
950
|
+
for (const ext of ['.ts', '.tsx']) {
|
951
|
+
if (importer.endsWith(ext) && extensions.includes(ext)) {
|
952
|
+
importSpecifierList.push(importee.replace(/.js$/, ext));
|
949
953
|
}
|
950
|
-
return false;
|
951
954
|
}
|
955
|
+
}
|
952
956
|
|
953
|
-
|
957
|
+
importSpecifierList.push(importee);
|
954
958
|
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
// relative or absolute path, we make it relative and attempt to
|
960
|
-
// resolve it. If we don't find anything, we try resolving it as we
|
961
|
-
// got it.
|
962
|
-
importSpecifierList.push(`./${importee}`);
|
963
|
-
}
|
959
|
+
const warn = (...args) => context.warn(...args);
|
960
|
+
const isRequire =
|
961
|
+
opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire;
|
962
|
+
const exportConditions = isRequire ? conditionsCjs : conditionsEsm;
|
964
963
|
|
965
|
-
|
964
|
+
if (useBrowserOverrides && !exportConditions.includes('browser'))
|
965
|
+
exportConditions.push('browser');
|
966
966
|
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
967
|
+
const resolvedWithoutBuiltins = await resolveImportSpecifiers({
|
968
|
+
importer,
|
969
|
+
importSpecifierList,
|
970
|
+
exportConditions,
|
971
|
+
warn,
|
972
|
+
packageInfoCache,
|
973
|
+
extensions,
|
974
|
+
mainFields,
|
975
|
+
preserveSymlinks,
|
976
|
+
useBrowserOverrides,
|
977
|
+
baseDir,
|
978
|
+
moduleDirectories,
|
979
|
+
rootDir,
|
980
|
+
ignoreSideEffectsForRoot
|
981
|
+
});
|
976
982
|
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
983
|
+
const resolved =
|
984
|
+
importeeIsBuiltin && preferBuiltins
|
985
|
+
? {
|
986
|
+
packageInfo: undefined,
|
987
|
+
hasModuleSideEffects: () => null,
|
988
|
+
hasPackageEntry: true,
|
989
|
+
packageBrowserField: false
|
982
990
|
}
|
991
|
+
: resolvedWithoutBuiltins;
|
992
|
+
if (!resolved) {
|
993
|
+
return null;
|
994
|
+
}
|
995
|
+
|
996
|
+
const { packageInfo, hasModuleSideEffects, hasPackageEntry, packageBrowserField } = resolved;
|
997
|
+
let { location } = resolved;
|
998
|
+
if (packageBrowserField) {
|
999
|
+
if (Object.prototype.hasOwnProperty.call(packageBrowserField, location)) {
|
1000
|
+
if (!packageBrowserField[location]) {
|
1001
|
+
browserMapCache.set(location, packageBrowserField);
|
1002
|
+
return { id: ES6_BROWSER_EMPTY };
|
983
1003
|
}
|
1004
|
+
location = packageBrowserField[location];
|
984
1005
|
}
|
1006
|
+
browserMapCache.set(location, packageBrowserField);
|
1007
|
+
}
|
985
1008
|
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
importer,
|
995
|
-
importSpecifierList,
|
996
|
-
exportConditions,
|
997
|
-
warn,
|
998
|
-
packageInfoCache,
|
999
|
-
extensions,
|
1000
|
-
mainFields,
|
1001
|
-
preserveSymlinks,
|
1002
|
-
useBrowserOverrides,
|
1003
|
-
baseDir,
|
1004
|
-
moduleDirectories,
|
1005
|
-
rootDir,
|
1006
|
-
ignoreSideEffectsForRoot
|
1007
|
-
});
|
1009
|
+
if (hasPackageEntry && !preserveSymlinks) {
|
1010
|
+
const fileExists = await exists(location);
|
1011
|
+
if (fileExists) {
|
1012
|
+
location = await realpath(location);
|
1013
|
+
}
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
idToPackageInfo.set(location, packageInfo);
|
1008
1017
|
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
if (!resolved) {
|
1018
|
+
if (hasPackageEntry) {
|
1019
|
+
if (importeeIsBuiltin && preferBuiltins) {
|
1020
|
+
if (!isPreferBuiltinsSet && resolvedWithoutBuiltins && resolved !== importee) {
|
1021
|
+
context.warn(
|
1022
|
+
`preferring built-in module '${importee}' over local alternative at '${resolvedWithoutBuiltins.location}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning`
|
1023
|
+
);
|
1024
|
+
}
|
1025
|
+
return false;
|
1026
|
+
} else if (jail && location.indexOf(path.normalize(jail.trim(path.sep))) !== 0) {
|
1019
1027
|
return null;
|
1020
1028
|
}
|
1029
|
+
}
|
1021
1030
|
|
1022
|
-
|
1023
|
-
|
1024
|
-
if (
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
}
|
1030
|
-
location = packageBrowserField[location];
|
1031
|
-
}
|
1032
|
-
browserMapCache.set(location, packageBrowserField);
|
1031
|
+
if (options.modulesOnly && (await exists(location))) {
|
1032
|
+
const code = await readFile$1(location, 'utf-8');
|
1033
|
+
if (isModule__default['default'](code)) {
|
1034
|
+
return {
|
1035
|
+
id: `${location}${importSuffix}`,
|
1036
|
+
moduleSideEffects: hasModuleSideEffects(location)
|
1037
|
+
};
|
1033
1038
|
}
|
1039
|
+
return null;
|
1040
|
+
}
|
1041
|
+
const result = {
|
1042
|
+
id: `${location}${importSuffix}`,
|
1043
|
+
moduleSideEffects: hasModuleSideEffects(location)
|
1044
|
+
};
|
1045
|
+
return result;
|
1046
|
+
};
|
1034
1047
|
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1048
|
+
return {
|
1049
|
+
name: 'node-resolve',
|
1050
|
+
|
1051
|
+
buildStart(options) {
|
1052
|
+
rollupOptions = options;
|
1053
|
+
|
1054
|
+
for (const warning of warnings) {
|
1055
|
+
this.warn(warning);
|
1040
1056
|
}
|
1041
1057
|
|
1042
|
-
|
1058
|
+
({ preserveSymlinks } = options);
|
1059
|
+
},
|
1043
1060
|
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
return null;
|
1054
|
-
}
|
1061
|
+
generateBundle() {
|
1062
|
+
readCachedFile.clear();
|
1063
|
+
isFileCached.clear();
|
1064
|
+
isDirCached.clear();
|
1065
|
+
},
|
1066
|
+
|
1067
|
+
async resolveId(importee, importer, opts) {
|
1068
|
+
if (importee === ES6_BROWSER_EMPTY) {
|
1069
|
+
return importee;
|
1055
1070
|
}
|
1071
|
+
// ignore IDs with null character, these belong to other plugins
|
1072
|
+
if (/\0/.test(importee)) return null;
|
1056
1073
|
|
1057
|
-
if (
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1074
|
+
if (/\0/.test(importer)) {
|
1075
|
+
importer = undefined;
|
1076
|
+
}
|
1077
|
+
|
1078
|
+
const resolved = await doResolveId(this, importee, importer, opts);
|
1079
|
+
if (resolved) {
|
1080
|
+
const resolvedResolved = await this.resolve(resolved.id, importer, { skipSelf: true });
|
1081
|
+
const isExternal = !!(resolvedResolved && resolvedResolved.external);
|
1082
|
+
if (isExternal) {
|
1083
|
+
return false;
|
1064
1084
|
}
|
1065
|
-
return null;
|
1066
1085
|
}
|
1067
|
-
|
1068
|
-
id: `${location}${importSuffix}`,
|
1069
|
-
moduleSideEffects: hasModuleSideEffects(location)
|
1070
|
-
};
|
1071
|
-
return result;
|
1086
|
+
return resolved;
|
1072
1087
|
},
|
1073
1088
|
|
1074
1089
|
load(importee) {
|
package/dist/es/index.js
CHANGED
@@ -9,7 +9,7 @@ import resolve$1 from 'resolve';
|
|
9
9
|
import { createFilter } from '@rollup/pluginutils';
|
10
10
|
|
11
11
|
const access = promisify(fs.access);
|
12
|
-
const readFile = promisify(fs.readFile);
|
12
|
+
const readFile$1 = promisify(fs.readFile);
|
13
13
|
const realpath = promisify(fs.realpath);
|
14
14
|
const stat = promisify(fs.stat);
|
15
15
|
async function exists(filePath) {
|
@@ -73,7 +73,7 @@ const isFileCached = makeCache(async (file) => {
|
|
73
73
|
}
|
74
74
|
});
|
75
75
|
|
76
|
-
const readCachedFile = makeCache(readFile);
|
76
|
+
const readCachedFile = makeCache(readFile$1);
|
77
77
|
|
78
78
|
// returns the imported package name for bare module imports
|
79
79
|
function getPackageName(id) {
|
@@ -334,11 +334,11 @@ async function resolvePackageTarget(context, { target, subpath, pattern, interna
|
|
334
334
|
target.replace(/\*/g, subpath),
|
335
335
|
context.pkgURL.href
|
336
336
|
);
|
337
|
-
return result ? pathToFileURL(result.location) : null;
|
337
|
+
return result ? pathToFileURL(result.location).href : null;
|
338
338
|
}
|
339
339
|
|
340
340
|
const result = await context.resolveId(`${target}${subpath}`, context.pkgURL.href);
|
341
|
-
return result ? pathToFileURL(result.location) : null;
|
341
|
+
return result ? pathToFileURL(result.location).href : null;
|
342
342
|
}
|
343
343
|
throw new InvalidPackageTargetError(context, `Invalid mapping: "${target}".`);
|
344
344
|
}
|
@@ -539,7 +539,7 @@ async function resolvePackageImports({
|
|
539
539
|
}
|
540
540
|
|
541
541
|
const resolveImportPath = promisify(resolve$1);
|
542
|
-
const readFile
|
542
|
+
const readFile = promisify(fs.readFile);
|
543
543
|
|
544
544
|
async function getPackageJson(importer, pkgName, resolveOptions, moduleDirectories) {
|
545
545
|
if (importer) {
|
@@ -552,7 +552,7 @@ async function getPackageJson(importer, pkgName, resolveOptions, moduleDirectori
|
|
552
552
|
|
553
553
|
try {
|
554
554
|
const pkgJsonPath = await resolveImportPath(`${pkgName}/package.json`, resolveOptions);
|
555
|
-
const pkgJson = JSON.parse(await readFile
|
555
|
+
const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf-8'));
|
556
556
|
return { pkgJsonPath, pkgJson };
|
557
557
|
} catch (_) {
|
558
558
|
return null;
|
@@ -859,203 +859,218 @@ function nodeResolve(opts = {}) {
|
|
859
859
|
const browserMapCache = new Map();
|
860
860
|
let preserveSymlinks;
|
861
861
|
|
862
|
-
|
863
|
-
|
862
|
+
const doResolveId = async (context, importee, importer, opts) => {
|
863
|
+
// strip query params from import
|
864
|
+
const [importPath, params] = importee.split('?');
|
865
|
+
const importSuffix = `${params ? `?${params}` : ''}`;
|
866
|
+
importee = importPath;
|
864
867
|
|
865
|
-
|
866
|
-
rollupOptions = options;
|
868
|
+
const baseDir = !importer || dedupe(importee) ? rootDir : dirname(importer);
|
867
869
|
|
868
|
-
|
869
|
-
|
870
|
+
// https://github.com/defunctzombie/package-browser-field-spec
|
871
|
+
const browser = browserMapCache.get(importer);
|
872
|
+
if (useBrowserOverrides && browser) {
|
873
|
+
const resolvedImportee = resolve(baseDir, importee);
|
874
|
+
if (browser[importee] === false || browser[resolvedImportee] === false) {
|
875
|
+
return { id: ES6_BROWSER_EMPTY };
|
870
876
|
}
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
isDirCached.clear();
|
879
|
-
},
|
880
|
-
|
881
|
-
async resolveId(importee, importer, opts) {
|
882
|
-
if (importee === ES6_BROWSER_EMPTY) {
|
883
|
-
return importee;
|
877
|
+
const browserImportee =
|
878
|
+
browser[importee] ||
|
879
|
+
browser[resolvedImportee] ||
|
880
|
+
browser[`${resolvedImportee}.js`] ||
|
881
|
+
browser[`${resolvedImportee}.json`];
|
882
|
+
if (browserImportee) {
|
883
|
+
importee = browserImportee;
|
884
884
|
}
|
885
|
-
|
886
|
-
if (/\0/.test(importee)) return null;
|
885
|
+
}
|
887
886
|
|
888
|
-
|
889
|
-
|
887
|
+
const parts = importee.split(/[/\\]/);
|
888
|
+
let id = parts.shift();
|
889
|
+
let isRelativeImport = false;
|
890
|
+
|
891
|
+
if (id[0] === '@' && parts.length > 0) {
|
892
|
+
// scoped packages
|
893
|
+
id += `/${parts.shift()}`;
|
894
|
+
} else if (id[0] === '.') {
|
895
|
+
// an import relative to the parent dir of the importer
|
896
|
+
id = resolve(baseDir, importee);
|
897
|
+
isRelativeImport = true;
|
898
|
+
}
|
899
|
+
|
900
|
+
if (
|
901
|
+
!isRelativeImport &&
|
902
|
+
resolveOnly.length &&
|
903
|
+
!resolveOnly.some((pattern) => pattern.test(id))
|
904
|
+
) {
|
905
|
+
if (normalizeInput(rollupOptions.input).includes(importee)) {
|
906
|
+
return null;
|
890
907
|
}
|
908
|
+
return false;
|
909
|
+
}
|
891
910
|
|
892
|
-
|
893
|
-
const [importPath, params] = importee.split('?');
|
894
|
-
const importSuffix = `${params ? `?${params}` : ''}`;
|
895
|
-
importee = importPath;
|
911
|
+
const importSpecifierList = [];
|
896
912
|
|
897
|
-
|
913
|
+
if (importer === undefined && !importee[0].match(/^\.?\.?\//)) {
|
914
|
+
// For module graph roots (i.e. when importer is undefined), we
|
915
|
+
// need to handle 'path fragments` like `foo/bar` that are commonly
|
916
|
+
// found in rollup config files. If importee doesn't look like a
|
917
|
+
// relative or absolute path, we make it relative and attempt to
|
918
|
+
// resolve it. If we don't find anything, we try resolving it as we
|
919
|
+
// got it.
|
920
|
+
importSpecifierList.push(`./${importee}`);
|
921
|
+
}
|
898
922
|
|
899
|
-
|
900
|
-
const browser = browserMapCache.get(importer);
|
901
|
-
if (useBrowserOverrides && browser) {
|
902
|
-
const resolvedImportee = resolve(baseDir, importee);
|
903
|
-
if (browser[importee] === false || browser[resolvedImportee] === false) {
|
904
|
-
return ES6_BROWSER_EMPTY;
|
905
|
-
}
|
906
|
-
const browserImportee =
|
907
|
-
browser[importee] ||
|
908
|
-
browser[resolvedImportee] ||
|
909
|
-
browser[`${resolvedImportee}.js`] ||
|
910
|
-
browser[`${resolvedImportee}.json`];
|
911
|
-
if (browserImportee) {
|
912
|
-
importee = browserImportee;
|
913
|
-
}
|
914
|
-
}
|
923
|
+
const importeeIsBuiltin = builtins.has(importee);
|
915
924
|
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
}
|
924
|
-
|
925
|
-
id = resolve(baseDir, importee);
|
926
|
-
isRelativeImport = true;
|
927
|
-
}
|
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
|
+
}
|
928
934
|
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
if (normalizeInput(rollupOptions.input).includes(importee)) {
|
935
|
-
return null;
|
935
|
+
// TypeScript files may import '.js' to refer to either '.ts' or '.tsx'
|
936
|
+
if (importer && importee.endsWith('.js')) {
|
937
|
+
for (const ext of ['.ts', '.tsx']) {
|
938
|
+
if (importer.endsWith(ext) && extensions.includes(ext)) {
|
939
|
+
importSpecifierList.push(importee.replace(/.js$/, ext));
|
936
940
|
}
|
937
|
-
return false;
|
938
941
|
}
|
942
|
+
}
|
939
943
|
|
940
|
-
|
944
|
+
importSpecifierList.push(importee);
|
941
945
|
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
// relative or absolute path, we make it relative and attempt to
|
947
|
-
// resolve it. If we don't find anything, we try resolving it as we
|
948
|
-
// got it.
|
949
|
-
importSpecifierList.push(`./${importee}`);
|
950
|
-
}
|
946
|
+
const warn = (...args) => context.warn(...args);
|
947
|
+
const isRequire =
|
948
|
+
opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire;
|
949
|
+
const exportConditions = isRequire ? conditionsCjs : conditionsEsm;
|
951
950
|
|
952
|
-
|
951
|
+
if (useBrowserOverrides && !exportConditions.includes('browser'))
|
952
|
+
exportConditions.push('browser');
|
953
953
|
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
954
|
+
const resolvedWithoutBuiltins = await resolveImportSpecifiers({
|
955
|
+
importer,
|
956
|
+
importSpecifierList,
|
957
|
+
exportConditions,
|
958
|
+
warn,
|
959
|
+
packageInfoCache,
|
960
|
+
extensions,
|
961
|
+
mainFields,
|
962
|
+
preserveSymlinks,
|
963
|
+
useBrowserOverrides,
|
964
|
+
baseDir,
|
965
|
+
moduleDirectories,
|
966
|
+
rootDir,
|
967
|
+
ignoreSideEffectsForRoot
|
968
|
+
});
|
963
969
|
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
970
|
+
const resolved =
|
971
|
+
importeeIsBuiltin && preferBuiltins
|
972
|
+
? {
|
973
|
+
packageInfo: undefined,
|
974
|
+
hasModuleSideEffects: () => null,
|
975
|
+
hasPackageEntry: true,
|
976
|
+
packageBrowserField: false
|
969
977
|
}
|
978
|
+
: resolvedWithoutBuiltins;
|
979
|
+
if (!resolved) {
|
980
|
+
return null;
|
981
|
+
}
|
982
|
+
|
983
|
+
const { packageInfo, hasModuleSideEffects, hasPackageEntry, packageBrowserField } = resolved;
|
984
|
+
let { location } = resolved;
|
985
|
+
if (packageBrowserField) {
|
986
|
+
if (Object.prototype.hasOwnProperty.call(packageBrowserField, location)) {
|
987
|
+
if (!packageBrowserField[location]) {
|
988
|
+
browserMapCache.set(location, packageBrowserField);
|
989
|
+
return { id: ES6_BROWSER_EMPTY };
|
970
990
|
}
|
991
|
+
location = packageBrowserField[location];
|
971
992
|
}
|
993
|
+
browserMapCache.set(location, packageBrowserField);
|
994
|
+
}
|
972
995
|
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
importer,
|
982
|
-
importSpecifierList,
|
983
|
-
exportConditions,
|
984
|
-
warn,
|
985
|
-
packageInfoCache,
|
986
|
-
extensions,
|
987
|
-
mainFields,
|
988
|
-
preserveSymlinks,
|
989
|
-
useBrowserOverrides,
|
990
|
-
baseDir,
|
991
|
-
moduleDirectories,
|
992
|
-
rootDir,
|
993
|
-
ignoreSideEffectsForRoot
|
994
|
-
});
|
996
|
+
if (hasPackageEntry && !preserveSymlinks) {
|
997
|
+
const fileExists = await exists(location);
|
998
|
+
if (fileExists) {
|
999
|
+
location = await realpath(location);
|
1000
|
+
}
|
1001
|
+
}
|
1002
|
+
|
1003
|
+
idToPackageInfo.set(location, packageInfo);
|
995
1004
|
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
if (!resolved) {
|
1005
|
+
if (hasPackageEntry) {
|
1006
|
+
if (importeeIsBuiltin && preferBuiltins) {
|
1007
|
+
if (!isPreferBuiltinsSet && resolvedWithoutBuiltins && resolved !== importee) {
|
1008
|
+
context.warn(
|
1009
|
+
`preferring built-in module '${importee}' over local alternative at '${resolvedWithoutBuiltins.location}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning`
|
1010
|
+
);
|
1011
|
+
}
|
1012
|
+
return false;
|
1013
|
+
} else if (jail && location.indexOf(normalize(jail.trim(sep))) !== 0) {
|
1006
1014
|
return null;
|
1007
1015
|
}
|
1016
|
+
}
|
1008
1017
|
|
1009
|
-
|
1010
|
-
|
1011
|
-
if (
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
}
|
1017
|
-
location = packageBrowserField[location];
|
1018
|
-
}
|
1019
|
-
browserMapCache.set(location, packageBrowserField);
|
1018
|
+
if (options.modulesOnly && (await exists(location))) {
|
1019
|
+
const code = await readFile$1(location, 'utf-8');
|
1020
|
+
if (isModule(code)) {
|
1021
|
+
return {
|
1022
|
+
id: `${location}${importSuffix}`,
|
1023
|
+
moduleSideEffects: hasModuleSideEffects(location)
|
1024
|
+
};
|
1020
1025
|
}
|
1026
|
+
return null;
|
1027
|
+
}
|
1028
|
+
const result = {
|
1029
|
+
id: `${location}${importSuffix}`,
|
1030
|
+
moduleSideEffects: hasModuleSideEffects(location)
|
1031
|
+
};
|
1032
|
+
return result;
|
1033
|
+
};
|
1021
1034
|
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1035
|
+
return {
|
1036
|
+
name: 'node-resolve',
|
1037
|
+
|
1038
|
+
buildStart(options) {
|
1039
|
+
rollupOptions = options;
|
1040
|
+
|
1041
|
+
for (const warning of warnings) {
|
1042
|
+
this.warn(warning);
|
1027
1043
|
}
|
1028
1044
|
|
1029
|
-
|
1045
|
+
({ preserveSymlinks } = options);
|
1046
|
+
},
|
1030
1047
|
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
return null;
|
1041
|
-
}
|
1048
|
+
generateBundle() {
|
1049
|
+
readCachedFile.clear();
|
1050
|
+
isFileCached.clear();
|
1051
|
+
isDirCached.clear();
|
1052
|
+
},
|
1053
|
+
|
1054
|
+
async resolveId(importee, importer, opts) {
|
1055
|
+
if (importee === ES6_BROWSER_EMPTY) {
|
1056
|
+
return importee;
|
1042
1057
|
}
|
1058
|
+
// ignore IDs with null character, these belong to other plugins
|
1059
|
+
if (/\0/.test(importee)) return null;
|
1043
1060
|
|
1044
|
-
if (
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1061
|
+
if (/\0/.test(importer)) {
|
1062
|
+
importer = undefined;
|
1063
|
+
}
|
1064
|
+
|
1065
|
+
const resolved = await doResolveId(this, importee, importer, opts);
|
1066
|
+
if (resolved) {
|
1067
|
+
const resolvedResolved = await this.resolve(resolved.id, importer, { skipSelf: true });
|
1068
|
+
const isExternal = !!(resolvedResolved && resolvedResolved.external);
|
1069
|
+
if (isExternal) {
|
1070
|
+
return false;
|
1051
1071
|
}
|
1052
|
-
return null;
|
1053
1072
|
}
|
1054
|
-
|
1055
|
-
id: `${location}${importSuffix}`,
|
1056
|
-
moduleSideEffects: hasModuleSideEffects(location)
|
1057
|
-
};
|
1058
|
-
return result;
|
1073
|
+
return resolved;
|
1059
1074
|
},
|
1060
1075
|
|
1061
1076
|
load(importee) {
|
package/package.json
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rollup/plugin-node-resolve",
|
3
|
-
"version": "
|
3
|
+
"version": "13.0.0",
|
4
4
|
"publishConfig": {
|
5
5
|
"access": "public"
|
6
6
|
},
|
7
7
|
"description": "Locate and bundle third-party dependencies in node_modules",
|
8
8
|
"license": "MIT",
|
9
|
-
"repository":
|
9
|
+
"repository": {
|
10
|
+
"url": "rollup/plugins",
|
11
|
+
"directory": "packages/node-resolve"
|
12
|
+
},
|
10
13
|
"author": "Rich Harris <richard.a.harris@gmail.com>",
|
11
14
|
"homepage": "https://github.com/rollup/plugins/tree/master/packages/node-resolve/#readme",
|
12
15
|
"bugs": "https://github.com/rollup/plugins/issues",
|
@@ -26,13 +29,9 @@
|
|
26
29
|
"ci:lint": "pnpm run build && pnpm run lint",
|
27
30
|
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
|
28
31
|
"ci:test": "pnpm run test -- --verbose && pnpm run test:ts",
|
29
|
-
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
|
30
|
-
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
|
31
|
-
"lint:js": "eslint --fix --cache src test types --ext .js,.ts",
|
32
|
-
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
|
33
32
|
"prebuild": "del-cli dist",
|
34
33
|
"prepare": "pnpm run build",
|
35
|
-
"prepublishOnly": "pnpm run lint && pnpm run test && pnpm run test:ts",
|
34
|
+
"prepublishOnly": "pnpm -w run lint && pnpm run test && pnpm run test:ts",
|
36
35
|
"pretest": "pnpm run build",
|
37
36
|
"test": "ava",
|
38
37
|
"test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
|
@@ -51,7 +50,7 @@
|
|
51
50
|
"modules"
|
52
51
|
],
|
53
52
|
"peerDependencies": {
|
54
|
-
"rollup": "^
|
53
|
+
"rollup": "^2.42.0"
|
55
54
|
},
|
56
55
|
"dependencies": {
|
57
56
|
"@rollup/pluginutils": "^3.1.0",
|
@@ -68,7 +67,7 @@
|
|
68
67
|
"@rollup/plugin-commonjs": "^16.0.0",
|
69
68
|
"@rollup/plugin-json": "^4.1.0",
|
70
69
|
"es5-ext": "^0.10.53",
|
71
|
-
"rollup": "^2.
|
70
|
+
"rollup": "^2.42.0",
|
72
71
|
"source-map": "^0.7.3",
|
73
72
|
"string-capitalize": "^1.0.1"
|
74
73
|
},
|
package/types/index.d.ts
CHANGED
File without changes
|