@rsbuild/plugin-node-polyfill 1.4.1 → 1.4.3

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
@@ -112,6 +112,7 @@ const bufferData = Buffer.from("abc");
112
112
  - `readline`
113
113
  - `repl`
114
114
  - `tls`
115
+ - `v8`
115
116
 
116
117
  Currently there is no polyfill for the above modules on the browser side, so when you import the above modules, it will automatically fallback to an empty object.
117
118
 
package/dist/index.cjs CHANGED
@@ -27,23 +27,14 @@ var __webpack_require__ = {};
27
27
  var __webpack_exports__ = {};
28
28
  __webpack_require__.r(__webpack_exports__);
29
29
  __webpack_require__.d(__webpack_exports__, {
30
- getProvideGlobals: ()=>getProvideGlobals,
31
- PLUGIN_NODE_POLYFILL_NAME: ()=>PLUGIN_NODE_POLYFILL_NAME,
32
30
  getResolveFallback: ()=>getResolveFallback,
31
+ PLUGIN_NODE_POLYFILL_NAME: ()=>PLUGIN_NODE_POLYFILL_NAME,
32
+ getProvideGlobals: ()=>getProvideGlobals,
33
33
  pluginNodePolyfill: ()=>pluginNodePolyfill,
34
34
  resolvePolyfill: ()=>resolvePolyfill,
35
35
  resolvedPolyfillToModules: ()=>resolvedPolyfillToModules,
36
36
  builtinMappingResolved: ()=>builtinMappingResolved
37
37
  });
38
- class ProtocolImportsPlugin {
39
- apply(compiler) {
40
- compiler.hooks.normalModuleFactory.tap('NormalModuleReplacementPlugin', (nmf)=>{
41
- nmf.hooks.beforeResolve.tap('NormalModuleReplacementPlugin', (resource)=>{
42
- if (/^node:/.test(resource.request)) resource.request = resource.request.replace(/^node:/, '');
43
- });
44
- });
45
- }
46
- }
47
38
  const external_node_module_namespaceObject = require("node:module");
48
39
  const libs_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
49
40
  const builtinMappingResolved = {
@@ -83,6 +74,7 @@ const builtinMappingResolved = {
83
74
  tty: libs_require.resolve('tty-browserify'),
84
75
  url: libs_require.resolve('url/'),
85
76
  util: libs_require.resolve('util/util.js'),
77
+ v8: null,
86
78
  vm: libs_require.resolve('vm-browserify'),
87
79
  zlib: libs_require.resolve('browserify-zlib')
88
80
  };
@@ -91,7 +83,7 @@ const resolvedPolyfillToModules = Object.fromEntries(Object.entries(builtinMappi
91
83
  key
92
84
  ]));
93
85
  const resolvePolyfill = (libPath, overrides)=>{
94
- if ((null == overrides ? void 0 : overrides[libPath]) !== void 0) return overrides[libPath];
86
+ if (overrides?.[libPath] !== void 0) return overrides[libPath];
95
87
  return builtinMappingResolved[libPath];
96
88
  };
97
89
  const getResolveFallback = ({ protocolImports, exclude, include, overrides })=>{
@@ -149,7 +141,7 @@ function pluginNodePolyfill(options = {}) {
149
141
  return {
150
142
  name: PLUGIN_NODE_POLYFILL_NAME,
151
143
  setup (api) {
152
- api.modifyBundlerChain(async (chain, { isServer, bundler })=>{
144
+ api.modifyBundlerChain(async (chain, { isServer, rspack })=>{
153
145
  if (isServer && !force) return;
154
146
  chain.resolve.fallback.merge(getResolveFallback({
155
147
  protocolImports,
@@ -158,10 +150,18 @@ function pluginNodePolyfill(options = {}) {
158
150
  overrides
159
151
  }));
160
152
  const provideGlobals = await getProvideGlobals(options.globals, overrides);
161
- if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(bundler.ProvidePlugin, [
153
+ if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(rspack.ProvidePlugin, [
162
154
  provideGlobals
163
155
  ]);
164
- if (protocolImports) chain.plugin('protocol-imports').use(ProtocolImportsPlugin);
156
+ if (protocolImports) {
157
+ const regex = /^node:/;
158
+ chain.plugin('protocol-imports').use(rspack.NormalModuleReplacementPlugin, [
159
+ regex,
160
+ (resource)=>{
161
+ resource.request = resource.request.replace(regex, '');
162
+ }
163
+ ]);
164
+ }
165
165
  });
166
166
  }
167
167
  };
package/dist/index.js CHANGED
@@ -1,13 +1,4 @@
1
1
  import { createRequire } from "node:module";
2
- class ProtocolImportsPlugin {
3
- apply(compiler) {
4
- compiler.hooks.normalModuleFactory.tap('NormalModuleReplacementPlugin', (nmf)=>{
5
- nmf.hooks.beforeResolve.tap('NormalModuleReplacementPlugin', (resource)=>{
6
- if (/^node:/.test(resource.request)) resource.request = resource.request.replace(/^node:/, '');
7
- });
8
- });
9
- }
10
- }
11
2
  const libs_require = createRequire(import.meta.url);
12
3
  const builtinMappingResolved = {
13
4
  assert: libs_require.resolve('assert/'),
@@ -46,6 +37,7 @@ const builtinMappingResolved = {
46
37
  tty: libs_require.resolve('tty-browserify'),
47
38
  url: libs_require.resolve('url/'),
48
39
  util: libs_require.resolve('util/util.js'),
40
+ v8: null,
49
41
  vm: libs_require.resolve('vm-browserify'),
50
42
  zlib: libs_require.resolve('browserify-zlib')
51
43
  };
@@ -54,7 +46,7 @@ const resolvedPolyfillToModules = Object.fromEntries(Object.entries(builtinMappi
54
46
  key
55
47
  ]));
56
48
  const resolvePolyfill = (libPath, overrides)=>{
57
- if ((null == overrides ? void 0 : overrides[libPath]) !== void 0) return overrides[libPath];
49
+ if (overrides?.[libPath] !== void 0) return overrides[libPath];
58
50
  return builtinMappingResolved[libPath];
59
51
  };
60
52
  const getResolveFallback = ({ protocolImports, exclude, include, overrides })=>{
@@ -112,7 +104,7 @@ function pluginNodePolyfill(options = {}) {
112
104
  return {
113
105
  name: PLUGIN_NODE_POLYFILL_NAME,
114
106
  setup (api) {
115
- api.modifyBundlerChain(async (chain, { isServer, bundler })=>{
107
+ api.modifyBundlerChain(async (chain, { isServer, rspack })=>{
116
108
  if (isServer && !force) return;
117
109
  chain.resolve.fallback.merge(getResolveFallback({
118
110
  protocolImports,
@@ -121,10 +113,18 @@ function pluginNodePolyfill(options = {}) {
121
113
  overrides
122
114
  }));
123
115
  const provideGlobals = await getProvideGlobals(options.globals, overrides);
124
- if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(bundler.ProvidePlugin, [
116
+ if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(rspack.ProvidePlugin, [
125
117
  provideGlobals
126
118
  ]);
127
- if (protocolImports) chain.plugin('protocol-imports').use(ProtocolImportsPlugin);
119
+ if (protocolImports) {
120
+ const regex = /^node:/;
121
+ chain.plugin('protocol-imports').use(rspack.NormalModuleReplacementPlugin, [
122
+ regex,
123
+ (resource)=>{
124
+ resource.request = resource.request.replace(regex, '');
125
+ }
126
+ ]);
127
+ }
128
128
  });
129
129
  }
130
130
  };
package/dist/libs.d.ts CHANGED
@@ -35,6 +35,7 @@ export declare const builtinMappingResolved: {
35
35
  readonly tty: string;
36
36
  readonly url: string;
37
37
  readonly util: string;
38
+ readonly v8: null;
38
39
  readonly vm: string;
39
40
  readonly zlib: string;
40
41
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-node-polyfill",
3
- "version": "1.4.1",
4
- "repository": "https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill",
3
+ "version": "1.4.3",
4
+ "repository": "https://github.com/rstackjs/rsbuild-plugin-node-polyfill",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "exports": {
@@ -61,26 +61,26 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@biomejs/biome": "^1.9.4",
64
- "@playwright/test": "^1.54.1",
65
- "@rsbuild/core": "^1.4.12",
66
- "@rslib/core": "^0.11.0",
67
- "@rstest/core": "0.0.10",
68
- "@types/node": "^22.17.0",
69
- "nano-staged": "^0.8.0",
70
- "playwright": "^1.54.1",
64
+ "@playwright/test": "^1.57.0",
65
+ "@rsbuild/core": "^1.6.10",
66
+ "@rslib/core": "^0.18.2",
67
+ "@rstest/core": "0.6.8",
68
+ "@types/node": "^22.19.1",
69
+ "nano-staged": "^0.9.0",
70
+ "playwright": "^1.57.0",
71
71
  "simple-git-hooks": "^2.13.1",
72
- "tsx": "^4.20.3",
73
- "typescript": "^5.9.2"
72
+ "tsx": "^4.21.0",
73
+ "typescript": "^5.9.3"
74
74
  },
75
75
  "peerDependencies": {
76
- "@rsbuild/core": "1.x"
76
+ "@rsbuild/core": "^1.0.0 || ^2.0.0-0"
77
77
  },
78
78
  "peerDependenciesMeta": {
79
79
  "@rsbuild/core": {
80
80
  "optional": true
81
81
  }
82
82
  },
83
- "packageManager": "pnpm@10.14.0",
83
+ "packageManager": "pnpm@10.24.0",
84
84
  "publishConfig": {
85
85
  "access": "public",
86
86
  "registry": "https://registry.npmjs.org/"
@@ -1,4 +0,0 @@
1
- import type { Rspack } from '@rsbuild/core';
2
- export declare class ProtocolImportsPlugin {
3
- apply(compiler: Rspack.Compiler): void;
4
- }