@rsbuild/plugin-node-polyfill 1.4.2 → 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/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 = {
@@ -92,7 +83,7 @@ const resolvedPolyfillToModules = Object.fromEntries(Object.entries(builtinMappi
92
83
  key
93
84
  ]));
94
85
  const resolvePolyfill = (libPath, overrides)=>{
95
- if ((null == overrides ? void 0 : overrides[libPath]) !== void 0) return overrides[libPath];
86
+ if (overrides?.[libPath] !== void 0) return overrides[libPath];
96
87
  return builtinMappingResolved[libPath];
97
88
  };
98
89
  const getResolveFallback = ({ protocolImports, exclude, include, overrides })=>{
@@ -150,7 +141,7 @@ function pluginNodePolyfill(options = {}) {
150
141
  return {
151
142
  name: PLUGIN_NODE_POLYFILL_NAME,
152
143
  setup (api) {
153
- api.modifyBundlerChain(async (chain, { isServer, bundler })=>{
144
+ api.modifyBundlerChain(async (chain, { isServer, rspack })=>{
154
145
  if (isServer && !force) return;
155
146
  chain.resolve.fallback.merge(getResolveFallback({
156
147
  protocolImports,
@@ -159,10 +150,18 @@ function pluginNodePolyfill(options = {}) {
159
150
  overrides
160
151
  }));
161
152
  const provideGlobals = await getProvideGlobals(options.globals, overrides);
162
- 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, [
163
154
  provideGlobals
164
155
  ]);
165
- 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
+ }
166
165
  });
167
166
  }
168
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/'),
@@ -55,7 +46,7 @@ const resolvedPolyfillToModules = Object.fromEntries(Object.entries(builtinMappi
55
46
  key
56
47
  ]));
57
48
  const resolvePolyfill = (libPath, overrides)=>{
58
- if ((null == overrides ? void 0 : overrides[libPath]) !== void 0) return overrides[libPath];
49
+ if (overrides?.[libPath] !== void 0) return overrides[libPath];
59
50
  return builtinMappingResolved[libPath];
60
51
  };
61
52
  const getResolveFallback = ({ protocolImports, exclude, include, overrides })=>{
@@ -113,7 +104,7 @@ function pluginNodePolyfill(options = {}) {
113
104
  return {
114
105
  name: PLUGIN_NODE_POLYFILL_NAME,
115
106
  setup (api) {
116
- api.modifyBundlerChain(async (chain, { isServer, bundler })=>{
107
+ api.modifyBundlerChain(async (chain, { isServer, rspack })=>{
117
108
  if (isServer && !force) return;
118
109
  chain.resolve.fallback.merge(getResolveFallback({
119
110
  protocolImports,
@@ -122,10 +113,18 @@ function pluginNodePolyfill(options = {}) {
122
113
  overrides
123
114
  }));
124
115
  const provideGlobals = await getProvideGlobals(options.globals, overrides);
125
- 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, [
126
117
  provideGlobals
127
118
  ]);
128
- 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
+ }
129
128
  });
130
129
  }
131
130
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-node-polyfill",
3
- "version": "1.4.2",
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.55.0",
65
- "@rsbuild/core": "^1.4.15",
66
- "@rslib/core": "^0.12.2",
67
- "@rstest/core": "0.2.2",
68
- "@types/node": "^22.17.2",
69
- "nano-staged": "^0.8.0",
70
- "playwright": "^1.55.0",
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.4",
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.15.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
- }