@rsbuild/plugin-node-polyfill 1.3.0 → 1.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.
Files changed (3) hide show
  1. package/dist/index.cjs +43 -34
  2. package/dist/index.js +17 -13
  3. package/package.json +13 -12
package/dist/index.cjs CHANGED
@@ -2,27 +2,20 @@
2
2
  const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
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;
4
4
  }();
5
- // The require scope
6
5
  var __webpack_require__ = {};
7
- /************************************************************************/ // webpack/runtime/define_property_getters
8
6
  (()=>{
9
- __webpack_require__.d = function(exports1, definition) {
7
+ __webpack_require__.d = (exports1, definition)=>{
10
8
  for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
11
9
  enumerable: true,
12
10
  get: definition[key]
13
11
  });
14
12
  };
15
13
  })();
16
- // webpack/runtime/has_own_property
17
14
  (()=>{
18
- __webpack_require__.o = function(obj, prop) {
19
- return Object.prototype.hasOwnProperty.call(obj, prop);
20
- };
15
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
21
16
  })();
22
- // webpack/runtime/make_namespace_object
23
17
  (()=>{
24
- // define __esModule on exports
25
- __webpack_require__.r = function(exports1) {
18
+ __webpack_require__.r = (exports1)=>{
26
19
  if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
27
20
  value: 'Module'
28
21
  });
@@ -31,25 +24,21 @@ var __webpack_require__ = {};
31
24
  });
32
25
  };
33
26
  })();
34
- /************************************************************************/ var __webpack_exports__ = {};
35
- // ESM COMPAT FLAG
27
+ var __webpack_exports__ = {};
36
28
  __webpack_require__.r(__webpack_exports__);
37
- // EXPORTS
38
29
  __webpack_require__.d(__webpack_exports__, {
39
- PLUGIN_NODE_POLYFILL_NAME: ()=>/* binding */ PLUGIN_NODE_POLYFILL_NAME,
40
- resolvedPolyfillToModules: ()=>/* reexport */ resolvedPolyfillToModules,
41
- builtinMappingResolved: ()=>/* reexport */ builtinMappingResolved,
42
- getResolveFallback: ()=>/* binding */ getResolveFallback,
43
- pluginNodePolyfill: ()=>/* binding */ pluginNodePolyfill,
44
- resolvePolyfill: ()=>/* binding */ resolvePolyfill,
45
- getProvideGlobals: ()=>/* binding */ getProvideGlobals
30
+ getProvideGlobals: ()=>getProvideGlobals,
31
+ PLUGIN_NODE_POLYFILL_NAME: ()=>PLUGIN_NODE_POLYFILL_NAME,
32
+ getResolveFallback: ()=>getResolveFallback,
33
+ pluginNodePolyfill: ()=>pluginNodePolyfill,
34
+ resolvePolyfill: ()=>resolvePolyfill,
35
+ resolvedPolyfillToModules: ()=>resolvedPolyfillToModules,
36
+ builtinMappingResolved: ()=>builtinMappingResolved
46
37
  });
47
38
  class ProtocolImportsPlugin {
48
39
  apply(compiler) {
49
40
  compiler.hooks.normalModuleFactory.tap('NormalModuleReplacementPlugin', (nmf)=>{
50
41
  nmf.hooks.beforeResolve.tap('NormalModuleReplacementPlugin', (resource)=>{
51
- // Remove the `node:` prefix
52
- // see: https://github.com/webpack/webpack/issues/14166
53
42
  if (/^node:/.test(resource.request)) resource.request = resource.request.replace(/^node:/, '');
54
43
  });
55
44
  });
@@ -118,13 +107,21 @@ const getResolveFallback = ({ protocolImports, exclude, include, overrides })=>{
118
107
  };
119
108
  const getProvideGlobals = async (globals, overrides)=>{
120
109
  const result = {};
121
- if ((null == globals ? void 0 : globals.Buffer) !== false) result.Buffer = [
122
- resolvePolyfill('buffer', overrides),
123
- 'Buffer'
124
- ];
125
- if ((null == globals ? void 0 : globals.process) !== false) result.process = [
126
- resolvePolyfill('process', overrides)
127
- ];
110
+ if ((null == globals ? void 0 : globals.Buffer) !== false) {
111
+ result.Buffer = [
112
+ resolvePolyfill('buffer', overrides),
113
+ 'Buffer'
114
+ ];
115
+ result['global.Buffer'] = result.Buffer;
116
+ result['globalThis.Buffer'] = result.Buffer;
117
+ }
118
+ if ((null == globals ? void 0 : globals.process) !== false) {
119
+ result.process = [
120
+ resolvePolyfill('process', overrides)
121
+ ];
122
+ result['global.process'] = result.process;
123
+ result['globalThis.process'] = result.process;
124
+ }
128
125
  return result;
129
126
  };
130
127
  const PLUGIN_NODE_POLYFILL_NAME = 'rsbuild:node-polyfill';
@@ -134,9 +131,7 @@ function pluginNodePolyfill(options = {}) {
134
131
  name: PLUGIN_NODE_POLYFILL_NAME,
135
132
  setup (api) {
136
133
  api.modifyBundlerChain(async (chain, { isServer, bundler })=>{
137
- // The server bundle does not require node polyfill
138
134
  if (isServer && !force) return;
139
- // module polyfill
140
135
  chain.resolve.fallback.merge(getResolveFallback({
141
136
  protocolImports,
142
137
  include: include,
@@ -152,8 +147,22 @@ function pluginNodePolyfill(options = {}) {
152
147
  }
153
148
  };
154
149
  }
155
- var __webpack_export_target__ = exports;
156
- for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
157
- if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
150
+ exports.PLUGIN_NODE_POLYFILL_NAME = __webpack_exports__.PLUGIN_NODE_POLYFILL_NAME;
151
+ exports.builtinMappingResolved = __webpack_exports__.builtinMappingResolved;
152
+ exports.getProvideGlobals = __webpack_exports__.getProvideGlobals;
153
+ exports.getResolveFallback = __webpack_exports__.getResolveFallback;
154
+ exports.pluginNodePolyfill = __webpack_exports__.pluginNodePolyfill;
155
+ exports.resolvePolyfill = __webpack_exports__.resolvePolyfill;
156
+ exports.resolvedPolyfillToModules = __webpack_exports__.resolvedPolyfillToModules;
157
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
158
+ "PLUGIN_NODE_POLYFILL_NAME",
159
+ "builtinMappingResolved",
160
+ "getProvideGlobals",
161
+ "getResolveFallback",
162
+ "pluginNodePolyfill",
163
+ "resolvePolyfill",
164
+ "resolvedPolyfillToModules"
165
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
166
+ Object.defineProperty(exports, '__esModule', {
158
167
  value: true
159
168
  });
package/dist/index.js CHANGED
@@ -1,16 +1,14 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
1
+ import { createRequire } from "node:module";
2
2
  class ProtocolImportsPlugin {
3
3
  apply(compiler) {
4
4
  compiler.hooks.normalModuleFactory.tap('NormalModuleReplacementPlugin', (nmf)=>{
5
5
  nmf.hooks.beforeResolve.tap('NormalModuleReplacementPlugin', (resource)=>{
6
- // Remove the `node:` prefix
7
- // see: https://github.com/webpack/webpack/issues/14166
8
6
  if (/^node:/.test(resource.request)) resource.request = resource.request.replace(/^node:/, '');
9
7
  });
10
8
  });
11
9
  }
12
10
  }
13
- const libs_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url);
11
+ const libs_require = createRequire(import.meta.url);
14
12
  const builtinMappingResolved = {
15
13
  assert: libs_require.resolve('assert/'),
16
14
  buffer: libs_require.resolve('buffer/'),
@@ -72,13 +70,21 @@ const getResolveFallback = ({ protocolImports, exclude, include, overrides })=>{
72
70
  };
73
71
  const getProvideGlobals = async (globals, overrides)=>{
74
72
  const result = {};
75
- if ((null == globals ? void 0 : globals.Buffer) !== false) result.Buffer = [
76
- resolvePolyfill('buffer', overrides),
77
- 'Buffer'
78
- ];
79
- if ((null == globals ? void 0 : globals.process) !== false) result.process = [
80
- resolvePolyfill('process', overrides)
81
- ];
73
+ if ((null == globals ? void 0 : globals.Buffer) !== false) {
74
+ result.Buffer = [
75
+ resolvePolyfill('buffer', overrides),
76
+ 'Buffer'
77
+ ];
78
+ result['global.Buffer'] = result.Buffer;
79
+ result['globalThis.Buffer'] = result.Buffer;
80
+ }
81
+ if ((null == globals ? void 0 : globals.process) !== false) {
82
+ result.process = [
83
+ resolvePolyfill('process', overrides)
84
+ ];
85
+ result['global.process'] = result.process;
86
+ result['globalThis.process'] = result.process;
87
+ }
82
88
  return result;
83
89
  };
84
90
  const PLUGIN_NODE_POLYFILL_NAME = 'rsbuild:node-polyfill';
@@ -88,9 +94,7 @@ function pluginNodePolyfill(options = {}) {
88
94
  name: PLUGIN_NODE_POLYFILL_NAME,
89
95
  setup (api) {
90
96
  api.modifyBundlerChain(async (chain, { isServer, bundler })=>{
91
- // The server bundle does not require node polyfill
92
97
  if (isServer && !force) return;
93
- // module polyfill
94
98
  chain.resolve.fallback.merge(getResolveFallback({
95
99
  protocolImports,
96
100
  include: include,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-node-polyfill",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "repository": "https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "prepare": "simple-git-hooks && npm run build",
24
24
  "test": "pnpm run /^test:/",
25
25
  "test:e2e": "playwright test",
26
- "test:unit": "vitest run",
26
+ "test:unit": "rstest run",
27
27
  "bump": "npx bumpp"
28
28
  },
29
29
  "simple-git-hooks": {
@@ -49,7 +49,7 @@
49
49
  "process": "^0.11.10",
50
50
  "punycode": "^2.3.1",
51
51
  "querystring-es3": "^0.2.1",
52
- "readable-stream": "^4.5.2",
52
+ "readable-stream": "^4.7.0",
53
53
  "stream-browserify": "^3.0.0",
54
54
  "stream-http": "^3.2.0",
55
55
  "string_decoder": "^1.3.0",
@@ -61,15 +61,16 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@biomejs/biome": "^1.9.4",
64
- "@playwright/test": "^1.49.0",
65
- "@rsbuild/core": "^1.1.6",
66
- "@rslib/core": "^0.1.1",
67
- "@types/node": "^22.10.1",
64
+ "@playwright/test": "^1.53.2",
65
+ "@rsbuild/core": "^1.4.4",
66
+ "@rslib/core": "^0.10.4",
67
+ "@rstest/core": "0.0.6",
68
+ "@types/node": "^22.16.0",
68
69
  "nano-staged": "^0.8.0",
69
- "playwright": "^1.49.0",
70
- "simple-git-hooks": "^2.11.1",
71
- "typescript": "^5.7.2",
72
- "vitest": "^2.1.6"
70
+ "playwright": "^1.53.2",
71
+ "simple-git-hooks": "^2.13.0",
72
+ "tsx": "^4.20.3",
73
+ "typescript": "^5.8.3"
73
74
  },
74
75
  "peerDependencies": {
75
76
  "@rsbuild/core": "1.x"
@@ -79,7 +80,7 @@
79
80
  "optional": true
80
81
  }
81
82
  },
82
- "packageManager": "pnpm@9.14.4",
83
+ "packageManager": "pnpm@10.12.4",
83
84
  "publishConfig": {
84
85
  "access": "public",
85
86
  "registry": "https://registry.npmjs.org/"