@rollup/plugin-node-resolve 13.1.3 → 13.2.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @rollup/plugin-node-resolve ChangeLog
2
2
 
3
+ ## v13.2.0
4
+
5
+ _2022-04-11_
6
+
7
+ ### Features
8
+
9
+ - feat: Add the ability to pass a function into resolveOnly (#1152)
10
+
3
11
  ## v13.1.3
4
12
 
5
13
  _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.0";
25
25
 
26
26
  util.promisify(fs__default["default"].access);
27
27
  const readFile$1 = util.promisify(fs__default["default"].readFile);
@@ -962,13 +962,22 @@ function nodeResolve(opts = {}) {
962
962
  options.dedupe.includes(importee) || options.dedupe.includes(getPackageName(importee));
963
963
  }
964
964
 
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
- });
965
+ // creates a function from the patterns to test if a particular module should be bundled.
966
+ const allowPatterns = (patterns) => {
967
+ const regexPatterns = patterns.map((pattern) => {
968
+ if (pattern instanceof RegExp) {
969
+ return pattern;
970
+ }
971
+ const normalized = pattern.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
972
+ return new RegExp(`^${normalized}$`);
973
+ });
974
+ return (id) => !regexPatterns.length || regexPatterns.some((pattern) => pattern.test(id));
975
+ };
976
+
977
+ const resolveOnly =
978
+ typeof options.resolveOnly === 'function'
979
+ ? options.resolveOnly
980
+ : allowPatterns(options.resolveOnly);
972
981
 
973
982
  const browserMapCache = new Map();
974
983
  let preserveSymlinks;
@@ -1011,11 +1020,8 @@ function nodeResolve(opts = {}) {
1011
1020
  isRelativeImport = true;
1012
1021
  }
1013
1022
 
1014
- if (
1015
- !isRelativeImport &&
1016
- resolveOnly.length &&
1017
- !resolveOnly.some((pattern) => pattern.test(id))
1018
- ) {
1023
+ // if it's not a relative import, and it's not requested, reject it.
1024
+ if (!isRelativeImport && !resolveOnly(id)) {
1019
1025
  if (normalizeInput(rollupOptions.input).includes(importee)) {
1020
1026
  return null;
1021
1027
  }
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.0";
12
12
 
13
13
  promisify(fs.access);
14
14
  const readFile$1 = promisify(fs.readFile);
@@ -949,13 +949,22 @@ function nodeResolve(opts = {}) {
949
949
  options.dedupe.includes(importee) || options.dedupe.includes(getPackageName(importee));
950
950
  }
951
951
 
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
- });
952
+ // creates a function from the patterns to test if a particular module should be bundled.
953
+ const allowPatterns = (patterns) => {
954
+ const regexPatterns = patterns.map((pattern) => {
955
+ if (pattern instanceof RegExp) {
956
+ return pattern;
957
+ }
958
+ const normalized = pattern.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
959
+ return new RegExp(`^${normalized}$`);
960
+ });
961
+ return (id) => !regexPatterns.length || regexPatterns.some((pattern) => pattern.test(id));
962
+ };
963
+
964
+ const resolveOnly =
965
+ typeof options.resolveOnly === 'function'
966
+ ? options.resolveOnly
967
+ : allowPatterns(options.resolveOnly);
959
968
 
960
969
  const browserMapCache = new Map();
961
970
  let preserveSymlinks;
@@ -998,11 +1007,8 @@ function nodeResolve(opts = {}) {
998
1007
  isRelativeImport = true;
999
1008
  }
1000
1009
 
1001
- if (
1002
- !isRelativeImport &&
1003
- resolveOnly.length &&
1004
- !resolveOnly.some((pattern) => pattern.test(id))
1005
- ) {
1010
+ // if it's not a relative import, and it's not requested, reject it.
1011
+ if (!isRelativeImport && !resolveOnly(id)) {
1006
1012
  if (normalizeInput(rollupOptions.input).includes(importee)) {
1007
1013
  return null;
1008
1014
  }
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.0",
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