@rollup/plugin-node-resolve 13.1.2 → 13.2.1

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,29 @@
1
1
  # @rollup/plugin-node-resolve ChangeLog
2
2
 
3
+ ## v13.2.1
4
+
5
+ _2022-04-15_
6
+
7
+ ### Bugfixes
8
+
9
+ - fix: update side effects logic to be deep when glob doesn’t contain `/` (#1148)
10
+
11
+ ## v13.2.0
12
+
13
+ _2022-04-11_
14
+
15
+ ### Features
16
+
17
+ - feat: Add the ability to pass a function into resolveOnly (#1152)
18
+
19
+ ## v13.1.3
20
+
21
+ _2022-01-05_
22
+
23
+ ### Bugfixes
24
+
25
+ - fix: use correct version when published (#1063)
26
+
3
27
  ## v13.1.2
4
28
 
5
29
  _2021-12-31_
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.1";
24
+ var version = "13.2.1";
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
  }
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.1";
11
+ var version = "13.2.1";
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rollup/plugin-node-resolve",
3
- "version": "13.1.2",
3
+ "version": "13.2.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -31,6 +31,7 @@
31
31
  "ci:test": "pnpm test -- --verbose && pnpm test:ts",
32
32
  "prebuild": "del-cli dist",
33
33
  "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi",
34
+ "prepublishOnly": "pnpm build",
34
35
  "prerelease": "pnpm build",
35
36
  "pretest": "pnpm build",
36
37
  "release": "pnpm plugin:release --workspace-root -- --pkg $npm_package_name",
@@ -68,7 +69,7 @@
68
69
  "@rollup/plugin-commonjs": "^16.0.0",
69
70
  "@rollup/plugin-json": "^4.1.0",
70
71
  "es5-ext": "^0.10.53",
71
- "rollup": "^2.58.0",
72
+ "rollup": "^2.67.3",
72
73
  "source-map": "^0.7.3",
73
74
  "string-capitalize": "^1.0.1"
74
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