@rollup/plugin-node-resolve 13.1.3 → 13.2.2

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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # @rollup/plugin-node-resolve ChangeLog
2
2
 
3
+ ## v13.2.2
4
+
5
+ _2022-05-02_
6
+
7
+ ### Bugfixes
8
+
9
+ - fix: Respect if other plugins resolve the resolution to a different id (#1181)
10
+ - fix: Revert respect if other plugins resolve the resolution to a different id (ae59ceb)
11
+ - fix: Respect if other plugins resolve the resolution to a different id (f8d4c44)
12
+
13
+ ## v13.2.1
14
+
15
+ _2022-04-15_
16
+
17
+ ### Bugfixes
18
+
19
+ - fix: update side effects logic to be deep when glob doesn’t contain `/` (#1148)
20
+
21
+ ## v13.2.0
22
+
23
+ _2022-04-11_
24
+
25
+ ### Features
26
+
27
+ - feat: Add the ability to pass a function into resolveOnly (#1152)
28
+
3
29
  ## v13.1.3
4
30
 
5
31
  _2022-01-05_
package/README.md CHANGED
@@ -140,12 +140,17 @@ If `true`, inspect resolved files to assert that they are ES2015 modules.
140
140
 
141
141
  ### `resolveOnly`
142
142
 
143
- Type: `Array[...String|RegExp]`<br>
143
+ Type: `Array[...String|RegExp] | (module: string) => boolean`<br>
144
144
  Default: `null`
145
145
 
146
146
  An `Array` which instructs the plugin to limit module resolution to those whose names match patterns in the array. _Note: Modules not matching any patterns will be marked as external._
147
147
 
148
- Example: `resolveOnly: ['batman', /^@batcave\/.*$/]`
148
+ Alternatively, you may pass in a function that returns a boolean to confirm whether the module should be included or not.
149
+
150
+ Examples:
151
+
152
+ - `resolveOnly: ['batman', /^@batcave\/.*$/]`
153
+ - `resolveOnly: module => !module.includes('joker')`
149
154
 
150
155
  ### `rootDir`
151
156
 
package/dist/cjs/index.js CHANGED
@@ -21,7 +21,7 @@ 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
- var version = "13.1.3";
24
+ var version = "13.2.2";
25
25
 
26
26
  util.promisify(fs__default["default"].access);
27
27
  const readFile$1 = util.promisify(fs__default["default"].readFile);
@@ -282,7 +282,17 @@ function getPackageInfo(options) {
282
282
  if (typeof packageSideEffects === 'boolean') {
283
283
  internalPackageInfo.hasModuleSideEffects = () => packageSideEffects;
284
284
  } else if (Array.isArray(packageSideEffects)) {
285
- internalPackageInfo.hasModuleSideEffects = pluginutils.createFilter(packageSideEffects, null, {
285
+ const finalPackageSideEffects = packageSideEffects.map((sideEffect) => {
286
+ /*
287
+ * The array accepts simple glob patterns to the relevant files... Patterns like .css, which do not include a /, will be treated like **\/.css.
288
+ * https://webpack.js.org/guides/tree-shaking/
289
+ */
290
+ if (sideEffect.includes('/')) {
291
+ return sideEffect;
292
+ }
293
+ return `**/${sideEffect}`;
294
+ });
295
+ internalPackageInfo.hasModuleSideEffects = pluginutils.createFilter(finalPackageSideEffects, null, {
286
296
  resolve: pkgRoot
287
297
  });
288
298
  }
@@ -962,13 +972,22 @@ function nodeResolve(opts = {}) {
962
972
  options.dedupe.includes(importee) || options.dedupe.includes(getPackageName(importee));
963
973
  }
964
974
 
965
- const resolveOnly = options.resolveOnly.map((pattern) => {
966
- if (pattern instanceof RegExp) {
967
- return pattern;
968
- }
969
- const normalized = pattern.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
970
- return new RegExp(`^${normalized}$`);
971
- });
975
+ // creates a function from the patterns to test if a particular module should be bundled.
976
+ const allowPatterns = (patterns) => {
977
+ const regexPatterns = patterns.map((pattern) => {
978
+ if (pattern instanceof RegExp) {
979
+ return pattern;
980
+ }
981
+ const normalized = pattern.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
982
+ return new RegExp(`^${normalized}$`);
983
+ });
984
+ return (id) => !regexPatterns.length || regexPatterns.some((pattern) => pattern.test(id));
985
+ };
986
+
987
+ const resolveOnly =
988
+ typeof options.resolveOnly === 'function'
989
+ ? options.resolveOnly
990
+ : allowPatterns(options.resolveOnly);
972
991
 
973
992
  const browserMapCache = new Map();
974
993
  let preserveSymlinks;
@@ -1011,11 +1030,8 @@ function nodeResolve(opts = {}) {
1011
1030
  isRelativeImport = true;
1012
1031
  }
1013
1032
 
1014
- if (
1015
- !isRelativeImport &&
1016
- resolveOnly.length &&
1017
- !resolveOnly.some((pattern) => pattern.test(id))
1018
- ) {
1033
+ // if it's not a relative import, and it's not requested, reject it.
1034
+ if (!isRelativeImport && !resolveOnly(id)) {
1019
1035
  if (normalizeInput(rollupOptions.input).includes(importee)) {
1020
1036
  return null;
1021
1037
  }
@@ -1135,14 +1151,14 @@ function nodeResolve(opts = {}) {
1135
1151
 
1136
1152
  version,
1137
1153
 
1138
- buildStart(options) {
1139
- rollupOptions = options;
1154
+ buildStart(buildOptions) {
1155
+ rollupOptions = buildOptions;
1140
1156
 
1141
1157
  for (const warning of warnings) {
1142
1158
  this.warn(warning);
1143
1159
  }
1144
1160
 
1145
- ({ preserveSymlinks } = options);
1161
+ ({ preserveSymlinks } = buildOptions);
1146
1162
  },
1147
1163
 
1148
1164
  generateBundle() {
@@ -1174,6 +1190,11 @@ function nodeResolve(opts = {}) {
1174
1190
  if (resolvedResolved.external) {
1175
1191
  return false;
1176
1192
  }
1193
+ // Allow other plugins to take over resolution. Rollup core will not
1194
+ // change the id if it corresponds to an existing file
1195
+ if (resolvedResolved.id !== resolved.id) {
1196
+ return resolvedResolved;
1197
+ }
1177
1198
  // Pass on meta information added by other plugins
1178
1199
  return { ...resolved, meta: resolvedResolved.meta };
1179
1200
  }
package/dist/es/index.js CHANGED
@@ -8,7 +8,7 @@ import { pathToFileURL, fileURLToPath } from 'url';
8
8
  import resolve$1 from 'resolve';
9
9
  import { createFilter } from '@rollup/pluginutils';
10
10
 
11
- var version = "13.1.3";
11
+ var version = "13.2.2";
12
12
 
13
13
  promisify(fs.access);
14
14
  const readFile$1 = promisify(fs.readFile);
@@ -269,7 +269,17 @@ function getPackageInfo(options) {
269
269
  if (typeof packageSideEffects === 'boolean') {
270
270
  internalPackageInfo.hasModuleSideEffects = () => packageSideEffects;
271
271
  } else if (Array.isArray(packageSideEffects)) {
272
- internalPackageInfo.hasModuleSideEffects = createFilter(packageSideEffects, null, {
272
+ const finalPackageSideEffects = packageSideEffects.map((sideEffect) => {
273
+ /*
274
+ * The array accepts simple glob patterns to the relevant files... Patterns like .css, which do not include a /, will be treated like **\/.css.
275
+ * https://webpack.js.org/guides/tree-shaking/
276
+ */
277
+ if (sideEffect.includes('/')) {
278
+ return sideEffect;
279
+ }
280
+ return `**/${sideEffect}`;
281
+ });
282
+ internalPackageInfo.hasModuleSideEffects = createFilter(finalPackageSideEffects, null, {
273
283
  resolve: pkgRoot
274
284
  });
275
285
  }
@@ -949,13 +959,22 @@ function nodeResolve(opts = {}) {
949
959
  options.dedupe.includes(importee) || options.dedupe.includes(getPackageName(importee));
950
960
  }
951
961
 
952
- const resolveOnly = options.resolveOnly.map((pattern) => {
953
- if (pattern instanceof RegExp) {
954
- return pattern;
955
- }
956
- const normalized = pattern.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
957
- return new RegExp(`^${normalized}$`);
958
- });
962
+ // creates a function from the patterns to test if a particular module should be bundled.
963
+ const allowPatterns = (patterns) => {
964
+ const regexPatterns = patterns.map((pattern) => {
965
+ if (pattern instanceof RegExp) {
966
+ return pattern;
967
+ }
968
+ const normalized = pattern.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
969
+ return new RegExp(`^${normalized}$`);
970
+ });
971
+ return (id) => !regexPatterns.length || regexPatterns.some((pattern) => pattern.test(id));
972
+ };
973
+
974
+ const resolveOnly =
975
+ typeof options.resolveOnly === 'function'
976
+ ? options.resolveOnly
977
+ : allowPatterns(options.resolveOnly);
959
978
 
960
979
  const browserMapCache = new Map();
961
980
  let preserveSymlinks;
@@ -998,11 +1017,8 @@ function nodeResolve(opts = {}) {
998
1017
  isRelativeImport = true;
999
1018
  }
1000
1019
 
1001
- if (
1002
- !isRelativeImport &&
1003
- resolveOnly.length &&
1004
- !resolveOnly.some((pattern) => pattern.test(id))
1005
- ) {
1020
+ // if it's not a relative import, and it's not requested, reject it.
1021
+ if (!isRelativeImport && !resolveOnly(id)) {
1006
1022
  if (normalizeInput(rollupOptions.input).includes(importee)) {
1007
1023
  return null;
1008
1024
  }
@@ -1122,14 +1138,14 @@ function nodeResolve(opts = {}) {
1122
1138
 
1123
1139
  version,
1124
1140
 
1125
- buildStart(options) {
1126
- rollupOptions = options;
1141
+ buildStart(buildOptions) {
1142
+ rollupOptions = buildOptions;
1127
1143
 
1128
1144
  for (const warning of warnings) {
1129
1145
  this.warn(warning);
1130
1146
  }
1131
1147
 
1132
- ({ preserveSymlinks } = options);
1148
+ ({ preserveSymlinks } = buildOptions);
1133
1149
  },
1134
1150
 
1135
1151
  generateBundle() {
@@ -1161,6 +1177,11 @@ function nodeResolve(opts = {}) {
1161
1177
  if (resolvedResolved.external) {
1162
1178
  return false;
1163
1179
  }
1180
+ // Allow other plugins to take over resolution. Rollup core will not
1181
+ // change the id if it corresponds to an existing file
1182
+ if (resolvedResolved.id !== resolved.id) {
1183
+ return resolvedResolved;
1184
+ }
1164
1185
  // Pass on meta information added by other plugins
1165
1186
  return { ...resolved, meta: resolvedResolved.meta };
1166
1187
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rollup/plugin-node-resolve",
3
- "version": "13.1.3",
3
+ "version": "13.2.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -69,7 +69,7 @@
69
69
  "@rollup/plugin-commonjs": "^16.0.0",
70
70
  "@rollup/plugin-json": "^4.1.0",
71
71
  "es5-ext": "^0.10.53",
72
- "rollup": "^2.58.0",
72
+ "rollup": "^2.67.3",
73
73
  "source-map": "^0.7.3",
74
74
  "string-capitalize": "^1.0.1"
75
75
  },
package/types/index.d.ts CHANGED
@@ -81,7 +81,7 @@ export interface RollupNodeResolveOptions {
81
81
  * names match patterns in the array.
82
82
  * @default []
83
83
  */
84
- resolveOnly?: ReadonlyArray<string | RegExp> | null;
84
+ resolveOnly?: ReadonlyArray<string | RegExp> | null | ((module: string) => boolean);
85
85
 
86
86
  /**
87
87
  * Specifies the root directory from which to resolve modules. Typically used when