@rsbuild/plugin-node-polyfill 1.4.3 → 1.4.5

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
@@ -28,7 +28,7 @@ Add plugin to your `rsbuild.config.ts`:
28
28
 
29
29
  ```ts
30
30
  // rsbuild.config.ts
31
- import { pluginNodePolyfill } from "@rsbuild/plugin-node-polyfill";
31
+ import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
32
32
 
33
33
  export default {
34
34
  plugins: [pluginNodePolyfill()],
@@ -47,7 +47,7 @@ When you use the above global variables in your code, the corresponding polyfill
47
47
  For instance, the following code would inject the `Buffer` polyfill:
48
48
 
49
49
  ```ts
50
- const bufferData = Buffer.from("abc");
50
+ const bufferData = Buffer.from('abc');
51
51
  ```
52
52
 
53
53
  You can disable this behavior through the `globals` option of the plugin:
@@ -95,9 +95,9 @@ pluginNodePolyfill({
95
95
  When the above module is referenced in code via import / require syntax, the corresponding polyfill will be injected.
96
96
 
97
97
  ```ts
98
- import { Buffer } from "buffer";
98
+ import { Buffer } from 'buffer';
99
99
 
100
- const bufferData = Buffer.from("abc");
100
+ const bufferData = Buffer.from('abc');
101
101
  ```
102
102
 
103
103
  ### Fallbacks
@@ -117,7 +117,7 @@ const bufferData = Buffer.from("abc");
117
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.
118
118
 
119
119
  ```ts
120
- import fs from "fs";
120
+ import fs from 'fs';
121
121
 
122
122
  console.log(fs); // -> {}
123
123
  ```
@@ -210,7 +210,7 @@ Specify an array of modules for which polyfills should be injected. If this opti
210
210
 
211
211
  ```ts
212
212
  pluginNodePolyfill({
213
- include: ["buffer", "crypto"], // Only "buffer" and "crypto" modules will be polyfilled.
213
+ include: ['buffer', 'crypto'], // Only "buffer" and "crypto" modules will be polyfilled.
214
214
  });
215
215
  ```
216
216
 
@@ -223,7 +223,7 @@ Specify an array of modules for which polyfills should not be injected from the
223
223
 
224
224
  ```ts
225
225
  pluginNodePolyfill({
226
- exclude: ["http", "https"], // All modules except "http" and "https" will be polyfilled.
226
+ exclude: ['http', 'https'], // All modules except "http" and "https" will be polyfilled.
227
227
  });
228
228
  ```
229
229
 
@@ -237,7 +237,7 @@ Override the default polyfills for specific modules.
237
237
  ```ts
238
238
  pluginNodePolyfill({
239
239
  overrides: {
240
- fs: "memfs",
240
+ fs: 'memfs',
241
241
  },
242
242
  });
243
243
  ```
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,13 +27,13 @@ var __webpack_require__ = {};
27
27
  var __webpack_exports__ = {};
28
28
  __webpack_require__.r(__webpack_exports__);
29
29
  __webpack_require__.d(__webpack_exports__, {
30
- getResolveFallback: ()=>getResolveFallback,
31
30
  PLUGIN_NODE_POLYFILL_NAME: ()=>PLUGIN_NODE_POLYFILL_NAME,
31
+ builtinMappingResolved: ()=>builtinMappingResolved,
32
32
  getProvideGlobals: ()=>getProvideGlobals,
33
+ getResolveFallback: ()=>getResolveFallback,
33
34
  pluginNodePolyfill: ()=>pluginNodePolyfill,
34
35
  resolvePolyfill: ()=>resolvePolyfill,
35
- resolvedPolyfillToModules: ()=>resolvedPolyfillToModules,
36
- builtinMappingResolved: ()=>builtinMappingResolved
36
+ resolvedPolyfillToModules: ()=>resolvedPolyfillToModules
37
37
  });
38
38
  const external_node_module_namespaceObject = require("node:module");
39
39
  const libs_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
@@ -141,7 +141,7 @@ function pluginNodePolyfill(options = {}) {
141
141
  return {
142
142
  name: PLUGIN_NODE_POLYFILL_NAME,
143
143
  setup (api) {
144
- api.modifyBundlerChain(async (chain, { isServer, rspack })=>{
144
+ api.modifyBundlerChain(async (chain, { isServer, bundler, rspack })=>{
145
145
  if (isServer && !force) return;
146
146
  chain.resolve.fallback.merge(getResolveFallback({
147
147
  protocolImports,
@@ -150,10 +150,10 @@ function pluginNodePolyfill(options = {}) {
150
150
  overrides
151
151
  }));
152
152
  const provideGlobals = await getProvideGlobals(options.globals, overrides);
153
- if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(rspack.ProvidePlugin, [
153
+ if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(bundler.ProvidePlugin, [
154
154
  provideGlobals
155
155
  ]);
156
- if (protocolImports) {
156
+ if (protocolImports && 'rspack' === api.context.bundlerType) {
157
157
  const regex = /^node:/;
158
158
  chain.plugin('protocol-imports').use(rspack.NormalModuleReplacementPlugin, [
159
159
  regex,
@@ -173,7 +173,7 @@ exports.getResolveFallback = __webpack_exports__.getResolveFallback;
173
173
  exports.pluginNodePolyfill = __webpack_exports__.pluginNodePolyfill;
174
174
  exports.resolvePolyfill = __webpack_exports__.resolvePolyfill;
175
175
  exports.resolvedPolyfillToModules = __webpack_exports__.resolvedPolyfillToModules;
176
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
176
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
177
177
  "PLUGIN_NODE_POLYFILL_NAME",
178
178
  "builtinMappingResolved",
179
179
  "getProvideGlobals",
@@ -181,7 +181,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
181
181
  "pluginNodePolyfill",
182
182
  "resolvePolyfill",
183
183
  "resolvedPolyfillToModules"
184
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
184
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
185
185
  Object.defineProperty(exports, '__esModule', {
186
186
  value: true
187
187
  });
package/dist/index.d.ts CHANGED
@@ -89,4 +89,4 @@ export declare const getResolveFallback: ({ protocolImports, exclude, include, o
89
89
  export declare const getProvideGlobals: (globals?: Globals, overrides?: PluginNodePolyfillOptions["overrides"]) => Promise<Record<string, string | string[]>>;
90
90
  export declare const PLUGIN_NODE_POLYFILL_NAME = "rsbuild:node-polyfill";
91
91
  export declare function pluginNodePolyfill(options?: PluginNodePolyfillOptions): RsbuildPlugin;
92
- export { builtinMappingResolved, resolvedPolyfillToModules, } from './libs.js';
92
+ export { builtinMappingResolved, resolvedPolyfillToModules } from './libs.js';
package/dist/index.js CHANGED
@@ -104,7 +104,7 @@ function pluginNodePolyfill(options = {}) {
104
104
  return {
105
105
  name: PLUGIN_NODE_POLYFILL_NAME,
106
106
  setup (api) {
107
- api.modifyBundlerChain(async (chain, { isServer, rspack })=>{
107
+ api.modifyBundlerChain(async (chain, { isServer, bundler, rspack })=>{
108
108
  if (isServer && !force) return;
109
109
  chain.resolve.fallback.merge(getResolveFallback({
110
110
  protocolImports,
@@ -113,10 +113,10 @@ function pluginNodePolyfill(options = {}) {
113
113
  overrides
114
114
  }));
115
115
  const provideGlobals = await getProvideGlobals(options.globals, overrides);
116
- if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(rspack.ProvidePlugin, [
116
+ if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(bundler.ProvidePlugin, [
117
117
  provideGlobals
118
118
  ]);
119
- if (protocolImports) {
119
+ if (protocolImports && 'rspack' === api.context.bundlerType) {
120
120
  const regex = /^node:/;
121
121
  chain.plugin('protocol-imports').use(rspack.NormalModuleReplacementPlugin, [
122
122
  regex,
package/package.json CHANGED
@@ -1,88 +1,83 @@
1
1
  {
2
- "name": "@rsbuild/plugin-node-polyfill",
3
- "version": "1.4.3",
4
- "repository": "https://github.com/rstackjs/rsbuild-plugin-node-polyfill",
5
- "license": "MIT",
6
- "type": "module",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/index.d.ts",
10
- "import": "./dist/index.js",
11
- "require": "./dist/index.cjs"
12
- }
13
- },
14
- "main": "./dist/index.cjs",
15
- "module": "./dist/index.js",
16
- "types": "./dist/index.d.ts",
17
- "files": ["dist"],
18
- "scripts": {
19
- "build": "rslib build",
20
- "dev": "rslib build --watch",
21
- "lint": "biome check .",
22
- "lint:write": "biome check . --write",
23
- "prepare": "simple-git-hooks && npm run build",
24
- "test": "pnpm run /^test:/",
25
- "test:e2e": "playwright test",
26
- "test:unit": "rstest run",
27
- "bump": "npx bumpp"
28
- },
29
- "simple-git-hooks": {
30
- "pre-commit": "npx nano-staged"
31
- },
32
- "nano-staged": {
33
- "*.{js,jsx,ts,tsx,mjs,cjs}": [
34
- "biome check --write --no-errors-on-unmatched"
35
- ]
36
- },
37
- "dependencies": {
38
- "assert": "^2.1.0",
39
- "browserify-zlib": "^0.2.0",
40
- "buffer": "^5.7.1",
41
- "console-browserify": "^1.2.0",
42
- "constants-browserify": "^1.0.0",
43
- "crypto-browserify": "^3.12.1",
44
- "domain-browser": "^5.7.0",
45
- "events": "^3.3.0",
46
- "https-browserify": "^1.0.0",
47
- "os-browserify": "^0.3.0",
48
- "path-browserify": "^1.0.1",
49
- "process": "^0.11.10",
50
- "punycode": "^2.3.1",
51
- "querystring-es3": "^0.2.1",
52
- "readable-stream": "^4.7.0",
53
- "stream-browserify": "^3.0.0",
54
- "stream-http": "^3.2.0",
55
- "string_decoder": "^1.3.0",
56
- "timers-browserify": "^2.0.12",
57
- "tty-browserify": "^0.0.1",
58
- "url": "^0.11.4",
59
- "util": "^0.12.5",
60
- "vm-browserify": "^1.1.2"
61
- },
62
- "devDependencies": {
63
- "@biomejs/biome": "^1.9.4",
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
- "simple-git-hooks": "^2.13.1",
72
- "tsx": "^4.21.0",
73
- "typescript": "^5.9.3"
74
- },
75
- "peerDependencies": {
76
- "@rsbuild/core": "^1.0.0 || ^2.0.0-0"
77
- },
78
- "peerDependenciesMeta": {
79
- "@rsbuild/core": {
80
- "optional": true
81
- }
82
- },
83
- "packageManager": "pnpm@10.24.0",
84
- "publishConfig": {
85
- "access": "public",
86
- "registry": "https://registry.npmjs.org/"
87
- }
88
- }
2
+ "name": "@rsbuild/plugin-node-polyfill",
3
+ "version": "1.4.5",
4
+ "repository": "https://github.com/rstackjs/rsbuild-plugin-node-polyfill",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
12
+ }
13
+ },
14
+ "main": "./dist/index.cjs",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "simple-git-hooks": {
21
+ "pre-commit": "pnpm run lint:write"
22
+ },
23
+ "dependencies": {
24
+ "assert": "^2.1.0",
25
+ "browserify-zlib": "^0.2.0",
26
+ "buffer": "^5.7.1",
27
+ "console-browserify": "^1.2.0",
28
+ "constants-browserify": "^1.0.0",
29
+ "crypto-browserify": "^3.12.1",
30
+ "domain-browser": "^5.7.0",
31
+ "events": "^3.3.0",
32
+ "https-browserify": "^1.0.0",
33
+ "os-browserify": "^0.3.0",
34
+ "path-browserify": "^1.0.1",
35
+ "process": "^0.11.10",
36
+ "punycode": "^2.3.1",
37
+ "querystring-es3": "^0.2.1",
38
+ "readable-stream": "^4.7.0",
39
+ "stream-browserify": "^3.0.0",
40
+ "stream-http": "^3.2.0",
41
+ "string_decoder": "^1.3.0",
42
+ "timers-browserify": "^2.0.12",
43
+ "tty-browserify": "^0.0.1",
44
+ "url": "^0.11.4",
45
+ "util": "^0.12.5",
46
+ "vm-browserify": "^1.1.2"
47
+ },
48
+ "devDependencies": {
49
+ "@playwright/test": "^1.60.0",
50
+ "@rsbuild/core": "^2.0.7",
51
+ "@rslib/core": "^0.21.5",
52
+ "@rslint/core": "^0.5.3",
53
+ "@rstest/core": "0.10.2",
54
+ "@types/node": "^24.12.4",
55
+ "playwright": "^1.60.0",
56
+ "prettier": "^3.8.3",
57
+ "simple-git-hooks": "^2.13.1",
58
+ "tsx": "^4.22.3",
59
+ "typescript": "6.0.3"
60
+ },
61
+ "peerDependencies": {
62
+ "@rsbuild/core": "^1.0.0 || ^2.0.0-0"
63
+ },
64
+ "peerDependenciesMeta": {
65
+ "@rsbuild/core": {
66
+ "optional": true
67
+ }
68
+ },
69
+ "publishConfig": {
70
+ "access": "public",
71
+ "registry": "https://registry.npmjs.org/"
72
+ },
73
+ "scripts": {
74
+ "build": "rslib",
75
+ "dev": "rslib -w",
76
+ "lint": "rslint && prettier -c .",
77
+ "lint:write": "rslint --fix && prettier -w .",
78
+ "test": "pnpm run /^test:/",
79
+ "test:e2e": "playwright test",
80
+ "test:unit": "rstest",
81
+ "bump": "npx bumpp"
82
+ }
83
+ }