@rsbuild/plugin-node-polyfill 1.2.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.
- package/README.md +32 -19
- package/dist/ProtocolImportsPlugin.d.ts +4 -0
- package/dist/index.cjs +157 -176
- package/dist/index.d.ts +15 -52
- package/dist/index.js +104 -141
- package/dist/libs.d.ts +41 -0
- package/package.json +17 -16
- package/dist/index.d.cts +0 -89
package/README.md
CHANGED
|
@@ -28,11 +28,11 @@ Add plugin to your `rsbuild.config.ts`:
|
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
30
|
// rsbuild.config.ts
|
|
31
|
-
import { pluginNodePolyfill } from
|
|
31
|
+
import { pluginNodePolyfill } from "@rsbuild/plugin-node-polyfill";
|
|
32
32
|
|
|
33
33
|
export default {
|
|
34
34
|
plugins: [pluginNodePolyfill()],
|
|
35
|
-
}
|
|
35
|
+
};
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
## Node Polyfills
|
|
@@ -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(
|
|
50
|
+
const bufferData = Buffer.from("abc");
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
You can disable this behavior through the `globals` option of the plugin:
|
|
@@ -58,7 +58,7 @@ pluginNodePolyfill({
|
|
|
58
58
|
Buffer: false,
|
|
59
59
|
process: false,
|
|
60
60
|
},
|
|
61
|
-
})
|
|
61
|
+
});
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
### Modules
|
|
@@ -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
|
|
98
|
+
import { Buffer } from "buffer";
|
|
99
99
|
|
|
100
|
-
const bufferData = Buffer.from(
|
|
100
|
+
const bufferData = Buffer.from("abc");
|
|
101
101
|
```
|
|
102
102
|
|
|
103
103
|
### Fallbacks
|
|
@@ -116,9 +116,9 @@ const bufferData = Buffer.from('abc')
|
|
|
116
116
|
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
117
|
|
|
118
118
|
```ts
|
|
119
|
-
import fs from
|
|
119
|
+
import fs from "fs";
|
|
120
120
|
|
|
121
|
-
console.log(fs) // -> {}
|
|
121
|
+
console.log(fs); // -> {}
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
## Options
|
|
@@ -131,9 +131,9 @@ Used to specify whether to inject polyfills for global variables.
|
|
|
131
131
|
|
|
132
132
|
```ts
|
|
133
133
|
type Globals = {
|
|
134
|
-
process?: boolean
|
|
135
|
-
Buffer?: boolean
|
|
136
|
-
}
|
|
134
|
+
process?: boolean;
|
|
135
|
+
Buffer?: boolean;
|
|
136
|
+
};
|
|
137
137
|
```
|
|
138
138
|
|
|
139
139
|
- **Default:**
|
|
@@ -142,7 +142,7 @@ type Globals = {
|
|
|
142
142
|
const defaultGlobals = {
|
|
143
143
|
Buffer: true,
|
|
144
144
|
process: true,
|
|
145
|
-
}
|
|
145
|
+
};
|
|
146
146
|
```
|
|
147
147
|
|
|
148
148
|
### protocolImports
|
|
@@ -157,7 +157,7 @@ For example, if you disable `protocolImports`, modules such as `node:path`, `nod
|
|
|
157
157
|
```ts
|
|
158
158
|
pluginNodePolyfill({
|
|
159
159
|
protocolImports: false,
|
|
160
|
-
})
|
|
160
|
+
});
|
|
161
161
|
```
|
|
162
162
|
|
|
163
163
|
### include
|
|
@@ -169,8 +169,8 @@ Specify an array of modules for which polyfills should be injected. If this opti
|
|
|
169
169
|
|
|
170
170
|
```ts
|
|
171
171
|
pluginNodePolyfill({
|
|
172
|
-
include: [
|
|
173
|
-
})
|
|
172
|
+
include: ["buffer", "crypto"], // Only "buffer" and "crypto" modules will be polyfilled.
|
|
173
|
+
});
|
|
174
174
|
```
|
|
175
175
|
|
|
176
176
|
### exclude
|
|
@@ -182,8 +182,8 @@ Specify an array of modules for which polyfills should not be injected from the
|
|
|
182
182
|
|
|
183
183
|
```ts
|
|
184
184
|
pluginNodePolyfill({
|
|
185
|
-
exclude: [
|
|
186
|
-
})
|
|
185
|
+
exclude: ["http", "https"], // All modules except "http" and "https" will be polyfilled.
|
|
186
|
+
});
|
|
187
187
|
```
|
|
188
188
|
|
|
189
189
|
### overrides
|
|
@@ -196,9 +196,22 @@ Override the default polyfills for specific modules.
|
|
|
196
196
|
```ts
|
|
197
197
|
pluginNodePolyfill({
|
|
198
198
|
overrides: {
|
|
199
|
-
fs:
|
|
199
|
+
fs: "memfs",
|
|
200
200
|
},
|
|
201
|
-
})
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### force
|
|
205
|
+
|
|
206
|
+
By default, the plugin only polyfills the browser-side code. If you want to polyfill the server-side code as well (when `output.target` is `node`), you can set the `force` option to `true`.
|
|
207
|
+
|
|
208
|
+
- **Type:** `boolean`
|
|
209
|
+
- **Default:** `false`
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
pluginNodePolyfill({
|
|
213
|
+
force: true,
|
|
214
|
+
});
|
|
202
215
|
```
|
|
203
216
|
|
|
204
217
|
## Exported variables
|
package/dist/index.cjs
CHANGED
|
@@ -1,187 +1,168 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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;
|
|
4
|
+
}();
|
|
5
|
+
var __webpack_require__ = {};
|
|
6
|
+
(()=>{
|
|
7
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
8
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: definition[key]
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
16
|
+
})();
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.r = (exports1)=>{
|
|
19
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
20
|
+
value: 'Module'
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
})();
|
|
27
|
+
var __webpack_exports__ = {};
|
|
28
|
+
__webpack_require__.r(__webpack_exports__);
|
|
29
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
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
|
|
30
37
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
readline: null,
|
|
82
|
-
repl: null,
|
|
83
|
-
stream: require2.resolve("stream-browserify"),
|
|
84
|
-
_stream_duplex: require2.resolve("readable-stream/lib/_stream_duplex.js"),
|
|
85
|
-
_stream_passthrough: require2.resolve(
|
|
86
|
-
"readable-stream/lib/_stream_passthrough.js"
|
|
87
|
-
),
|
|
88
|
-
_stream_readable: require2.resolve("readable-stream/lib/_stream_readable.js"),
|
|
89
|
-
_stream_transform: require2.resolve(
|
|
90
|
-
"readable-stream/lib/_stream_transform.js"
|
|
91
|
-
),
|
|
92
|
-
_stream_writable: require2.resolve("readable-stream/lib/_stream_writable.js"),
|
|
93
|
-
string_decoder: require2.resolve("string_decoder/"),
|
|
94
|
-
sys: require2.resolve("util/util.js"),
|
|
95
|
-
timers: require2.resolve("timers-browserify"),
|
|
96
|
-
tls: null,
|
|
97
|
-
tty: require2.resolve("tty-browserify"),
|
|
98
|
-
url: require2.resolve("url/"),
|
|
99
|
-
util: require2.resolve("util/util.js"),
|
|
100
|
-
vm: require2.resolve("vm-browserify"),
|
|
101
|
-
zlib: require2.resolve("browserify-zlib")
|
|
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
|
+
const external_node_module_namespaceObject = require("node:module");
|
|
48
|
+
const libs_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
49
|
+
const builtinMappingResolved = {
|
|
50
|
+
assert: libs_require.resolve('assert/'),
|
|
51
|
+
buffer: libs_require.resolve('buffer/'),
|
|
52
|
+
child_process: null,
|
|
53
|
+
cluster: null,
|
|
54
|
+
console: libs_require.resolve('console-browserify'),
|
|
55
|
+
constants: libs_require.resolve('constants-browserify'),
|
|
56
|
+
crypto: libs_require.resolve('crypto-browserify'),
|
|
57
|
+
dgram: null,
|
|
58
|
+
dns: null,
|
|
59
|
+
domain: libs_require.resolve('domain-browser'),
|
|
60
|
+
events: libs_require.resolve('events/'),
|
|
61
|
+
fs: null,
|
|
62
|
+
http: libs_require.resolve('stream-http'),
|
|
63
|
+
https: libs_require.resolve('https-browserify'),
|
|
64
|
+
module: null,
|
|
65
|
+
net: null,
|
|
66
|
+
os: libs_require.resolve('os-browserify/browser.js'),
|
|
67
|
+
path: libs_require.resolve('path-browserify'),
|
|
68
|
+
punycode: libs_require.resolve('punycode/'),
|
|
69
|
+
process: libs_require.resolve('process/browser.js'),
|
|
70
|
+
querystring: libs_require.resolve('querystring-es3/'),
|
|
71
|
+
readline: null,
|
|
72
|
+
repl: null,
|
|
73
|
+
stream: libs_require.resolve('stream-browserify'),
|
|
74
|
+
_stream_duplex: libs_require.resolve('readable-stream/lib/_stream_duplex.js'),
|
|
75
|
+
_stream_passthrough: libs_require.resolve('readable-stream/lib/_stream_passthrough.js'),
|
|
76
|
+
_stream_readable: libs_require.resolve('readable-stream/lib/_stream_readable.js'),
|
|
77
|
+
_stream_transform: libs_require.resolve('readable-stream/lib/_stream_transform.js'),
|
|
78
|
+
_stream_writable: libs_require.resolve('readable-stream/lib/_stream_writable.js'),
|
|
79
|
+
string_decoder: libs_require.resolve('string_decoder/'),
|
|
80
|
+
sys: libs_require.resolve('util/util.js'),
|
|
81
|
+
timers: libs_require.resolve('timers-browserify'),
|
|
82
|
+
tls: null,
|
|
83
|
+
tty: libs_require.resolve('tty-browserify'),
|
|
84
|
+
url: libs_require.resolve('url/'),
|
|
85
|
+
util: libs_require.resolve('util/util.js'),
|
|
86
|
+
vm: libs_require.resolve('vm-browserify'),
|
|
87
|
+
zlib: libs_require.resolve('browserify-zlib')
|
|
102
88
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return overrides[libPath];
|
|
111
|
-
}
|
|
112
|
-
return builtinMappingResolved[libPath];
|
|
89
|
+
const resolvedPolyfillToModules = Object.fromEntries(Object.entries(builtinMappingResolved).filter(([key])=>null !== key).map(([key, value])=>[
|
|
90
|
+
value,
|
|
91
|
+
key
|
|
92
|
+
]));
|
|
93
|
+
const resolvePolyfill = (libPath, overrides)=>{
|
|
94
|
+
if ((null == overrides ? void 0 : overrides[libPath]) !== void 0) return overrides[libPath];
|
|
95
|
+
return builtinMappingResolved[libPath];
|
|
113
96
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
const resolvedNodeLibs = include ? include : Object.keys(builtinMappingResolved).filter((name) => {
|
|
124
|
-
return !(exclude || []).includes(name);
|
|
125
|
-
});
|
|
126
|
-
const fallback = {};
|
|
127
|
-
for (const name of resolvedNodeLibs) {
|
|
128
|
-
const libPath = resolvePolyfill(name, overrides);
|
|
129
|
-
fallback[name] = libPath ?? false;
|
|
130
|
-
if (protocolImports) {
|
|
131
|
-
fallback[`node:${name}`] = fallback[name];
|
|
97
|
+
const getResolveFallback = ({ protocolImports, exclude, include, overrides })=>{
|
|
98
|
+
if (exclude && include) throw new Error('`include` is mutually exclusive with `exclude`.');
|
|
99
|
+
const resolvedNodeLibs = include ? include : Object.keys(builtinMappingResolved).filter((name)=>!(exclude || []).includes(name));
|
|
100
|
+
const fallback = {};
|
|
101
|
+
for (const name of resolvedNodeLibs){
|
|
102
|
+
const libPath = resolvePolyfill(name, overrides);
|
|
103
|
+
fallback[name] = libPath ?? false;
|
|
104
|
+
if (protocolImports) fallback[`node:${name}`] = fallback[name];
|
|
132
105
|
}
|
|
133
|
-
|
|
134
|
-
return fallback;
|
|
106
|
+
return fallback;
|
|
135
107
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
108
|
+
const getProvideGlobals = async (globals, overrides)=>{
|
|
109
|
+
const result = {};
|
|
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
|
+
}
|
|
125
|
+
return result;
|
|
145
126
|
};
|
|
146
|
-
|
|
127
|
+
const PLUGIN_NODE_POLYFILL_NAME = 'rsbuild:node-polyfill';
|
|
147
128
|
function pluginNodePolyfill(options = {}) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
overrides
|
|
167
|
-
);
|
|
168
|
-
if (Object.keys(provideGlobals).length) {
|
|
169
|
-
chain.plugin("node-polyfill-provide").use(bundler.ProvidePlugin, [provideGlobals]);
|
|
129
|
+
const { protocolImports = true, include, exclude, overrides, force = false } = options;
|
|
130
|
+
return {
|
|
131
|
+
name: PLUGIN_NODE_POLYFILL_NAME,
|
|
132
|
+
setup (api) {
|
|
133
|
+
api.modifyBundlerChain(async (chain, { isServer, bundler })=>{
|
|
134
|
+
if (isServer && !force) return;
|
|
135
|
+
chain.resolve.fallback.merge(getResolveFallback({
|
|
136
|
+
protocolImports,
|
|
137
|
+
include: include,
|
|
138
|
+
exclude,
|
|
139
|
+
overrides
|
|
140
|
+
}));
|
|
141
|
+
const provideGlobals = await getProvideGlobals(options.globals, overrides);
|
|
142
|
+
if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(bundler.ProvidePlugin, [
|
|
143
|
+
provideGlobals
|
|
144
|
+
]);
|
|
145
|
+
if (protocolImports) chain.plugin('protocol-imports').use(ProtocolImportsPlugin);
|
|
146
|
+
});
|
|
170
147
|
}
|
|
171
|
-
|
|
172
|
-
chain.plugin("protocol-imports").use(ProtocolImportsPlugin);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
};
|
|
148
|
+
};
|
|
177
149
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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', {
|
|
167
|
+
value: true
|
|
187
168
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,52 +1,9 @@
|
|
|
1
|
-
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
|
|
3
|
-
declare const builtinMappingResolved: {
|
|
4
|
-
readonly assert: string;
|
|
5
|
-
readonly buffer: string;
|
|
6
|
-
readonly child_process: null;
|
|
7
|
-
readonly cluster: null;
|
|
8
|
-
readonly console: string;
|
|
9
|
-
readonly constants: string;
|
|
10
|
-
readonly crypto: string;
|
|
11
|
-
readonly dgram: null;
|
|
12
|
-
readonly dns: null;
|
|
13
|
-
readonly domain: string;
|
|
14
|
-
readonly events: string;
|
|
15
|
-
readonly fs: null;
|
|
16
|
-
readonly http: string;
|
|
17
|
-
readonly https: string;
|
|
18
|
-
readonly module: null;
|
|
19
|
-
readonly net: null;
|
|
20
|
-
readonly os: string;
|
|
21
|
-
readonly path: string;
|
|
22
|
-
readonly punycode: string;
|
|
23
|
-
readonly process: string;
|
|
24
|
-
readonly querystring: string;
|
|
25
|
-
readonly readline: null;
|
|
26
|
-
readonly repl: null;
|
|
27
|
-
readonly stream: string;
|
|
28
|
-
readonly _stream_duplex: string;
|
|
29
|
-
readonly _stream_passthrough: string;
|
|
30
|
-
readonly _stream_readable: string;
|
|
31
|
-
readonly _stream_transform: string;
|
|
32
|
-
readonly _stream_writable: string;
|
|
33
|
-
readonly string_decoder: string;
|
|
34
|
-
readonly sys: string;
|
|
35
|
-
readonly timers: string;
|
|
36
|
-
readonly tls: null;
|
|
37
|
-
readonly tty: string;
|
|
38
|
-
readonly url: string;
|
|
39
|
-
readonly util: string;
|
|
40
|
-
readonly vm: string;
|
|
41
|
-
readonly zlib: string;
|
|
42
|
-
};
|
|
43
|
-
declare const resolvedPolyfillToModules: any;
|
|
44
|
-
|
|
1
|
+
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
45
2
|
type Globals = {
|
|
46
3
|
process?: boolean;
|
|
47
4
|
Buffer?: boolean;
|
|
48
5
|
};
|
|
49
|
-
type PluginNodePolyfillOptions = {
|
|
6
|
+
export type PluginNodePolyfillOptions = {
|
|
50
7
|
/**
|
|
51
8
|
* Whether to provide polyfill of globals.
|
|
52
9
|
* @default
|
|
@@ -79,11 +36,17 @@ type PluginNodePolyfillOptions = {
|
|
|
79
36
|
* @default undefined
|
|
80
37
|
*/
|
|
81
38
|
overrides?: Record<string, string | false>;
|
|
39
|
+
/**
|
|
40
|
+
* By default, the plugin only polyfills the browser-side code.
|
|
41
|
+
* If you want to polyfill the server-side code as well (when `output.target` is `node`),
|
|
42
|
+
* you can set the `force` option to `true`.
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
force?: boolean;
|
|
82
46
|
};
|
|
83
|
-
declare const resolvePolyfill: (libPath: string, overrides?: PluginNodePolyfillOptions["overrides"]) => string | false | null;
|
|
84
|
-
declare const getResolveFallback: ({ protocolImports, exclude, include, overrides, }: Pick<PluginNodePolyfillOptions, "protocolImports" | "exclude" | "include" | "overrides">) => Record<string, string | false>;
|
|
85
|
-
declare const getProvideGlobals: (globals?: Globals, overrides?: PluginNodePolyfillOptions["overrides"]) => Promise<Record<string, string | string[]>>;
|
|
86
|
-
declare const PLUGIN_NODE_POLYFILL_NAME = "rsbuild:node-polyfill";
|
|
87
|
-
declare function pluginNodePolyfill(options?: PluginNodePolyfillOptions): RsbuildPlugin;
|
|
88
|
-
|
|
89
|
-
export { PLUGIN_NODE_POLYFILL_NAME, type PluginNodePolyfillOptions, builtinMappingResolved, getProvideGlobals, getResolveFallback, pluginNodePolyfill, resolvePolyfill, resolvedPolyfillToModules };
|
|
47
|
+
export declare const resolvePolyfill: (libPath: string, overrides?: PluginNodePolyfillOptions["overrides"]) => string | false | null;
|
|
48
|
+
export declare const getResolveFallback: ({ protocolImports, exclude, include, overrides, }: Pick<PluginNodePolyfillOptions, "protocolImports" | "exclude" | "include" | "overrides">) => Record<string, string | false>;
|
|
49
|
+
export declare const getProvideGlobals: (globals?: Globals, overrides?: PluginNodePolyfillOptions["overrides"]) => Promise<Record<string, string | string[]>>;
|
|
50
|
+
export declare const PLUGIN_NODE_POLYFILL_NAME = "rsbuild:node-polyfill";
|
|
51
|
+
export declare function pluginNodePolyfill(options?: PluginNodePolyfillOptions): RsbuildPlugin;
|
|
52
|
+
export { builtinMappingResolved, resolvedPolyfillToModules, } from './libs.js';
|
package/dist/index.js
CHANGED
|
@@ -1,150 +1,113 @@
|
|
|
1
|
-
// src/ProtocolImportsPlugin.ts
|
|
2
|
-
var ProtocolImportsPlugin = class {
|
|
3
|
-
apply(compiler) {
|
|
4
|
-
compiler.hooks.normalModuleFactory.tap(
|
|
5
|
-
"NormalModuleReplacementPlugin",
|
|
6
|
-
(nmf) => {
|
|
7
|
-
nmf.hooks.beforeResolve.tap(
|
|
8
|
-
"NormalModuleReplacementPlugin",
|
|
9
|
-
(resource) => {
|
|
10
|
-
if (/^node:/.test(resource.request)) {
|
|
11
|
-
resource.request = resource.request.replace(/^node:/, "");
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// src/libs.ts
|
|
21
1
|
import { createRequire } from "node:module";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
+
const libs_require = createRequire(import.meta.url);
|
|
12
|
+
const builtinMappingResolved = {
|
|
13
|
+
assert: libs_require.resolve('assert/'),
|
|
14
|
+
buffer: libs_require.resolve('buffer/'),
|
|
15
|
+
child_process: null,
|
|
16
|
+
cluster: null,
|
|
17
|
+
console: libs_require.resolve('console-browserify'),
|
|
18
|
+
constants: libs_require.resolve('constants-browserify'),
|
|
19
|
+
crypto: libs_require.resolve('crypto-browserify'),
|
|
20
|
+
dgram: null,
|
|
21
|
+
dns: null,
|
|
22
|
+
domain: libs_require.resolve('domain-browser'),
|
|
23
|
+
events: libs_require.resolve('events/'),
|
|
24
|
+
fs: null,
|
|
25
|
+
http: libs_require.resolve('stream-http'),
|
|
26
|
+
https: libs_require.resolve('https-browserify'),
|
|
27
|
+
module: null,
|
|
28
|
+
net: null,
|
|
29
|
+
os: libs_require.resolve('os-browserify/browser.js'),
|
|
30
|
+
path: libs_require.resolve('path-browserify'),
|
|
31
|
+
punycode: libs_require.resolve('punycode/'),
|
|
32
|
+
process: libs_require.resolve('process/browser.js'),
|
|
33
|
+
querystring: libs_require.resolve('querystring-es3/'),
|
|
34
|
+
readline: null,
|
|
35
|
+
repl: null,
|
|
36
|
+
stream: libs_require.resolve('stream-browserify'),
|
|
37
|
+
_stream_duplex: libs_require.resolve('readable-stream/lib/_stream_duplex.js'),
|
|
38
|
+
_stream_passthrough: libs_require.resolve('readable-stream/lib/_stream_passthrough.js'),
|
|
39
|
+
_stream_readable: libs_require.resolve('readable-stream/lib/_stream_readable.js'),
|
|
40
|
+
_stream_transform: libs_require.resolve('readable-stream/lib/_stream_transform.js'),
|
|
41
|
+
_stream_writable: libs_require.resolve('readable-stream/lib/_stream_writable.js'),
|
|
42
|
+
string_decoder: libs_require.resolve('string_decoder/'),
|
|
43
|
+
sys: libs_require.resolve('util/util.js'),
|
|
44
|
+
timers: libs_require.resolve('timers-browserify'),
|
|
45
|
+
tls: null,
|
|
46
|
+
tty: libs_require.resolve('tty-browserify'),
|
|
47
|
+
url: libs_require.resolve('url/'),
|
|
48
|
+
util: libs_require.resolve('util/util.js'),
|
|
49
|
+
vm: libs_require.resolve('vm-browserify'),
|
|
50
|
+
zlib: libs_require.resolve('browserify-zlib')
|
|
66
51
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return overrides[libPath];
|
|
75
|
-
}
|
|
76
|
-
return builtinMappingResolved[libPath];
|
|
52
|
+
const resolvedPolyfillToModules = Object.fromEntries(Object.entries(builtinMappingResolved).filter(([key])=>null !== key).map(([key, value])=>[
|
|
53
|
+
value,
|
|
54
|
+
key
|
|
55
|
+
]));
|
|
56
|
+
const resolvePolyfill = (libPath, overrides)=>{
|
|
57
|
+
if ((null == overrides ? void 0 : overrides[libPath]) !== void 0) return overrides[libPath];
|
|
58
|
+
return builtinMappingResolved[libPath];
|
|
77
59
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
const resolvedNodeLibs = include ? include : Object.keys(builtinMappingResolved).filter((name) => {
|
|
88
|
-
return !(exclude || []).includes(name);
|
|
89
|
-
});
|
|
90
|
-
const fallback = {};
|
|
91
|
-
for (const name of resolvedNodeLibs) {
|
|
92
|
-
const libPath = resolvePolyfill(name, overrides);
|
|
93
|
-
fallback[name] = libPath ?? false;
|
|
94
|
-
if (protocolImports) {
|
|
95
|
-
fallback[`node:${name}`] = fallback[name];
|
|
60
|
+
const getResolveFallback = ({ protocolImports, exclude, include, overrides })=>{
|
|
61
|
+
if (exclude && include) throw new Error('`include` is mutually exclusive with `exclude`.');
|
|
62
|
+
const resolvedNodeLibs = include ? include : Object.keys(builtinMappingResolved).filter((name)=>!(exclude || []).includes(name));
|
|
63
|
+
const fallback = {};
|
|
64
|
+
for (const name of resolvedNodeLibs){
|
|
65
|
+
const libPath = resolvePolyfill(name, overrides);
|
|
66
|
+
fallback[name] = libPath ?? false;
|
|
67
|
+
if (protocolImports) fallback[`node:${name}`] = fallback[name];
|
|
96
68
|
}
|
|
97
|
-
|
|
98
|
-
return fallback;
|
|
69
|
+
return fallback;
|
|
99
70
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
71
|
+
const getProvideGlobals = async (globals, overrides)=>{
|
|
72
|
+
const result = {};
|
|
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
|
+
}
|
|
88
|
+
return result;
|
|
109
89
|
};
|
|
110
|
-
|
|
90
|
+
const PLUGIN_NODE_POLYFILL_NAME = 'rsbuild:node-polyfill';
|
|
111
91
|
function pluginNodePolyfill(options = {}) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
92
|
+
const { protocolImports = true, include, exclude, overrides, force = false } = options;
|
|
93
|
+
return {
|
|
94
|
+
name: PLUGIN_NODE_POLYFILL_NAME,
|
|
95
|
+
setup (api) {
|
|
96
|
+
api.modifyBundlerChain(async (chain, { isServer, bundler })=>{
|
|
97
|
+
if (isServer && !force) return;
|
|
98
|
+
chain.resolve.fallback.merge(getResolveFallback({
|
|
99
|
+
protocolImports,
|
|
100
|
+
include: include,
|
|
101
|
+
exclude,
|
|
102
|
+
overrides
|
|
103
|
+
}));
|
|
104
|
+
const provideGlobals = await getProvideGlobals(options.globals, overrides);
|
|
105
|
+
if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(bundler.ProvidePlugin, [
|
|
106
|
+
provideGlobals
|
|
107
|
+
]);
|
|
108
|
+
if (protocolImports) chain.plugin('protocol-imports').use(ProtocolImportsPlugin);
|
|
109
|
+
});
|
|
119
110
|
}
|
|
120
|
-
|
|
121
|
-
getResolveFallback({
|
|
122
|
-
protocolImports,
|
|
123
|
-
include,
|
|
124
|
-
exclude,
|
|
125
|
-
overrides
|
|
126
|
-
})
|
|
127
|
-
);
|
|
128
|
-
const provideGlobals = await getProvideGlobals(
|
|
129
|
-
options.globals,
|
|
130
|
-
overrides
|
|
131
|
-
);
|
|
132
|
-
if (Object.keys(provideGlobals).length) {
|
|
133
|
-
chain.plugin("node-polyfill-provide").use(bundler.ProvidePlugin, [provideGlobals]);
|
|
134
|
-
}
|
|
135
|
-
if (protocolImports) {
|
|
136
|
-
chain.plugin("protocol-imports").use(ProtocolImportsPlugin);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
};
|
|
111
|
+
};
|
|
141
112
|
}
|
|
142
|
-
export {
|
|
143
|
-
PLUGIN_NODE_POLYFILL_NAME,
|
|
144
|
-
builtinMappingResolved,
|
|
145
|
-
getProvideGlobals,
|
|
146
|
-
getResolveFallback,
|
|
147
|
-
pluginNodePolyfill,
|
|
148
|
-
resolvePolyfill,
|
|
149
|
-
resolvedPolyfillToModules
|
|
150
|
-
};
|
|
113
|
+
export { PLUGIN_NODE_POLYFILL_NAME, builtinMappingResolved, getProvideGlobals, getResolveFallback, pluginNodePolyfill, resolvePolyfill, resolvedPolyfillToModules };
|
package/dist/libs.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const builtinMappingResolved: {
|
|
2
|
+
readonly assert: string;
|
|
3
|
+
readonly buffer: string;
|
|
4
|
+
readonly child_process: null;
|
|
5
|
+
readonly cluster: null;
|
|
6
|
+
readonly console: string;
|
|
7
|
+
readonly constants: string;
|
|
8
|
+
readonly crypto: string;
|
|
9
|
+
readonly dgram: null;
|
|
10
|
+
readonly dns: null;
|
|
11
|
+
readonly domain: string;
|
|
12
|
+
readonly events: string;
|
|
13
|
+
readonly fs: null;
|
|
14
|
+
readonly http: string;
|
|
15
|
+
readonly https: string;
|
|
16
|
+
readonly module: null;
|
|
17
|
+
readonly net: null;
|
|
18
|
+
readonly os: string;
|
|
19
|
+
readonly path: string;
|
|
20
|
+
readonly punycode: string;
|
|
21
|
+
readonly process: string;
|
|
22
|
+
readonly querystring: string;
|
|
23
|
+
readonly readline: null;
|
|
24
|
+
readonly repl: null;
|
|
25
|
+
readonly stream: string;
|
|
26
|
+
readonly _stream_duplex: string;
|
|
27
|
+
readonly _stream_passthrough: string;
|
|
28
|
+
readonly _stream_readable: string;
|
|
29
|
+
readonly _stream_transform: string;
|
|
30
|
+
readonly _stream_writable: string;
|
|
31
|
+
readonly string_decoder: string;
|
|
32
|
+
readonly sys: string;
|
|
33
|
+
readonly timers: string;
|
|
34
|
+
readonly tls: null;
|
|
35
|
+
readonly tty: string;
|
|
36
|
+
readonly url: string;
|
|
37
|
+
readonly util: string;
|
|
38
|
+
readonly vm: string;
|
|
39
|
+
readonly zlib: string;
|
|
40
|
+
};
|
|
41
|
+
export declare const resolvedPolyfillToModules: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-node-polyfill",
|
|
3
|
-
"version": "1.
|
|
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",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"types": "./dist/index.d.ts",
|
|
17
17
|
"files": ["dist"],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "
|
|
20
|
-
"dev": "
|
|
19
|
+
"build": "rslib build",
|
|
20
|
+
"dev": "rslib build --watch",
|
|
21
21
|
"lint": "biome check .",
|
|
22
22
|
"lint:write": "biome check . --write",
|
|
23
23
|
"prepare": "simple-git-hooks && npm run build",
|
|
24
24
|
"test": "pnpm run /^test:/",
|
|
25
25
|
"test:e2e": "playwright test",
|
|
26
|
-
"test:unit": "
|
|
26
|
+
"test:unit": "rstest run",
|
|
27
27
|
"bump": "npx bumpp"
|
|
28
28
|
},
|
|
29
29
|
"simple-git-hooks": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"buffer": "^5.7.1",
|
|
41
41
|
"console-browserify": "^1.2.0",
|
|
42
42
|
"constants-browserify": "^1.0.0",
|
|
43
|
-
"crypto-browserify": "^3.12.
|
|
43
|
+
"crypto-browserify": "^3.12.1",
|
|
44
44
|
"domain-browser": "^5.7.0",
|
|
45
45
|
"events": "^3.3.0",
|
|
46
46
|
"https-browserify": "^1.0.0",
|
|
@@ -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.
|
|
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,25 +61,26 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@biomejs/biome": "^1.9.4",
|
|
64
|
-
"@playwright/test": "^1.
|
|
65
|
-
"@rsbuild/core": "^1.
|
|
66
|
-
"@
|
|
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",
|
|
67
69
|
"nano-staged": "^0.8.0",
|
|
68
|
-
"playwright": "^1.
|
|
69
|
-
"simple-git-hooks": "^2.
|
|
70
|
-
"
|
|
71
|
-
"typescript": "^5.
|
|
72
|
-
"vitest": "^2.1.3"
|
|
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
|
-
"@rsbuild/core": "1.x
|
|
76
|
+
"@rsbuild/core": "1.x"
|
|
76
77
|
},
|
|
77
78
|
"peerDependenciesMeta": {
|
|
78
79
|
"@rsbuild/core": {
|
|
79
80
|
"optional": true
|
|
80
81
|
}
|
|
81
82
|
},
|
|
82
|
-
"packageManager": "pnpm@
|
|
83
|
+
"packageManager": "pnpm@10.12.4",
|
|
83
84
|
"publishConfig": {
|
|
84
85
|
"access": "public",
|
|
85
86
|
"registry": "https://registry.npmjs.org/"
|
package/dist/index.d.cts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
|
|
3
|
-
declare const builtinMappingResolved: {
|
|
4
|
-
readonly assert: string;
|
|
5
|
-
readonly buffer: string;
|
|
6
|
-
readonly child_process: null;
|
|
7
|
-
readonly cluster: null;
|
|
8
|
-
readonly console: string;
|
|
9
|
-
readonly constants: string;
|
|
10
|
-
readonly crypto: string;
|
|
11
|
-
readonly dgram: null;
|
|
12
|
-
readonly dns: null;
|
|
13
|
-
readonly domain: string;
|
|
14
|
-
readonly events: string;
|
|
15
|
-
readonly fs: null;
|
|
16
|
-
readonly http: string;
|
|
17
|
-
readonly https: string;
|
|
18
|
-
readonly module: null;
|
|
19
|
-
readonly net: null;
|
|
20
|
-
readonly os: string;
|
|
21
|
-
readonly path: string;
|
|
22
|
-
readonly punycode: string;
|
|
23
|
-
readonly process: string;
|
|
24
|
-
readonly querystring: string;
|
|
25
|
-
readonly readline: null;
|
|
26
|
-
readonly repl: null;
|
|
27
|
-
readonly stream: string;
|
|
28
|
-
readonly _stream_duplex: string;
|
|
29
|
-
readonly _stream_passthrough: string;
|
|
30
|
-
readonly _stream_readable: string;
|
|
31
|
-
readonly _stream_transform: string;
|
|
32
|
-
readonly _stream_writable: string;
|
|
33
|
-
readonly string_decoder: string;
|
|
34
|
-
readonly sys: string;
|
|
35
|
-
readonly timers: string;
|
|
36
|
-
readonly tls: null;
|
|
37
|
-
readonly tty: string;
|
|
38
|
-
readonly url: string;
|
|
39
|
-
readonly util: string;
|
|
40
|
-
readonly vm: string;
|
|
41
|
-
readonly zlib: string;
|
|
42
|
-
};
|
|
43
|
-
declare const resolvedPolyfillToModules: any;
|
|
44
|
-
|
|
45
|
-
type Globals = {
|
|
46
|
-
process?: boolean;
|
|
47
|
-
Buffer?: boolean;
|
|
48
|
-
};
|
|
49
|
-
type PluginNodePolyfillOptions = {
|
|
50
|
-
/**
|
|
51
|
-
* Whether to provide polyfill of globals.
|
|
52
|
-
* @default
|
|
53
|
-
* {
|
|
54
|
-
* Buffer: true,
|
|
55
|
-
* process: true,
|
|
56
|
-
* }
|
|
57
|
-
*/
|
|
58
|
-
globals?: Globals;
|
|
59
|
-
/**
|
|
60
|
-
* Whether to polyfill Node.js builtin modules starting with `node:`.
|
|
61
|
-
* @see https://nodejs.org/api/esm.html#node-imports
|
|
62
|
-
* @default true
|
|
63
|
-
*/
|
|
64
|
-
protocolImports?: boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Exclude certain modules to be polyfilled.
|
|
67
|
-
* This option is mutually exclusive with {@link PluginNodePolyfillOptions.include | `include`}.
|
|
68
|
-
* @default undefined
|
|
69
|
-
*/
|
|
70
|
-
exclude?: string[];
|
|
71
|
-
/**
|
|
72
|
-
* Only include certain modules to be polyfilled.
|
|
73
|
-
* This option is mutually exclusive with {@link PluginNodePolyfillOptions.exclude | `exclude`}.
|
|
74
|
-
* @default undefined
|
|
75
|
-
*/
|
|
76
|
-
include?: string[];
|
|
77
|
-
/**
|
|
78
|
-
* Override the default polyfills for specific modules.
|
|
79
|
-
* @default undefined
|
|
80
|
-
*/
|
|
81
|
-
overrides?: Record<string, string | false>;
|
|
82
|
-
};
|
|
83
|
-
declare const resolvePolyfill: (libPath: string, overrides?: PluginNodePolyfillOptions["overrides"]) => string | false | null;
|
|
84
|
-
declare const getResolveFallback: ({ protocolImports, exclude, include, overrides, }: Pick<PluginNodePolyfillOptions, "protocolImports" | "exclude" | "include" | "overrides">) => Record<string, string | false>;
|
|
85
|
-
declare const getProvideGlobals: (globals?: Globals, overrides?: PluginNodePolyfillOptions["overrides"]) => Promise<Record<string, string | string[]>>;
|
|
86
|
-
declare const PLUGIN_NODE_POLYFILL_NAME = "rsbuild:node-polyfill";
|
|
87
|
-
declare function pluginNodePolyfill(options?: PluginNodePolyfillOptions): RsbuildPlugin;
|
|
88
|
-
|
|
89
|
-
export { PLUGIN_NODE_POLYFILL_NAME, type PluginNodePolyfillOptions, builtinMappingResolved, getProvideGlobals, getResolveFallback, pluginNodePolyfill, resolvePolyfill, resolvedPolyfillToModules };
|