@rollup/plugin-node-resolve 15.2.3 → 15.3.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/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
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var path = require('path');
6
- var isBuiltinModule = require('is-builtin-module');
6
+ var module$1 = require('module');
7
7
  var deepMerge = require('deepmerge');
8
8
  var isModule = require('is-module');
9
9
  var fs = require('fs');
@@ -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.3";
15
+ var version = "15.3.0";
16
16
  var peerDependencies = {
17
17
  rollup: "^2.78.0||^3.0.0||^4.0.0"
18
18
  };
@@ -1058,6 +1058,8 @@ const defaults = {
1058
1058
  // TODO: set to false in next major release or remove
1059
1059
  allowExportsFolderMapping: true
1060
1060
  };
1061
+ const nodeImportPrefix = /^node:/;
1062
+
1061
1063
  const DEFAULTS = deepFreeze(deepMerge({}, defaults));
1062
1064
 
1063
1065
  function nodeResolve(opts = {}) {
@@ -1071,7 +1073,7 @@ function nodeResolve(opts = {}) {
1071
1073
  const idToPackageInfo = new Map();
1072
1074
  const mainFields = getMainFields(options);
1073
1075
  const useBrowserOverrides = mainFields.indexOf('browser') !== -1;
1074
- const isPreferBuiltinsSet = options.preferBuiltins === true || options.preferBuiltins === false;
1076
+ const isPreferBuiltinsSet = Object.prototype.hasOwnProperty.call(options, 'preferBuiltins');
1075
1077
  const preferBuiltins = isPreferBuiltinsSet ? options.preferBuiltins : true;
1076
1078
  const rootDir = path.resolve(options.rootDir || process.cwd());
1077
1079
  let { dedupe } = options;
@@ -1206,9 +1208,11 @@ function nodeResolve(opts = {}) {
1206
1208
  allowExportsFolderMapping: options.allowExportsFolderMapping
1207
1209
  });
1208
1210
 
1209
- const importeeIsBuiltin = isBuiltinModule(importee);
1211
+ const importeeIsBuiltin = module$1.builtinModules.includes(importee.replace(nodeImportPrefix, ''));
1212
+ const preferImporteeIsBuiltin =
1213
+ typeof preferBuiltins === 'function' ? preferBuiltins(importee) : preferBuiltins;
1210
1214
  const resolved =
1211
- importeeIsBuiltin && preferBuiltins
1215
+ importeeIsBuiltin && preferImporteeIsBuiltin
1212
1216
  ? {
1213
1217
  packageInfo: undefined,
1214
1218
  hasModuleSideEffects: () => null,
@@ -1243,11 +1247,14 @@ function nodeResolve(opts = {}) {
1243
1247
  idToPackageInfo.set(location, packageInfo);
1244
1248
 
1245
1249
  if (hasPackageEntry) {
1246
- if (importeeIsBuiltin && preferBuiltins) {
1250
+ if (importeeIsBuiltin && preferImporteeIsBuiltin) {
1247
1251
  if (!isPreferBuiltinsSet && resolvedWithoutBuiltins && resolved !== importee) {
1248
- context.warn(
1249
- `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`
1250
- );
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
+ });
1251
1258
  }
1252
1259
  return false;
1253
1260
  } else if (jail && location.indexOf(path.normalize(jail.trim(path.sep))) !== 0) {
package/dist/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import path, { dirname, resolve, extname, normalize, sep } from 'path';
2
- import isBuiltinModule from 'is-builtin-module';
2
+ import { builtinModules } from 'module';
3
3
  import deepMerge from 'deepmerge';
4
4
  import isModule from 'is-module';
5
5
  import fs, { realpathSync } from 'fs';
@@ -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.3";
11
+ var version = "15.3.0";
12
12
  var peerDependencies = {
13
13
  rollup: "^2.78.0||^3.0.0||^4.0.0"
14
14
  };
@@ -1054,6 +1054,8 @@ const defaults = {
1054
1054
  // TODO: set to false in next major release or remove
1055
1055
  allowExportsFolderMapping: true
1056
1056
  };
1057
+ const nodeImportPrefix = /^node:/;
1058
+
1057
1059
  const DEFAULTS = deepFreeze(deepMerge({}, defaults));
1058
1060
 
1059
1061
  function nodeResolve(opts = {}) {
@@ -1067,7 +1069,7 @@ function nodeResolve(opts = {}) {
1067
1069
  const idToPackageInfo = new Map();
1068
1070
  const mainFields = getMainFields(options);
1069
1071
  const useBrowserOverrides = mainFields.indexOf('browser') !== -1;
1070
- const isPreferBuiltinsSet = options.preferBuiltins === true || options.preferBuiltins === false;
1072
+ const isPreferBuiltinsSet = Object.prototype.hasOwnProperty.call(options, 'preferBuiltins');
1071
1073
  const preferBuiltins = isPreferBuiltinsSet ? options.preferBuiltins : true;
1072
1074
  const rootDir = resolve(options.rootDir || process.cwd());
1073
1075
  let { dedupe } = options;
@@ -1202,9 +1204,11 @@ function nodeResolve(opts = {}) {
1202
1204
  allowExportsFolderMapping: options.allowExportsFolderMapping
1203
1205
  });
1204
1206
 
1205
- const importeeIsBuiltin = isBuiltinModule(importee);
1207
+ const importeeIsBuiltin = builtinModules.includes(importee.replace(nodeImportPrefix, ''));
1208
+ const preferImporteeIsBuiltin =
1209
+ typeof preferBuiltins === 'function' ? preferBuiltins(importee) : preferBuiltins;
1206
1210
  const resolved =
1207
- importeeIsBuiltin && preferBuiltins
1211
+ importeeIsBuiltin && preferImporteeIsBuiltin
1208
1212
  ? {
1209
1213
  packageInfo: undefined,
1210
1214
  hasModuleSideEffects: () => null,
@@ -1239,11 +1243,14 @@ function nodeResolve(opts = {}) {
1239
1243
  idToPackageInfo.set(location, packageInfo);
1240
1244
 
1241
1245
  if (hasPackageEntry) {
1242
- if (importeeIsBuiltin && preferBuiltins) {
1246
+ if (importeeIsBuiltin && preferImporteeIsBuiltin) {
1243
1247
  if (!isPreferBuiltinsSet && resolvedWithoutBuiltins && resolved !== importee) {
1244
- context.warn(
1245
- `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`
1246
- );
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
+ });
1247
1254
  }
1248
1255
  return false;
1249
1256
  } else if (jail && location.indexOf(normalize(jail.trim(sep))) !== 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rollup/plugin-node-resolve",
3
- "version": "15.2.3",
3
+ "version": "15.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -23,21 +23,6 @@
23
23
  "engines": {
24
24
  "node": ">=14.0.0"
25
25
  },
26
- "scripts": {
27
- "build": "rollup -c",
28
- "ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
29
- "ci:lint": "pnpm build && pnpm lint",
30
- "ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
31
- "ci:test": "pnpm test -- --verbose",
32
- "prebuild": "del-cli dist",
33
- "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi",
34
- "prepublishOnly": "pnpm build",
35
- "prerelease": "pnpm build",
36
- "pretest": "pnpm build",
37
- "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name",
38
- "test": "pnpm test:ts && ava",
39
- "test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
40
- },
41
26
  "files": [
42
27
  "dist",
43
28
  "!dist/**/*.map",
@@ -64,7 +49,6 @@
64
49
  "@rollup/pluginutils": "^5.0.1",
65
50
  "@types/resolve": "1.20.2",
66
51
  "deepmerge": "^4.2.2",
67
- "is-builtin-module": "^3.2.1",
68
52
  "is-module": "^1.0.0",
69
53
  "resolve": "^1.22.1"
70
54
  },
@@ -88,5 +72,18 @@
88
72
  "!**/recipes/**",
89
73
  "!**/types.ts"
90
74
  ]
75
+ },
76
+ "scripts": {
77
+ "build": "rollup -c",
78
+ "ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
79
+ "ci:lint": "pnpm build && pnpm lint",
80
+ "ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
81
+ "ci:test": "pnpm test -- --verbose",
82
+ "prebuild": "del-cli dist",
83
+ "prerelease": "pnpm build",
84
+ "pretest": "pnpm build",
85
+ "release": "pnpm --workspace-root package:release $(pwd)",
86
+ "test": "pnpm test:ts && ava",
87
+ "test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
91
88
  }
92
- }
89
+ }
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