@rsbuild/plugin-node-polyfill 1.0.4 → 1.2.0
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 +60 -13
- package/dist/index.cjs +116 -144
- package/dist/index.d.cts +63 -1
- package/dist/index.d.ts +63 -1
- package/dist/index.js +106 -102
- package/package.json +86 -82
- package/dist/ProtocolImportsPlugin-HUSWFIAE.js +0 -23
- package/dist/chunk-6C3VEZWH.js +0 -9
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ An Rsbuild plugin to automatically inject polyfills for [Node.js builtin modules
|
|
|
7
7
|
<img src="https://img.shields.io/npm/v/@rsbuild/plugin-node-polyfill?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
|
|
8
8
|
</a>
|
|
9
9
|
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
|
|
10
|
+
<a href="https://npmcharts.com/compare/@rsbuild/plugin-node-polyfill?minimal=true"><img src="https://img.shields.io/npm/dm/@rsbuild/plugin-node-polyfill.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
|
|
10
11
|
</p>
|
|
11
12
|
|
|
12
13
|
## When to use
|
|
@@ -27,11 +28,11 @@ Add plugin to your `rsbuild.config.ts`:
|
|
|
27
28
|
|
|
28
29
|
```ts
|
|
29
30
|
// rsbuild.config.ts
|
|
30
|
-
import { pluginNodePolyfill } from
|
|
31
|
+
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill'
|
|
31
32
|
|
|
32
33
|
export default {
|
|
33
34
|
plugins: [pluginNodePolyfill()],
|
|
34
|
-
}
|
|
35
|
+
}
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
## Node Polyfills
|
|
@@ -46,7 +47,7 @@ When you use the above global variables in your code, the corresponding polyfill
|
|
|
46
47
|
For instance, the following code would inject the `Buffer` polyfill:
|
|
47
48
|
|
|
48
49
|
```ts
|
|
49
|
-
const bufferData = Buffer.from(
|
|
50
|
+
const bufferData = Buffer.from('abc')
|
|
50
51
|
```
|
|
51
52
|
|
|
52
53
|
You can disable this behavior through the `globals` option of the plugin:
|
|
@@ -57,7 +58,7 @@ pluginNodePolyfill({
|
|
|
57
58
|
Buffer: false,
|
|
58
59
|
process: false,
|
|
59
60
|
},
|
|
60
|
-
})
|
|
61
|
+
})
|
|
61
62
|
```
|
|
62
63
|
|
|
63
64
|
### Modules
|
|
@@ -94,9 +95,9 @@ pluginNodePolyfill({
|
|
|
94
95
|
When the above module is referenced in code via import / require syntax, the corresponding polyfill will be injected.
|
|
95
96
|
|
|
96
97
|
```ts
|
|
97
|
-
import { Buffer } from
|
|
98
|
+
import { Buffer } from 'buffer'
|
|
98
99
|
|
|
99
|
-
const bufferData = Buffer.from(
|
|
100
|
+
const bufferData = Buffer.from('abc')
|
|
100
101
|
```
|
|
101
102
|
|
|
102
103
|
### Fallbacks
|
|
@@ -115,9 +116,9 @@ const bufferData = Buffer.from("abc");
|
|
|
115
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.
|
|
116
117
|
|
|
117
118
|
```ts
|
|
118
|
-
import fs from
|
|
119
|
+
import fs from 'fs'
|
|
119
120
|
|
|
120
|
-
console.log(fs)
|
|
121
|
+
console.log(fs) // -> {}
|
|
121
122
|
```
|
|
122
123
|
|
|
123
124
|
## Options
|
|
@@ -130,9 +131,9 @@ Used to specify whether to inject polyfills for global variables.
|
|
|
130
131
|
|
|
131
132
|
```ts
|
|
132
133
|
type Globals = {
|
|
133
|
-
process?: boolean
|
|
134
|
-
Buffer?: boolean
|
|
135
|
-
}
|
|
134
|
+
process?: boolean
|
|
135
|
+
Buffer?: boolean
|
|
136
|
+
}
|
|
136
137
|
```
|
|
137
138
|
|
|
138
139
|
- **Default:**
|
|
@@ -141,7 +142,7 @@ type Globals = {
|
|
|
141
142
|
const defaultGlobals = {
|
|
142
143
|
Buffer: true,
|
|
143
144
|
process: true,
|
|
144
|
-
}
|
|
145
|
+
}
|
|
145
146
|
```
|
|
146
147
|
|
|
147
148
|
### protocolImports
|
|
@@ -156,9 +157,55 @@ For example, if you disable `protocolImports`, modules such as `node:path`, `nod
|
|
|
156
157
|
```ts
|
|
157
158
|
pluginNodePolyfill({
|
|
158
159
|
protocolImports: false,
|
|
159
|
-
})
|
|
160
|
+
})
|
|
160
161
|
```
|
|
161
162
|
|
|
163
|
+
### include
|
|
164
|
+
|
|
165
|
+
Specify an array of modules for which polyfills should be injected. If this option is set, only the specified modules will be polyfilled. `include` is mutually exclusive with [`exclude`](#exclude).
|
|
166
|
+
|
|
167
|
+
- **Type:** `string[]`
|
|
168
|
+
- **Default:** `undefined`
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
pluginNodePolyfill({
|
|
172
|
+
include: ['buffer', 'crypto'], // Only "buffer" and "crypto" modules will be polyfilled.
|
|
173
|
+
})
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### exclude
|
|
177
|
+
|
|
178
|
+
Specify an array of modules for which polyfills should not be injected from the default. If this option is set, the specified modules will be excluded from polyfilled. `exclude` is mutually exclusive with [`include`](#include).
|
|
179
|
+
|
|
180
|
+
- **Type:** `string[]`
|
|
181
|
+
- **Default:** `undefined`
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
pluginNodePolyfill({
|
|
185
|
+
exclude: ['http', 'https'], // All modules except "http" and "https" will be polyfilled.
|
|
186
|
+
})
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### overrides
|
|
190
|
+
|
|
191
|
+
Override the default polyfills for specific modules.
|
|
192
|
+
|
|
193
|
+
- **Type:** `Record<string, string>`
|
|
194
|
+
- **Default:** `{}`
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
pluginNodePolyfill({
|
|
198
|
+
overrides: {
|
|
199
|
+
fs: 'memfs',
|
|
200
|
+
},
|
|
201
|
+
})
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Exported variables
|
|
205
|
+
|
|
206
|
+
- `builtinMappingResolved`: A map of Node.js builtin modules to their resolved corresponding polyfills modules.
|
|
207
|
+
- `resolvedPolyfillToModules`: A map of resolved polyfill modules to the polyfill modules before resolving.
|
|
208
|
+
|
|
162
209
|
## License
|
|
163
210
|
|
|
164
211
|
[MIT](./LICENSE).
|
package/dist/index.cjs
CHANGED
|
@@ -3,9 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __esm = (fn, res) => function __init() {
|
|
7
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
8
|
-
};
|
|
9
6
|
var __export = (target, all) => {
|
|
10
7
|
for (var name in all)
|
|
11
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -20,154 +17,115 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
20
17
|
};
|
|
21
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
19
|
|
|
23
|
-
//
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
PLUGIN_NODE_POLYFILL_NAME: () => PLUGIN_NODE_POLYFILL_NAME,
|
|
24
|
+
builtinMappingResolved: () => builtinMappingResolved,
|
|
25
|
+
getProvideGlobals: () => getProvideGlobals,
|
|
26
|
+
getResolveFallback: () => getResolveFallback,
|
|
27
|
+
pluginNodePolyfill: () => pluginNodePolyfill,
|
|
28
|
+
resolvePolyfill: () => resolvePolyfill,
|
|
29
|
+
resolvedPolyfillToModules: () => resolvedPolyfillToModules
|
|
31
30
|
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
32
|
+
|
|
33
|
+
// node_modules/.pnpm/tsup@8.3.0_postcss@8.4.47_typescript@5.6.3/node_modules/tsup/assets/cjs_shims.js
|
|
34
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
35
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
32
36
|
|
|
33
37
|
// src/ProtocolImportsPlugin.ts
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"src/ProtocolImportsPlugin.ts"() {
|
|
41
|
-
"use strict";
|
|
42
|
-
init_cjs_shims();
|
|
43
|
-
ProtocolImportsPlugin = class {
|
|
44
|
-
apply(compiler) {
|
|
45
|
-
compiler.hooks.normalModuleFactory.tap(
|
|
38
|
+
var ProtocolImportsPlugin = class {
|
|
39
|
+
apply(compiler) {
|
|
40
|
+
compiler.hooks.normalModuleFactory.tap(
|
|
41
|
+
"NormalModuleReplacementPlugin",
|
|
42
|
+
(nmf) => {
|
|
43
|
+
nmf.hooks.beforeResolve.tap(
|
|
46
44
|
"NormalModuleReplacementPlugin",
|
|
47
|
-
(
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
if (/^node:/.test(resource.request)) {
|
|
52
|
-
resource.request = resource.request.replace(/^node:/, "");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
);
|
|
45
|
+
(resource) => {
|
|
46
|
+
if (/^node:/.test(resource.request)) {
|
|
47
|
+
resource.request = resource.request.replace(/^node:/, "");
|
|
48
|
+
}
|
|
56
49
|
}
|
|
57
50
|
);
|
|
58
51
|
}
|
|
59
|
-
|
|
52
|
+
);
|
|
60
53
|
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// src/index.ts
|
|
64
|
-
var src_exports = {};
|
|
65
|
-
__export(src_exports, {
|
|
66
|
-
PLUGIN_NODE_POLYFILL_NAME: () => PLUGIN_NODE_POLYFILL_NAME,
|
|
67
|
-
pluginNodePolyfill: () => pluginNodePolyfill
|
|
68
|
-
});
|
|
69
|
-
module.exports = __toCommonJS(src_exports);
|
|
70
|
-
init_cjs_shims();
|
|
54
|
+
};
|
|
71
55
|
|
|
72
56
|
// src/libs.ts
|
|
73
|
-
var libs_exports = {};
|
|
74
|
-
__export(libs_exports, {
|
|
75
|
-
_stream_duplex: () => _stream_duplex,
|
|
76
|
-
_stream_passthrough: () => _stream_passthrough,
|
|
77
|
-
_stream_readable: () => _stream_readable,
|
|
78
|
-
_stream_transform: () => _stream_transform,
|
|
79
|
-
_stream_writable: () => _stream_writable,
|
|
80
|
-
assert: () => assert,
|
|
81
|
-
buffer: () => buffer,
|
|
82
|
-
child_process: () => child_process,
|
|
83
|
-
cluster: () => cluster,
|
|
84
|
-
console: () => console,
|
|
85
|
-
constants: () => constants,
|
|
86
|
-
crypto: () => crypto,
|
|
87
|
-
dgram: () => dgram,
|
|
88
|
-
dns: () => dns,
|
|
89
|
-
domain: () => domain,
|
|
90
|
-
events: () => events,
|
|
91
|
-
fs: () => fs,
|
|
92
|
-
http: () => http,
|
|
93
|
-
https: () => https,
|
|
94
|
-
module: () => module2,
|
|
95
|
-
net: () => net,
|
|
96
|
-
os: () => os,
|
|
97
|
-
path: () => path,
|
|
98
|
-
process: () => process,
|
|
99
|
-
punycode: () => punycode,
|
|
100
|
-
querystring: () => querystring,
|
|
101
|
-
readline: () => readline,
|
|
102
|
-
repl: () => repl,
|
|
103
|
-
stream: () => stream,
|
|
104
|
-
string_decoder: () => string_decoder,
|
|
105
|
-
sys: () => sys,
|
|
106
|
-
timers: () => timers,
|
|
107
|
-
tls: () => tls,
|
|
108
|
-
tty: () => tty,
|
|
109
|
-
url: () => url,
|
|
110
|
-
util: () => util,
|
|
111
|
-
vm: () => vm,
|
|
112
|
-
zlib: () => zlib
|
|
113
|
-
});
|
|
114
|
-
init_cjs_shims();
|
|
115
57
|
var import_node_module = require("module");
|
|
116
58
|
var require2 = (0, import_node_module.createRequire)(importMetaUrl);
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
"readable-stream/lib/_stream_duplex.js"
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
"
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
|
|
59
|
+
var builtinMappingResolved = {
|
|
60
|
+
assert: require2.resolve("assert/"),
|
|
61
|
+
buffer: require2.resolve("buffer/"),
|
|
62
|
+
child_process: null,
|
|
63
|
+
cluster: null,
|
|
64
|
+
console: require2.resolve("console-browserify"),
|
|
65
|
+
constants: require2.resolve("constants-browserify"),
|
|
66
|
+
crypto: require2.resolve("crypto-browserify"),
|
|
67
|
+
dgram: null,
|
|
68
|
+
dns: null,
|
|
69
|
+
domain: require2.resolve("domain-browser"),
|
|
70
|
+
events: require2.resolve("events/"),
|
|
71
|
+
fs: null,
|
|
72
|
+
http: require2.resolve("stream-http"),
|
|
73
|
+
https: require2.resolve("https-browserify"),
|
|
74
|
+
module: null,
|
|
75
|
+
net: null,
|
|
76
|
+
os: require2.resolve("os-browserify/browser.js"),
|
|
77
|
+
path: require2.resolve("path-browserify"),
|
|
78
|
+
punycode: require2.resolve("punycode/"),
|
|
79
|
+
process: require2.resolve("process/browser.js"),
|
|
80
|
+
querystring: require2.resolve("querystring-es3/"),
|
|
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")
|
|
102
|
+
};
|
|
103
|
+
var resolvedPolyfillToModules = Object.fromEntries(
|
|
104
|
+
Object.entries(builtinMappingResolved).filter(([key]) => key !== null).map(([key, value]) => [value, key])
|
|
155
105
|
);
|
|
156
|
-
var string_decoder = require2.resolve("string_decoder/");
|
|
157
|
-
var sys = require2.resolve("util/util.js");
|
|
158
|
-
var timers = require2.resolve("timers-browserify");
|
|
159
|
-
var tls = null;
|
|
160
|
-
var tty = require2.resolve("tty-browserify");
|
|
161
|
-
var url = require2.resolve("url/");
|
|
162
|
-
var util = require2.resolve("util/util.js");
|
|
163
|
-
var vm = require2.resolve("vm-browserify");
|
|
164
|
-
var zlib = require2.resolve("browserify-zlib");
|
|
165
106
|
|
|
166
107
|
// src/index.ts
|
|
167
|
-
var
|
|
108
|
+
var resolvePolyfill = (libPath, overrides) => {
|
|
109
|
+
if (overrides?.[libPath] !== void 0) {
|
|
110
|
+
return overrides[libPath];
|
|
111
|
+
}
|
|
112
|
+
return builtinMappingResolved[libPath];
|
|
113
|
+
};
|
|
114
|
+
var getResolveFallback = ({
|
|
115
|
+
protocolImports,
|
|
116
|
+
exclude,
|
|
117
|
+
include,
|
|
118
|
+
overrides
|
|
119
|
+
}) => {
|
|
120
|
+
if (exclude && include) {
|
|
121
|
+
throw new Error("`include` is mutually exclusive with `exclude`.");
|
|
122
|
+
}
|
|
123
|
+
const resolvedNodeLibs = include ? include : Object.keys(builtinMappingResolved).filter((name) => {
|
|
124
|
+
return !(exclude || []).includes(name);
|
|
125
|
+
});
|
|
168
126
|
const fallback = {};
|
|
169
|
-
for (const name of
|
|
170
|
-
const libPath =
|
|
127
|
+
for (const name of resolvedNodeLibs) {
|
|
128
|
+
const libPath = resolvePolyfill(name, overrides);
|
|
171
129
|
fallback[name] = libPath ?? false;
|
|
172
130
|
if (protocolImports) {
|
|
173
131
|
fallback[`node:${name}`] = fallback[name];
|
|
@@ -175,19 +133,19 @@ var getResolveFallback = (protocolImports) => {
|
|
|
175
133
|
}
|
|
176
134
|
return fallback;
|
|
177
135
|
};
|
|
178
|
-
var getProvideGlobals = async (globals) => {
|
|
136
|
+
var getProvideGlobals = async (globals, overrides) => {
|
|
179
137
|
const result = {};
|
|
180
138
|
if (globals?.Buffer !== false) {
|
|
181
|
-
result.Buffer = [buffer, "Buffer"];
|
|
139
|
+
result.Buffer = [resolvePolyfill("buffer", overrides), "Buffer"];
|
|
182
140
|
}
|
|
183
141
|
if (globals?.process !== false) {
|
|
184
|
-
result.process = [process];
|
|
142
|
+
result.process = [resolvePolyfill("process", overrides)];
|
|
185
143
|
}
|
|
186
144
|
return result;
|
|
187
145
|
};
|
|
188
146
|
var PLUGIN_NODE_POLYFILL_NAME = "rsbuild:node-polyfill";
|
|
189
147
|
function pluginNodePolyfill(options = {}) {
|
|
190
|
-
const { protocolImports = true } = options;
|
|
148
|
+
const { protocolImports = true, include, exclude, overrides } = options;
|
|
191
149
|
return {
|
|
192
150
|
name: PLUGIN_NODE_POLYFILL_NAME,
|
|
193
151
|
setup(api) {
|
|
@@ -195,14 +153,23 @@ function pluginNodePolyfill(options = {}) {
|
|
|
195
153
|
if (isServer) {
|
|
196
154
|
return;
|
|
197
155
|
}
|
|
198
|
-
chain.resolve.fallback.merge(
|
|
199
|
-
|
|
156
|
+
chain.resolve.fallback.merge(
|
|
157
|
+
getResolveFallback({
|
|
158
|
+
protocolImports,
|
|
159
|
+
include,
|
|
160
|
+
exclude,
|
|
161
|
+
overrides
|
|
162
|
+
})
|
|
163
|
+
);
|
|
164
|
+
const provideGlobals = await getProvideGlobals(
|
|
165
|
+
options.globals,
|
|
166
|
+
overrides
|
|
167
|
+
);
|
|
200
168
|
if (Object.keys(provideGlobals).length) {
|
|
201
169
|
chain.plugin("node-polyfill-provide").use(bundler.ProvidePlugin, [provideGlobals]);
|
|
202
170
|
}
|
|
203
171
|
if (protocolImports) {
|
|
204
|
-
|
|
205
|
-
chain.plugin("protocol-imports").use(ProtocolImportsPlugin2);
|
|
172
|
+
chain.plugin("protocol-imports").use(ProtocolImportsPlugin);
|
|
206
173
|
}
|
|
207
174
|
});
|
|
208
175
|
}
|
|
@@ -211,5 +178,10 @@ function pluginNodePolyfill(options = {}) {
|
|
|
211
178
|
// Annotate the CommonJS export names for ESM import in node:
|
|
212
179
|
0 && (module.exports = {
|
|
213
180
|
PLUGIN_NODE_POLYFILL_NAME,
|
|
214
|
-
|
|
181
|
+
builtinMappingResolved,
|
|
182
|
+
getProvideGlobals,
|
|
183
|
+
getResolveFallback,
|
|
184
|
+
pluginNodePolyfill,
|
|
185
|
+
resolvePolyfill,
|
|
186
|
+
resolvedPolyfillToModules
|
|
215
187
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
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
|
+
|
|
3
45
|
type Globals = {
|
|
4
46
|
process?: boolean;
|
|
5
47
|
Buffer?: boolean;
|
|
@@ -20,8 +62,28 @@ type PluginNodePolyfillOptions = {
|
|
|
20
62
|
* @default true
|
|
21
63
|
*/
|
|
22
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>;
|
|
23
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[]>>;
|
|
24
86
|
declare const PLUGIN_NODE_POLYFILL_NAME = "rsbuild:node-polyfill";
|
|
25
87
|
declare function pluginNodePolyfill(options?: PluginNodePolyfillOptions): RsbuildPlugin;
|
|
26
88
|
|
|
27
|
-
export { PLUGIN_NODE_POLYFILL_NAME, type PluginNodePolyfillOptions, pluginNodePolyfill };
|
|
89
|
+
export { PLUGIN_NODE_POLYFILL_NAME, type PluginNodePolyfillOptions, builtinMappingResolved, getProvideGlobals, getResolveFallback, pluginNodePolyfill, resolvePolyfill, resolvedPolyfillToModules };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
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
|
+
|
|
3
45
|
type Globals = {
|
|
4
46
|
process?: boolean;
|
|
5
47
|
Buffer?: boolean;
|
|
@@ -20,8 +62,28 @@ type PluginNodePolyfillOptions = {
|
|
|
20
62
|
* @default true
|
|
21
63
|
*/
|
|
22
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>;
|
|
23
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[]>>;
|
|
24
86
|
declare const PLUGIN_NODE_POLYFILL_NAME = "rsbuild:node-polyfill";
|
|
25
87
|
declare function pluginNodePolyfill(options?: PluginNodePolyfillOptions): RsbuildPlugin;
|
|
26
88
|
|
|
27
|
-
export { PLUGIN_NODE_POLYFILL_NAME, type PluginNodePolyfillOptions, pluginNodePolyfill };
|
|
89
|
+
export { PLUGIN_NODE_POLYFILL_NAME, type PluginNodePolyfillOptions, builtinMappingResolved, getProvideGlobals, getResolveFallback, pluginNodePolyfill, resolvePolyfill, resolvedPolyfillToModules };
|
package/dist/index.js
CHANGED
|
@@ -1,105 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
};
|
|
4
19
|
|
|
5
20
|
// src/libs.ts
|
|
6
|
-
var libs_exports = {};
|
|
7
|
-
__export(libs_exports, {
|
|
8
|
-
_stream_duplex: () => _stream_duplex,
|
|
9
|
-
_stream_passthrough: () => _stream_passthrough,
|
|
10
|
-
_stream_readable: () => _stream_readable,
|
|
11
|
-
_stream_transform: () => _stream_transform,
|
|
12
|
-
_stream_writable: () => _stream_writable,
|
|
13
|
-
assert: () => assert,
|
|
14
|
-
buffer: () => buffer,
|
|
15
|
-
child_process: () => child_process,
|
|
16
|
-
cluster: () => cluster,
|
|
17
|
-
console: () => console,
|
|
18
|
-
constants: () => constants,
|
|
19
|
-
crypto: () => crypto,
|
|
20
|
-
dgram: () => dgram,
|
|
21
|
-
dns: () => dns,
|
|
22
|
-
domain: () => domain,
|
|
23
|
-
events: () => events,
|
|
24
|
-
fs: () => fs,
|
|
25
|
-
http: () => http,
|
|
26
|
-
https: () => https,
|
|
27
|
-
module: () => module,
|
|
28
|
-
net: () => net,
|
|
29
|
-
os: () => os,
|
|
30
|
-
path: () => path,
|
|
31
|
-
process: () => process,
|
|
32
|
-
punycode: () => punycode,
|
|
33
|
-
querystring: () => querystring,
|
|
34
|
-
readline: () => readline,
|
|
35
|
-
repl: () => repl,
|
|
36
|
-
stream: () => stream,
|
|
37
|
-
string_decoder: () => string_decoder,
|
|
38
|
-
sys: () => sys,
|
|
39
|
-
timers: () => timers,
|
|
40
|
-
tls: () => tls,
|
|
41
|
-
tty: () => tty,
|
|
42
|
-
url: () => url,
|
|
43
|
-
util: () => util,
|
|
44
|
-
vm: () => vm,
|
|
45
|
-
zlib: () => zlib
|
|
46
|
-
});
|
|
47
21
|
import { createRequire } from "node:module";
|
|
48
22
|
var require2 = createRequire(import.meta.url);
|
|
49
|
-
var
|
|
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
|
-
"readable-stream/lib/_stream_duplex.js"
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
"
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
|
|
23
|
+
var builtinMappingResolved = {
|
|
24
|
+
assert: require2.resolve("assert/"),
|
|
25
|
+
buffer: require2.resolve("buffer/"),
|
|
26
|
+
child_process: null,
|
|
27
|
+
cluster: null,
|
|
28
|
+
console: require2.resolve("console-browserify"),
|
|
29
|
+
constants: require2.resolve("constants-browserify"),
|
|
30
|
+
crypto: require2.resolve("crypto-browserify"),
|
|
31
|
+
dgram: null,
|
|
32
|
+
dns: null,
|
|
33
|
+
domain: require2.resolve("domain-browser"),
|
|
34
|
+
events: require2.resolve("events/"),
|
|
35
|
+
fs: null,
|
|
36
|
+
http: require2.resolve("stream-http"),
|
|
37
|
+
https: require2.resolve("https-browserify"),
|
|
38
|
+
module: null,
|
|
39
|
+
net: null,
|
|
40
|
+
os: require2.resolve("os-browserify/browser.js"),
|
|
41
|
+
path: require2.resolve("path-browserify"),
|
|
42
|
+
punycode: require2.resolve("punycode/"),
|
|
43
|
+
process: require2.resolve("process/browser.js"),
|
|
44
|
+
querystring: require2.resolve("querystring-es3/"),
|
|
45
|
+
readline: null,
|
|
46
|
+
repl: null,
|
|
47
|
+
stream: require2.resolve("stream-browserify"),
|
|
48
|
+
_stream_duplex: require2.resolve("readable-stream/lib/_stream_duplex.js"),
|
|
49
|
+
_stream_passthrough: require2.resolve(
|
|
50
|
+
"readable-stream/lib/_stream_passthrough.js"
|
|
51
|
+
),
|
|
52
|
+
_stream_readable: require2.resolve("readable-stream/lib/_stream_readable.js"),
|
|
53
|
+
_stream_transform: require2.resolve(
|
|
54
|
+
"readable-stream/lib/_stream_transform.js"
|
|
55
|
+
),
|
|
56
|
+
_stream_writable: require2.resolve("readable-stream/lib/_stream_writable.js"),
|
|
57
|
+
string_decoder: require2.resolve("string_decoder/"),
|
|
58
|
+
sys: require2.resolve("util/util.js"),
|
|
59
|
+
timers: require2.resolve("timers-browserify"),
|
|
60
|
+
tls: null,
|
|
61
|
+
tty: require2.resolve("tty-browserify"),
|
|
62
|
+
url: require2.resolve("url/"),
|
|
63
|
+
util: require2.resolve("util/util.js"),
|
|
64
|
+
vm: require2.resolve("vm-browserify"),
|
|
65
|
+
zlib: require2.resolve("browserify-zlib")
|
|
66
|
+
};
|
|
67
|
+
var resolvedPolyfillToModules = Object.fromEntries(
|
|
68
|
+
Object.entries(builtinMappingResolved).filter(([key]) => key !== null).map(([key, value]) => [value, key])
|
|
87
69
|
);
|
|
88
|
-
var string_decoder = require2.resolve("string_decoder/");
|
|
89
|
-
var sys = require2.resolve("util/util.js");
|
|
90
|
-
var timers = require2.resolve("timers-browserify");
|
|
91
|
-
var tls = null;
|
|
92
|
-
var tty = require2.resolve("tty-browserify");
|
|
93
|
-
var url = require2.resolve("url/");
|
|
94
|
-
var util = require2.resolve("util/util.js");
|
|
95
|
-
var vm = require2.resolve("vm-browserify");
|
|
96
|
-
var zlib = require2.resolve("browserify-zlib");
|
|
97
70
|
|
|
98
71
|
// src/index.ts
|
|
99
|
-
var
|
|
72
|
+
var resolvePolyfill = (libPath, overrides) => {
|
|
73
|
+
if (overrides?.[libPath] !== void 0) {
|
|
74
|
+
return overrides[libPath];
|
|
75
|
+
}
|
|
76
|
+
return builtinMappingResolved[libPath];
|
|
77
|
+
};
|
|
78
|
+
var getResolveFallback = ({
|
|
79
|
+
protocolImports,
|
|
80
|
+
exclude,
|
|
81
|
+
include,
|
|
82
|
+
overrides
|
|
83
|
+
}) => {
|
|
84
|
+
if (exclude && include) {
|
|
85
|
+
throw new Error("`include` is mutually exclusive with `exclude`.");
|
|
86
|
+
}
|
|
87
|
+
const resolvedNodeLibs = include ? include : Object.keys(builtinMappingResolved).filter((name) => {
|
|
88
|
+
return !(exclude || []).includes(name);
|
|
89
|
+
});
|
|
100
90
|
const fallback = {};
|
|
101
|
-
for (const name of
|
|
102
|
-
const libPath =
|
|
91
|
+
for (const name of resolvedNodeLibs) {
|
|
92
|
+
const libPath = resolvePolyfill(name, overrides);
|
|
103
93
|
fallback[name] = libPath ?? false;
|
|
104
94
|
if (protocolImports) {
|
|
105
95
|
fallback[`node:${name}`] = fallback[name];
|
|
@@ -107,19 +97,19 @@ var getResolveFallback = (protocolImports) => {
|
|
|
107
97
|
}
|
|
108
98
|
return fallback;
|
|
109
99
|
};
|
|
110
|
-
var getProvideGlobals = async (globals) => {
|
|
100
|
+
var getProvideGlobals = async (globals, overrides) => {
|
|
111
101
|
const result = {};
|
|
112
102
|
if (globals?.Buffer !== false) {
|
|
113
|
-
result.Buffer = [buffer, "Buffer"];
|
|
103
|
+
result.Buffer = [resolvePolyfill("buffer", overrides), "Buffer"];
|
|
114
104
|
}
|
|
115
105
|
if (globals?.process !== false) {
|
|
116
|
-
result.process = [process];
|
|
106
|
+
result.process = [resolvePolyfill("process", overrides)];
|
|
117
107
|
}
|
|
118
108
|
return result;
|
|
119
109
|
};
|
|
120
110
|
var PLUGIN_NODE_POLYFILL_NAME = "rsbuild:node-polyfill";
|
|
121
111
|
function pluginNodePolyfill(options = {}) {
|
|
122
|
-
const { protocolImports = true } = options;
|
|
112
|
+
const { protocolImports = true, include, exclude, overrides } = options;
|
|
123
113
|
return {
|
|
124
114
|
name: PLUGIN_NODE_POLYFILL_NAME,
|
|
125
115
|
setup(api) {
|
|
@@ -127,13 +117,22 @@ function pluginNodePolyfill(options = {}) {
|
|
|
127
117
|
if (isServer) {
|
|
128
118
|
return;
|
|
129
119
|
}
|
|
130
|
-
chain.resolve.fallback.merge(
|
|
131
|
-
|
|
120
|
+
chain.resolve.fallback.merge(
|
|
121
|
+
getResolveFallback({
|
|
122
|
+
protocolImports,
|
|
123
|
+
include,
|
|
124
|
+
exclude,
|
|
125
|
+
overrides
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
const provideGlobals = await getProvideGlobals(
|
|
129
|
+
options.globals,
|
|
130
|
+
overrides
|
|
131
|
+
);
|
|
132
132
|
if (Object.keys(provideGlobals).length) {
|
|
133
133
|
chain.plugin("node-polyfill-provide").use(bundler.ProvidePlugin, [provideGlobals]);
|
|
134
134
|
}
|
|
135
135
|
if (protocolImports) {
|
|
136
|
-
const { ProtocolImportsPlugin } = await import("./ProtocolImportsPlugin-HUSWFIAE.js");
|
|
137
136
|
chain.plugin("protocol-imports").use(ProtocolImportsPlugin);
|
|
138
137
|
}
|
|
139
138
|
});
|
|
@@ -142,5 +141,10 @@ function pluginNodePolyfill(options = {}) {
|
|
|
142
141
|
}
|
|
143
142
|
export {
|
|
144
143
|
PLUGIN_NODE_POLYFILL_NAME,
|
|
145
|
-
|
|
144
|
+
builtinMappingResolved,
|
|
145
|
+
getProvideGlobals,
|
|
146
|
+
getResolveFallback,
|
|
147
|
+
pluginNodePolyfill,
|
|
148
|
+
resolvePolyfill,
|
|
149
|
+
resolvedPolyfillToModules
|
|
146
150
|
};
|
package/package.json
CHANGED
|
@@ -1,83 +1,87 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
2
|
+
"name": "@rsbuild/plugin-node-polyfill",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"repository": "https://github.com/rspack-contrib/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.js",
|
|
15
|
+
"module": "./dist/index.mjs",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": ["dist"],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"dev": "tsup --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": "vitest 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.0",
|
|
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.5.2",
|
|
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.48.1",
|
|
65
|
+
"@rsbuild/core": "^1.0.15",
|
|
66
|
+
"@types/node": "^20.16.13",
|
|
67
|
+
"nano-staged": "^0.8.0",
|
|
68
|
+
"playwright": "^1.48.1",
|
|
69
|
+
"simple-git-hooks": "^2.11.1",
|
|
70
|
+
"tsup": "^8.3.0",
|
|
71
|
+
"typescript": "^5.6.3",
|
|
72
|
+
"vitest": "^2.1.3"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@rsbuild/core": "1.x || ^1.0.1-beta.0"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"@rsbuild/core": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"packageManager": "pnpm@9.12.2",
|
|
83
|
+
"publishConfig": {
|
|
84
|
+
"access": "public",
|
|
85
|
+
"registry": "https://registry.npmjs.org/"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import "./chunk-6C3VEZWH.js";
|
|
2
|
-
|
|
3
|
-
// src/ProtocolImportsPlugin.ts
|
|
4
|
-
var ProtocolImportsPlugin = class {
|
|
5
|
-
apply(compiler) {
|
|
6
|
-
compiler.hooks.normalModuleFactory.tap(
|
|
7
|
-
"NormalModuleReplacementPlugin",
|
|
8
|
-
(nmf) => {
|
|
9
|
-
nmf.hooks.beforeResolve.tap(
|
|
10
|
-
"NormalModuleReplacementPlugin",
|
|
11
|
-
(resource) => {
|
|
12
|
-
if (/^node:/.test(resource.request)) {
|
|
13
|
-
resource.request = resource.request.replace(/^node:/, "");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
export {
|
|
22
|
-
ProtocolImportsPlugin
|
|
23
|
-
};
|