@rsbuild/plugin-node-polyfill 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +6 -0
- package/dist/index.js +48 -11
- package/dist/index.mjs +59 -11
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,12 @@ type PluginNodePolyfillOptions = {
|
|
|
14
14
|
* }
|
|
15
15
|
*/
|
|
16
16
|
globals?: Globals;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to polyfill Node.js builtin modules starting with `node:`.
|
|
19
|
+
* @see https://nodejs.org/api/esm.html#node-imports
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
protocolImports?: boolean;
|
|
17
23
|
};
|
|
18
24
|
declare function pluginNodePolyfill(options?: PluginNodePolyfillOptions): RsbuildPlugin;
|
|
19
25
|
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,6 +30,35 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
32
|
|
|
33
|
+
// src/ProtocolImportsPlugin.ts
|
|
34
|
+
var ProtocolImportsPlugin_exports = {};
|
|
35
|
+
__export(ProtocolImportsPlugin_exports, {
|
|
36
|
+
ProtocolImportsPlugin: () => ProtocolImportsPlugin
|
|
37
|
+
});
|
|
38
|
+
var ProtocolImportsPlugin;
|
|
39
|
+
var init_ProtocolImportsPlugin = __esm({
|
|
40
|
+
"src/ProtocolImportsPlugin.ts"() {
|
|
41
|
+
"use strict";
|
|
42
|
+
ProtocolImportsPlugin = class {
|
|
43
|
+
apply(compiler) {
|
|
44
|
+
compiler.hooks.normalModuleFactory.tap(
|
|
45
|
+
"NormalModuleReplacementPlugin",
|
|
46
|
+
(nmf) => {
|
|
47
|
+
nmf.hooks.beforeResolve.tap(
|
|
48
|
+
"NormalModuleReplacementPlugin",
|
|
49
|
+
(resource) => {
|
|
50
|
+
if (/^node:/.test(resource.request)) {
|
|
51
|
+
resource.request = resource.request.replace(/^node:/, "");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
30
62
|
// src/index.ts
|
|
31
63
|
var src_exports = {};
|
|
32
64
|
__export(src_exports, {
|
|
@@ -116,17 +148,17 @@ var vm = require.resolve("vm-browserify");
|
|
|
116
148
|
var zlib = require.resolve("browserify-zlib");
|
|
117
149
|
|
|
118
150
|
// src/index.ts
|
|
119
|
-
var getResolveFallback = (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
151
|
+
var getResolveFallback = (protocolImports) => {
|
|
152
|
+
const fallback = {};
|
|
153
|
+
for (const name of Object.keys(libs_exports)) {
|
|
154
|
+
const libPath = libs_exports[name];
|
|
155
|
+
fallback[name] = libPath ?? false;
|
|
156
|
+
if (protocolImports) {
|
|
157
|
+
fallback[`node:${name}`] = fallback[name];
|
|
125
158
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
);
|
|
159
|
+
}
|
|
160
|
+
return fallback;
|
|
161
|
+
};
|
|
130
162
|
var getProvideGlobals = async (globals) => {
|
|
131
163
|
const result = {};
|
|
132
164
|
if (globals?.Buffer !== false) {
|
|
@@ -138,6 +170,7 @@ var getProvideGlobals = async (globals) => {
|
|
|
138
170
|
return result;
|
|
139
171
|
};
|
|
140
172
|
function pluginNodePolyfill(options = {}) {
|
|
173
|
+
const { protocolImports = true } = options;
|
|
141
174
|
return {
|
|
142
175
|
name: "rsbuild:node-polyfill",
|
|
143
176
|
setup(api) {
|
|
@@ -145,11 +178,15 @@ function pluginNodePolyfill(options = {}) {
|
|
|
145
178
|
if (isServer) {
|
|
146
179
|
return;
|
|
147
180
|
}
|
|
148
|
-
chain.resolve.fallback.merge(getResolveFallback(
|
|
181
|
+
chain.resolve.fallback.merge(getResolveFallback(protocolImports));
|
|
149
182
|
const provideGlobals = await getProvideGlobals(options.globals);
|
|
150
183
|
if (Object.keys(provideGlobals).length) {
|
|
151
184
|
chain.plugin(CHAIN_ID.PLUGIN.NODE_POLYFILL_PROVIDE).use(bundler.ProvidePlugin, [provideGlobals]);
|
|
152
185
|
}
|
|
186
|
+
if (protocolImports) {
|
|
187
|
+
const { ProtocolImportsPlugin: ProtocolImportsPlugin2 } = await Promise.resolve().then(() => (init_ProtocolImportsPlugin(), ProtocolImportsPlugin_exports));
|
|
188
|
+
chain.plugin("protocol-imports").use(ProtocolImportsPlugin2);
|
|
189
|
+
}
|
|
153
190
|
});
|
|
154
191
|
}
|
|
155
192
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { createRequire } from 'module';
|
|
|
2
2
|
var require = createRequire(import.meta['url']);
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
6
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
6
7
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
7
8
|
}) : x)(function(x) {
|
|
@@ -9,6 +10,9 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
9
10
|
return require.apply(this, arguments);
|
|
10
11
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
11
12
|
});
|
|
13
|
+
var __esm = (fn, res) => function __init() {
|
|
14
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
+
};
|
|
12
16
|
var __export = (target, all) => {
|
|
13
17
|
for (var name in all)
|
|
14
18
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -17,6 +21,44 @@ var __export = (target, all) => {
|
|
|
17
21
|
// ../../node_modules/.pnpm/@modern-js+module-tools@2.48.3/node_modules/@modern-js/module-tools/shims/esm.js
|
|
18
22
|
import { fileURLToPath } from "url";
|
|
19
23
|
import path from "path";
|
|
24
|
+
var init_esm = __esm({
|
|
25
|
+
"../../node_modules/.pnpm/@modern-js+module-tools@2.48.3/node_modules/@modern-js/module-tools/shims/esm.js"() {
|
|
26
|
+
"use strict";
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// src/ProtocolImportsPlugin.ts
|
|
31
|
+
var ProtocolImportsPlugin_exports = {};
|
|
32
|
+
__export(ProtocolImportsPlugin_exports, {
|
|
33
|
+
ProtocolImportsPlugin: () => ProtocolImportsPlugin
|
|
34
|
+
});
|
|
35
|
+
var ProtocolImportsPlugin;
|
|
36
|
+
var init_ProtocolImportsPlugin = __esm({
|
|
37
|
+
"src/ProtocolImportsPlugin.ts"() {
|
|
38
|
+
"use strict";
|
|
39
|
+
init_esm();
|
|
40
|
+
ProtocolImportsPlugin = class {
|
|
41
|
+
apply(compiler) {
|
|
42
|
+
compiler.hooks.normalModuleFactory.tap(
|
|
43
|
+
"NormalModuleReplacementPlugin",
|
|
44
|
+
(nmf) => {
|
|
45
|
+
nmf.hooks.beforeResolve.tap(
|
|
46
|
+
"NormalModuleReplacementPlugin",
|
|
47
|
+
(resource) => {
|
|
48
|
+
if (/^node:/.test(resource.request)) {
|
|
49
|
+
resource.request = resource.request.replace(/^node:/, "");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// src/index.ts
|
|
61
|
+
init_esm();
|
|
20
62
|
|
|
21
63
|
// src/libs.ts
|
|
22
64
|
var libs_exports = {};
|
|
@@ -60,6 +102,7 @@ __export(libs_exports, {
|
|
|
60
102
|
vm: () => vm,
|
|
61
103
|
zlib: () => zlib
|
|
62
104
|
});
|
|
105
|
+
init_esm();
|
|
63
106
|
var assert = __require.resolve("assert/");
|
|
64
107
|
var buffer = __require.resolve("buffer/");
|
|
65
108
|
var child_process = null;
|
|
@@ -110,17 +153,17 @@ var vm = __require.resolve("vm-browserify");
|
|
|
110
153
|
var zlib = __require.resolve("browserify-zlib");
|
|
111
154
|
|
|
112
155
|
// src/index.ts
|
|
113
|
-
var getResolveFallback = (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
156
|
+
var getResolveFallback = (protocolImports) => {
|
|
157
|
+
const fallback = {};
|
|
158
|
+
for (const name of Object.keys(libs_exports)) {
|
|
159
|
+
const libPath = libs_exports[name];
|
|
160
|
+
fallback[name] = libPath ?? false;
|
|
161
|
+
if (protocolImports) {
|
|
162
|
+
fallback[`node:${name}`] = fallback[name];
|
|
119
163
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
);
|
|
164
|
+
}
|
|
165
|
+
return fallback;
|
|
166
|
+
};
|
|
124
167
|
var getProvideGlobals = async (globals) => {
|
|
125
168
|
const result = {};
|
|
126
169
|
if (globals?.Buffer !== false) {
|
|
@@ -132,6 +175,7 @@ var getProvideGlobals = async (globals) => {
|
|
|
132
175
|
return result;
|
|
133
176
|
};
|
|
134
177
|
function pluginNodePolyfill(options = {}) {
|
|
178
|
+
const { protocolImports = true } = options;
|
|
135
179
|
return {
|
|
136
180
|
name: "rsbuild:node-polyfill",
|
|
137
181
|
setup(api) {
|
|
@@ -139,11 +183,15 @@ function pluginNodePolyfill(options = {}) {
|
|
|
139
183
|
if (isServer) {
|
|
140
184
|
return;
|
|
141
185
|
}
|
|
142
|
-
chain.resolve.fallback.merge(getResolveFallback(
|
|
186
|
+
chain.resolve.fallback.merge(getResolveFallback(protocolImports));
|
|
143
187
|
const provideGlobals = await getProvideGlobals(options.globals);
|
|
144
188
|
if (Object.keys(provideGlobals).length) {
|
|
145
189
|
chain.plugin(CHAIN_ID.PLUGIN.NODE_POLYFILL_PROVIDE).use(bundler.ProvidePlugin, [provideGlobals]);
|
|
146
190
|
}
|
|
191
|
+
if (protocolImports) {
|
|
192
|
+
const { ProtocolImportsPlugin: ProtocolImportsPlugin2 } = await Promise.resolve().then(() => (init_ProtocolImportsPlugin(), ProtocolImportsPlugin_exports));
|
|
193
|
+
chain.plugin("protocol-imports").use(ProtocolImportsPlugin2);
|
|
194
|
+
}
|
|
147
195
|
});
|
|
148
196
|
}
|
|
149
197
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-node-polyfill",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Node polyfill plugin for Rsbuild",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"repository": {
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"url": "^0.11.3",
|
|
47
47
|
"util": "^0.12.5",
|
|
48
48
|
"vm-browserify": "^1.1.2",
|
|
49
|
-
"@rsbuild/shared": "0.5.
|
|
49
|
+
"@rsbuild/shared": "0.5.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"typescript": "^5.4.2",
|
|
53
|
-
"@rsbuild/core": "0.5.
|
|
53
|
+
"@rsbuild/core": "0.5.4"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@rsbuild/core": "^0.5.
|
|
56
|
+
"@rsbuild/core": "^0.5.4"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public",
|