@rsbuild/plugin-node-polyfill 1.4.2 → 1.4.4

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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
- return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
3
+ return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
4
  }();
5
5
  var __webpack_require__ = {};
6
6
  (()=>{
@@ -16,7 +16,7 @@ var __webpack_require__ = {};
16
16
  })();
17
17
  (()=>{
18
18
  __webpack_require__.r = (exports1)=>{
19
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
19
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
20
20
  value: 'Module'
21
21
  });
22
22
  Object.defineProperty(exports1, '__esModule', {
@@ -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, bundler, rspack })=>{
154
145
  if (isServer && !force) return;
155
146
  chain.resolve.fallback.merge(getResolveFallback({
156
147
  protocolImports,
@@ -162,7 +153,15 @@ function pluginNodePolyfill(options = {}) {
162
153
  if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(bundler.ProvidePlugin, [
163
154
  provideGlobals
164
155
  ]);
165
- if (protocolImports) chain.plugin('protocol-imports').use(ProtocolImportsPlugin);
156
+ if (protocolImports && 'rspack' === api.context.bundlerType) {
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
  };
@@ -174,7 +173,7 @@ exports.getResolveFallback = __webpack_exports__.getResolveFallback;
174
173
  exports.pluginNodePolyfill = __webpack_exports__.pluginNodePolyfill;
175
174
  exports.resolvePolyfill = __webpack_exports__.resolvePolyfill;
176
175
  exports.resolvedPolyfillToModules = __webpack_exports__.resolvedPolyfillToModules;
177
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
176
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
178
177
  "PLUGIN_NODE_POLYFILL_NAME",
179
178
  "builtinMappingResolved",
180
179
  "getProvideGlobals",
@@ -182,7 +181,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
182
181
  "pluginNodePolyfill",
183
182
  "resolvePolyfill",
184
183
  "resolvedPolyfillToModules"
185
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
184
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
186
185
  Object.defineProperty(exports, '__esModule', {
187
186
  value: true
188
187
  });
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, bundler, rspack })=>{
117
108
  if (isServer && !force) return;
118
109
  chain.resolve.fallback.merge(getResolveFallback({
119
110
  protocolImports,
@@ -125,7 +116,15 @@ function pluginNodePolyfill(options = {}) {
125
116
  if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(bundler.ProvidePlugin, [
126
117
  provideGlobals
127
118
  ]);
128
- if (protocolImports) chain.plugin('protocol-imports').use(ProtocolImportsPlugin);
119
+ if (protocolImports && 'rspack' === api.context.bundlerType) {
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.4",
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.58.1",
65
+ "@rsbuild/core": "^1.7.2",
66
+ "@rslib/core": "^0.19.4",
67
+ "@rstest/core": "0.8.1",
68
+ "@types/node": "^24.10.9",
69
+ "nano-staged": "^0.9.0",
70
+ "playwright": "^1.58.1",
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.28.2",
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
- }