@rollup/plugin-node-resolve 15.2.4 → 15.3.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/README.md CHANGED
@@ -133,11 +133,19 @@ Specifies the properties to scan within a `package.json`, used to determine the
133
133
 
134
134
  ### `preferBuiltins`
135
135
 
136
- Type: `Boolean`<br>
136
+ Type: `Boolean | (module: string) => boolean`<br>
137
137
  Default: `true` (with warnings if a builtin module is used over a local version. Set to `true` to disable warning.)
138
138
 
139
139
  If `true`, the plugin will prefer built-in modules (e.g. `fs`, `path`). If `false`, the plugin will look for locally installed modules of the same name.
140
140
 
141
+ Alternatively, you may pass in a function that returns a boolean to confirm whether the plugin should prefer built-in modules. e.g.
142
+
143
+ ```js
144
+ preferBuiltins: (module) => module !== 'punycode';
145
+ ```
146
+
147
+ will not treat `punycode` as a built-in module
148
+
141
149
  ### `modulesOnly`
142
150
 
143
151
  Type: `Boolean`<br>
package/dist/cjs/index.js CHANGED
@@ -12,7 +12,7 @@ var url = require('url');
12
12
  var resolve = require('resolve');
13
13
  var pluginutils = require('@rollup/pluginutils');
14
14
 
15
- var version = "15.2.4";
15
+ var version = "15.3.1";
16
16
  var peerDependencies = {
17
17
  rollup: "^2.78.0||^3.0.0||^4.0.0"
18
18
  };
@@ -1073,7 +1073,7 @@ function nodeResolve(opts = {}) {
1073
1073
  const idToPackageInfo = new Map();
1074
1074
  const mainFields = getMainFields(options);
1075
1075
  const useBrowserOverrides = mainFields.indexOf('browser') !== -1;
1076
- const isPreferBuiltinsSet = options.preferBuiltins === true || options.preferBuiltins === false;
1076
+ const isPreferBuiltinsSet = Object.prototype.hasOwnProperty.call(options, 'preferBuiltins');
1077
1077
  const preferBuiltins = isPreferBuiltinsSet ? options.preferBuiltins : true;
1078
1078
  const rootDir = path.resolve(options.rootDir || process.cwd());
1079
1079
  let { dedupe } = options;
@@ -1209,8 +1209,10 @@ function nodeResolve(opts = {}) {
1209
1209
  });
1210
1210
 
1211
1211
  const importeeIsBuiltin = module$1.builtinModules.includes(importee.replace(nodeImportPrefix, ''));
1212
+ const preferImporteeIsBuiltin =
1213
+ typeof preferBuiltins === 'function' ? preferBuiltins(importee) : preferBuiltins;
1212
1214
  const resolved =
1213
- importeeIsBuiltin && preferBuiltins
1215
+ importeeIsBuiltin && preferImporteeIsBuiltin
1214
1216
  ? {
1215
1217
  packageInfo: undefined,
1216
1218
  hasModuleSideEffects: () => null,
@@ -1245,11 +1247,14 @@ function nodeResolve(opts = {}) {
1245
1247
  idToPackageInfo.set(location, packageInfo);
1246
1248
 
1247
1249
  if (hasPackageEntry) {
1248
- if (importeeIsBuiltin && preferBuiltins) {
1250
+ if (importeeIsBuiltin && preferImporteeIsBuiltin) {
1249
1251
  if (!isPreferBuiltinsSet && resolvedWithoutBuiltins && resolved !== importee) {
1250
- context.warn(
1251
- `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`
1252
- );
1252
+ context.warn({
1253
+ message:
1254
+ `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.` +
1255
+ `or passing a function to 'preferBuiltins' to provide more fine-grained control over which built-in modules to prefer.`,
1256
+ pluginCode: 'PREFER_BUILTINS'
1257
+ });
1253
1258
  }
1254
1259
  return false;
1255
1260
  } else if (jail && location.indexOf(path.normalize(jail.trim(path.sep))) !== 0) {
@@ -1302,7 +1307,7 @@ function nodeResolve(opts = {}) {
1302
1307
  return importee;
1303
1308
  }
1304
1309
  // ignore IDs with null character, these belong to other plugins
1305
- if (/\0/.test(importee)) return null;
1310
+ if (importee && importee.includes('\0')) return null;
1306
1311
 
1307
1312
  const { custom = {} } = resolveOptions;
1308
1313
  const { 'node-resolve': { resolved: alreadyResolved } = {} } = custom;
@@ -1310,7 +1315,7 @@ function nodeResolve(opts = {}) {
1310
1315
  return alreadyResolved;
1311
1316
  }
1312
1317
 
1313
- if (/\0/.test(importer)) {
1318
+ if (importer && importer.includes('\0')) {
1314
1319
  importer = undefined;
1315
1320
  }
1316
1321
 
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 = "15.2.4";
11
+ var version = "15.3.1";
12
12
  var peerDependencies = {
13
13
  rollup: "^2.78.0||^3.0.0||^4.0.0"
14
14
  };
@@ -1069,7 +1069,7 @@ function nodeResolve(opts = {}) {
1069
1069
  const idToPackageInfo = new Map();
1070
1070
  const mainFields = getMainFields(options);
1071
1071
  const useBrowserOverrides = mainFields.indexOf('browser') !== -1;
1072
- const isPreferBuiltinsSet = options.preferBuiltins === true || options.preferBuiltins === false;
1072
+ const isPreferBuiltinsSet = Object.prototype.hasOwnProperty.call(options, 'preferBuiltins');
1073
1073
  const preferBuiltins = isPreferBuiltinsSet ? options.preferBuiltins : true;
1074
1074
  const rootDir = resolve(options.rootDir || process.cwd());
1075
1075
  let { dedupe } = options;
@@ -1205,8 +1205,10 @@ function nodeResolve(opts = {}) {
1205
1205
  });
1206
1206
 
1207
1207
  const importeeIsBuiltin = builtinModules.includes(importee.replace(nodeImportPrefix, ''));
1208
+ const preferImporteeIsBuiltin =
1209
+ typeof preferBuiltins === 'function' ? preferBuiltins(importee) : preferBuiltins;
1208
1210
  const resolved =
1209
- importeeIsBuiltin && preferBuiltins
1211
+ importeeIsBuiltin && preferImporteeIsBuiltin
1210
1212
  ? {
1211
1213
  packageInfo: undefined,
1212
1214
  hasModuleSideEffects: () => null,
@@ -1241,11 +1243,14 @@ function nodeResolve(opts = {}) {
1241
1243
  idToPackageInfo.set(location, packageInfo);
1242
1244
 
1243
1245
  if (hasPackageEntry) {
1244
- if (importeeIsBuiltin && preferBuiltins) {
1246
+ if (importeeIsBuiltin && preferImporteeIsBuiltin) {
1245
1247
  if (!isPreferBuiltinsSet && resolvedWithoutBuiltins && resolved !== importee) {
1246
- context.warn(
1247
- `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`
1248
- );
1248
+ context.warn({
1249
+ message:
1250
+ `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.` +
1251
+ `or passing a function to 'preferBuiltins' to provide more fine-grained control over which built-in modules to prefer.`,
1252
+ pluginCode: 'PREFER_BUILTINS'
1253
+ });
1249
1254
  }
1250
1255
  return false;
1251
1256
  } else if (jail && location.indexOf(normalize(jail.trim(sep))) !== 0) {
@@ -1298,7 +1303,7 @@ function nodeResolve(opts = {}) {
1298
1303
  return importee;
1299
1304
  }
1300
1305
  // ignore IDs with null character, these belong to other plugins
1301
- if (/\0/.test(importee)) return null;
1306
+ if (importee && importee.includes('\0')) return null;
1302
1307
 
1303
1308
  const { custom = {} } = resolveOptions;
1304
1309
  const { 'node-resolve': { resolved: alreadyResolved } = {} } = custom;
@@ -1306,7 +1311,7 @@ function nodeResolve(opts = {}) {
1306
1311
  return alreadyResolved;
1307
1312
  }
1308
1313
 
1309
- if (/\0/.test(importer)) {
1314
+ if (importer && importer.includes('\0')) {
1310
1315
  importer = undefined;
1311
1316
  }
1312
1317
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rollup/plugin-node-resolve",
3
- "version": "15.2.4",
3
+ "version": "15.3.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/types/index.d.ts CHANGED
@@ -79,9 +79,11 @@ export interface RollupNodeResolveOptions {
79
79
  /**
80
80
  * If `true`, the plugin will prefer built-in modules (e.g. `fs`, `path`). If `false`,
81
81
  * the plugin will look for locally installed modules of the same name.
82
+ *
83
+ * If a function is provided, it will be called to determine whether to prefer built-ins.
82
84
  * @default true
83
85
  */
84
- preferBuiltins?: boolean;
86
+ preferBuiltins?: boolean | ((module: string) => boolean);
85
87
 
86
88
  /**
87
89
  * An `Array` which instructs the plugin to limit module resolution to those whose