@rsbuild/plugin-node-polyfill 1.0.0-alpha.0 → 1.0.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/LICENSE +1 -1
- package/README.md +148 -9
- package/dist/ProtocolImportsPlugin-HUSWFIAE.js +23 -0
- package/dist/chunk-6C3VEZWH.js +9 -0
- package/dist/index.cjs +53 -38
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +36 -93
- package/package.json +32 -15
- package/dist/ProtocolImportsPlugin.d.ts +0 -4
- package/dist/libs.d.ts +0 -38
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 Rspack Contrib
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,19 +1,158 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# @rsbuild/plugin-node-polyfill
|
|
2
|
+
|
|
3
|
+
@rsbuild/plugin-node-polyfill is a Rsbuild plugin to do something.
|
|
4
|
+
|
|
5
|
+
<p>
|
|
6
|
+
<a href="https://npmjs.com/package/@rsbuild/plugin-node-polyfill">
|
|
7
|
+
<img src="https://img.shields.io/npm/v/@rsbuild/plugin-node-polyfill?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
|
|
8
|
+
</a>
|
|
9
|
+
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
|
|
3
10
|
</p>
|
|
4
11
|
|
|
5
|
-
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
Install:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm add @rsbuild/plugin-node-polyfill -D
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Add plugin to your `rsbuild.config.ts`:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// rsbuild.config.ts
|
|
24
|
+
import { pluginNodePolyfill } from "@rsbuild/plugin-node-polyfill";
|
|
25
|
+
|
|
26
|
+
export default {
|
|
27
|
+
plugins: [pluginNodePolyfill()],
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Node Polyfills
|
|
32
|
+
|
|
33
|
+
### Globals
|
|
34
|
+
|
|
35
|
+
- `Buffer`
|
|
36
|
+
- `process`
|
|
37
|
+
|
|
38
|
+
When you use the above global variables in your code, the corresponding polyfill will be automatically injected.
|
|
39
|
+
|
|
40
|
+
For instance, the following code would inject the `Buffer` polyfill:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const bufferData = Buffer.from("abc");
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
You can disable this behavior through the `globals` option of the plugin:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
pluginNodePolyfill({
|
|
50
|
+
globals: {
|
|
51
|
+
Buffer: false,
|
|
52
|
+
process: false,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Modules
|
|
58
|
+
|
|
59
|
+
- `assert`
|
|
60
|
+
- `buffer`
|
|
61
|
+
- `console`
|
|
62
|
+
- `constants`
|
|
63
|
+
- `crypto`
|
|
64
|
+
- `domain`
|
|
65
|
+
- `events`
|
|
66
|
+
- `http`
|
|
67
|
+
- `https`
|
|
68
|
+
- `os`
|
|
69
|
+
- `path`
|
|
70
|
+
- `punycode`
|
|
71
|
+
- `process`
|
|
72
|
+
- `querystring`
|
|
73
|
+
- `stream`
|
|
74
|
+
- `_stream_duplex`
|
|
75
|
+
- `_stream_passthrough`
|
|
76
|
+
- `_stream_readable`
|
|
77
|
+
- `_stream_transform`
|
|
78
|
+
- `_stream_writable`
|
|
79
|
+
- `string_decoder`
|
|
80
|
+
- `sys`
|
|
81
|
+
- `timers`
|
|
82
|
+
- `tty`
|
|
83
|
+
- `url`
|
|
84
|
+
- `util`
|
|
85
|
+
- `vm`
|
|
86
|
+
- `zlib`
|
|
87
|
+
|
|
88
|
+
When the above module is referenced in code via import / require syntax, the corresponding polyfill will be injected.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { Buffer } from "buffer";
|
|
92
|
+
|
|
93
|
+
const bufferData = Buffer.from("abc");
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Fallbacks
|
|
97
|
+
|
|
98
|
+
- `child_process`
|
|
99
|
+
- `cluster`
|
|
100
|
+
- `dgram`
|
|
101
|
+
- `dns`
|
|
102
|
+
- `fs`
|
|
103
|
+
- `module`
|
|
104
|
+
- `net`
|
|
105
|
+
- `readline`
|
|
106
|
+
- `repl`
|
|
107
|
+
- `tls`
|
|
108
|
+
|
|
109
|
+
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.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import fs from "fs";
|
|
113
|
+
|
|
114
|
+
console.log(fs); // -> {}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Options
|
|
118
|
+
|
|
119
|
+
### globals
|
|
120
|
+
|
|
121
|
+
Used to specify whether to inject polyfills for global variables.
|
|
122
|
+
|
|
123
|
+
- **Type:**
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
type Globals = {
|
|
127
|
+
process?: boolean;
|
|
128
|
+
Buffer?: boolean;
|
|
129
|
+
};
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- **Default:**
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
const defaultGlobals = {
|
|
136
|
+
Buffer: true,
|
|
137
|
+
process: true,
|
|
138
|
+
};
|
|
139
|
+
```
|
|
6
140
|
|
|
7
|
-
|
|
141
|
+
### protocolImports
|
|
8
142
|
|
|
9
|
-
|
|
143
|
+
Whether to polyfill Node.js builtin modules starting with `node:`.
|
|
10
144
|
|
|
11
|
-
|
|
145
|
+
- **Type:** `boolean`
|
|
146
|
+
- **Default:** `true`
|
|
12
147
|
|
|
13
|
-
|
|
148
|
+
For example, if you disable `protocolImports`, modules such as `node:path`, `node:http`, etc. will not be polyfilled.
|
|
14
149
|
|
|
15
|
-
|
|
150
|
+
```ts
|
|
151
|
+
pluginNodePolyfill({
|
|
152
|
+
protocolImports: false,
|
|
153
|
+
});
|
|
154
|
+
```
|
|
16
155
|
|
|
17
156
|
## License
|
|
18
157
|
|
|
19
|
-
|
|
158
|
+
[MIT](./LICENSE).
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __esm = (fn, res) => function __init() {
|
|
9
7
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
@@ -20,16 +18,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
20
18
|
}
|
|
21
19
|
return to;
|
|
22
20
|
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
31
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
22
|
|
|
23
|
+
// node_modules/.pnpm/tsup@8.0.2_postcss@8.4.38_typescript@5.5.2/node_modules/tsup/assets/cjs_shims.js
|
|
24
|
+
var getImportMetaUrl, importMetaUrl;
|
|
25
|
+
var init_cjs_shims = __esm({
|
|
26
|
+
"node_modules/.pnpm/tsup@8.0.2_postcss@8.4.38_typescript@5.5.2/node_modules/tsup/assets/cjs_shims.js"() {
|
|
27
|
+
"use strict";
|
|
28
|
+
getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
29
|
+
importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
33
|
// src/ProtocolImportsPlugin.ts
|
|
34
34
|
var ProtocolImportsPlugin_exports = {};
|
|
35
35
|
__export(ProtocolImportsPlugin_exports, {
|
|
@@ -39,6 +39,7 @@ var ProtocolImportsPlugin;
|
|
|
39
39
|
var init_ProtocolImportsPlugin = __esm({
|
|
40
40
|
"src/ProtocolImportsPlugin.ts"() {
|
|
41
41
|
"use strict";
|
|
42
|
+
init_cjs_shims();
|
|
42
43
|
ProtocolImportsPlugin = class {
|
|
43
44
|
apply(compiler) {
|
|
44
45
|
compiler.hooks.normalModuleFactory.tap(
|
|
@@ -66,6 +67,7 @@ __export(src_exports, {
|
|
|
66
67
|
pluginNodePolyfill: () => pluginNodePolyfill
|
|
67
68
|
});
|
|
68
69
|
module.exports = __toCommonJS(src_exports);
|
|
70
|
+
init_cjs_shims();
|
|
69
71
|
|
|
70
72
|
// src/libs.ts
|
|
71
73
|
var libs_exports = {};
|
|
@@ -109,44 +111,57 @@ __export(libs_exports, {
|
|
|
109
111
|
vm: () => vm,
|
|
110
112
|
zlib: () => zlib
|
|
111
113
|
});
|
|
112
|
-
|
|
113
|
-
var
|
|
114
|
+
init_cjs_shims();
|
|
115
|
+
var import_node_module = require("module");
|
|
116
|
+
var require2 = (0, import_node_module.createRequire)(importMetaUrl);
|
|
117
|
+
var assert = require2.resolve("assert/");
|
|
118
|
+
var buffer = require2.resolve("buffer/");
|
|
114
119
|
var child_process = null;
|
|
115
120
|
var cluster = null;
|
|
116
|
-
var console =
|
|
117
|
-
var constants =
|
|
118
|
-
var crypto =
|
|
121
|
+
var console = require2.resolve("console-browserify");
|
|
122
|
+
var constants = require2.resolve("constants-browserify");
|
|
123
|
+
var crypto = require2.resolve("crypto-browserify");
|
|
119
124
|
var dgram = null;
|
|
120
125
|
var dns = null;
|
|
121
|
-
var domain =
|
|
122
|
-
var events =
|
|
126
|
+
var domain = require2.resolve("domain-browser");
|
|
127
|
+
var events = require2.resolve("events/");
|
|
123
128
|
var fs = null;
|
|
124
|
-
var http =
|
|
125
|
-
var https =
|
|
129
|
+
var http = require2.resolve("stream-http");
|
|
130
|
+
var https = require2.resolve("https-browserify");
|
|
126
131
|
var module2 = null;
|
|
127
132
|
var net = null;
|
|
128
|
-
var os =
|
|
129
|
-
var path =
|
|
130
|
-
var punycode =
|
|
131
|
-
var process =
|
|
132
|
-
var querystring =
|
|
133
|
+
var os = require2.resolve("os-browserify/browser.js");
|
|
134
|
+
var path = require2.resolve("path-browserify");
|
|
135
|
+
var punycode = require2.resolve("punycode/");
|
|
136
|
+
var process = require2.resolve("process/browser.js");
|
|
137
|
+
var querystring = require2.resolve("querystring-es3/");
|
|
133
138
|
var readline = null;
|
|
134
139
|
var repl = null;
|
|
135
|
-
var stream =
|
|
136
|
-
var _stream_duplex =
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
var
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
var
|
|
143
|
-
|
|
140
|
+
var stream = require2.resolve("stream-browserify");
|
|
141
|
+
var _stream_duplex = require2.resolve(
|
|
142
|
+
"readable-stream/lib/_stream_duplex.js"
|
|
143
|
+
);
|
|
144
|
+
var _stream_passthrough = require2.resolve(
|
|
145
|
+
"readable-stream/lib/_stream_passthrough.js"
|
|
146
|
+
);
|
|
147
|
+
var _stream_readable = require2.resolve(
|
|
148
|
+
"readable-stream/lib/_stream_readable.js"
|
|
149
|
+
);
|
|
150
|
+
var _stream_transform = require2.resolve(
|
|
151
|
+
"readable-stream/lib/_stream_transform.js"
|
|
152
|
+
);
|
|
153
|
+
var _stream_writable = require2.resolve(
|
|
154
|
+
"readable-stream/lib/_stream_writable.js"
|
|
155
|
+
);
|
|
156
|
+
var string_decoder = require2.resolve("string_decoder/");
|
|
157
|
+
var sys = require2.resolve("util/util.js");
|
|
158
|
+
var timers = require2.resolve("timers-browserify");
|
|
144
159
|
var tls = null;
|
|
145
|
-
var tty =
|
|
146
|
-
var url =
|
|
147
|
-
var util =
|
|
148
|
-
var vm =
|
|
149
|
-
var zlib =
|
|
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");
|
|
150
165
|
|
|
151
166
|
// src/index.ts
|
|
152
167
|
var getResolveFallback = (protocolImports) => {
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
|
|
3
|
+
type Globals = {
|
|
4
|
+
process?: boolean;
|
|
5
|
+
Buffer?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type PluginNodePolyfillOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Whether to provide polyfill of globals.
|
|
10
|
+
* @default
|
|
11
|
+
* {
|
|
12
|
+
* Buffer: true,
|
|
13
|
+
* process: true,
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
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;
|
|
23
|
+
};
|
|
24
|
+
declare const PLUGIN_NODE_POLYFILL_NAME = "rsbuild:node-polyfill";
|
|
25
|
+
declare function pluginNodePolyfill(options?: PluginNodePolyfillOptions): RsbuildPlugin;
|
|
26
|
+
|
|
27
|
+
export { PLUGIN_NODE_POLYFILL_NAME, type PluginNodePolyfillOptions, pluginNodePolyfill };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
|
|
2
3
|
type Globals = {
|
|
3
4
|
process?: boolean;
|
|
4
5
|
Buffer?: boolean;
|
|
5
6
|
};
|
|
6
|
-
|
|
7
|
+
type PluginNodePolyfillOptions = {
|
|
7
8
|
/**
|
|
8
9
|
* Whether to provide polyfill of globals.
|
|
9
10
|
* @default
|
|
@@ -20,6 +21,7 @@ export type PluginNodePolyfillOptions = {
|
|
|
20
21
|
*/
|
|
21
22
|
protocolImports?: boolean;
|
|
22
23
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
declare const PLUGIN_NODE_POLYFILL_NAME = "rsbuild:node-polyfill";
|
|
25
|
+
declare function pluginNodePolyfill(options?: PluginNodePolyfillOptions): RsbuildPlugin;
|
|
26
|
+
|
|
27
|
+
export { PLUGIN_NODE_POLYFILL_NAME, type PluginNodePolyfillOptions, pluginNodePolyfill };
|
package/dist/index.js
CHANGED
|
@@ -1,64 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
7
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
8
|
-
}) : x)(function(x) {
|
|
9
|
-
if (typeof require !== "undefined")
|
|
10
|
-
return require.apply(this, arguments);
|
|
11
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
-
});
|
|
13
|
-
var __esm = (fn, res) => function __init() {
|
|
14
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
-
};
|
|
16
|
-
var __export = (target, all) => {
|
|
17
|
-
for (var name in all)
|
|
18
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.54.5_eslint@9.6.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
22
|
-
import { fileURLToPath } from "url";
|
|
23
|
-
import path from "path";
|
|
24
|
-
var init_esm = __esm({
|
|
25
|
-
"../../node_modules/.pnpm/@modern-js+module-tools@2.54.5_eslint@9.6.0_typescript@5.5.2/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();
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-6C3VEZWH.js";
|
|
62
4
|
|
|
63
5
|
// src/libs.ts
|
|
64
6
|
var libs_exports = {};
|
|
@@ -85,7 +27,7 @@ __export(libs_exports, {
|
|
|
85
27
|
module: () => module,
|
|
86
28
|
net: () => net,
|
|
87
29
|
os: () => os,
|
|
88
|
-
path: () =>
|
|
30
|
+
path: () => path,
|
|
89
31
|
process: () => process,
|
|
90
32
|
punycode: () => punycode,
|
|
91
33
|
querystring: () => querystring,
|
|
@@ -102,55 +44,56 @@ __export(libs_exports, {
|
|
|
102
44
|
vm: () => vm,
|
|
103
45
|
zlib: () => zlib
|
|
104
46
|
});
|
|
105
|
-
|
|
106
|
-
var
|
|
107
|
-
var
|
|
47
|
+
import { createRequire } from "node:module";
|
|
48
|
+
var require2 = createRequire(import.meta.url);
|
|
49
|
+
var assert = require2.resolve("assert/");
|
|
50
|
+
var buffer = require2.resolve("buffer/");
|
|
108
51
|
var child_process = null;
|
|
109
52
|
var cluster = null;
|
|
110
|
-
var console =
|
|
111
|
-
var constants =
|
|
112
|
-
var crypto =
|
|
53
|
+
var console = require2.resolve("console-browserify");
|
|
54
|
+
var constants = require2.resolve("constants-browserify");
|
|
55
|
+
var crypto = require2.resolve("crypto-browserify");
|
|
113
56
|
var dgram = null;
|
|
114
57
|
var dns = null;
|
|
115
|
-
var domain =
|
|
116
|
-
var events =
|
|
58
|
+
var domain = require2.resolve("domain-browser");
|
|
59
|
+
var events = require2.resolve("events/");
|
|
117
60
|
var fs = null;
|
|
118
|
-
var http =
|
|
119
|
-
var https =
|
|
61
|
+
var http = require2.resolve("stream-http");
|
|
62
|
+
var https = require2.resolve("https-browserify");
|
|
120
63
|
var module = null;
|
|
121
64
|
var net = null;
|
|
122
|
-
var os =
|
|
123
|
-
var
|
|
124
|
-
var punycode =
|
|
125
|
-
var process =
|
|
126
|
-
var querystring =
|
|
65
|
+
var os = require2.resolve("os-browserify/browser.js");
|
|
66
|
+
var path = require2.resolve("path-browserify");
|
|
67
|
+
var punycode = require2.resolve("punycode/");
|
|
68
|
+
var process = require2.resolve("process/browser.js");
|
|
69
|
+
var querystring = require2.resolve("querystring-es3/");
|
|
127
70
|
var readline = null;
|
|
128
71
|
var repl = null;
|
|
129
|
-
var stream =
|
|
130
|
-
var _stream_duplex =
|
|
72
|
+
var stream = require2.resolve("stream-browserify");
|
|
73
|
+
var _stream_duplex = require2.resolve(
|
|
131
74
|
"readable-stream/lib/_stream_duplex.js"
|
|
132
75
|
);
|
|
133
|
-
var _stream_passthrough =
|
|
76
|
+
var _stream_passthrough = require2.resolve(
|
|
134
77
|
"readable-stream/lib/_stream_passthrough.js"
|
|
135
78
|
);
|
|
136
|
-
var _stream_readable =
|
|
79
|
+
var _stream_readable = require2.resolve(
|
|
137
80
|
"readable-stream/lib/_stream_readable.js"
|
|
138
81
|
);
|
|
139
|
-
var _stream_transform =
|
|
82
|
+
var _stream_transform = require2.resolve(
|
|
140
83
|
"readable-stream/lib/_stream_transform.js"
|
|
141
84
|
);
|
|
142
|
-
var _stream_writable =
|
|
85
|
+
var _stream_writable = require2.resolve(
|
|
143
86
|
"readable-stream/lib/_stream_writable.js"
|
|
144
87
|
);
|
|
145
|
-
var string_decoder =
|
|
146
|
-
var sys =
|
|
147
|
-
var timers =
|
|
88
|
+
var string_decoder = require2.resolve("string_decoder/");
|
|
89
|
+
var sys = require2.resolve("util/util.js");
|
|
90
|
+
var timers = require2.resolve("timers-browserify");
|
|
148
91
|
var tls = null;
|
|
149
|
-
var tty =
|
|
150
|
-
var url =
|
|
151
|
-
var util =
|
|
152
|
-
var vm =
|
|
153
|
-
var zlib =
|
|
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");
|
|
154
97
|
|
|
155
98
|
// src/index.ts
|
|
156
99
|
var getResolveFallback = (protocolImports) => {
|
|
@@ -190,8 +133,8 @@ function pluginNodePolyfill(options = {}) {
|
|
|
190
133
|
chain.plugin(CHAIN_ID.PLUGIN.NODE_POLYFILL_PROVIDE).use(bundler.ProvidePlugin, [provideGlobals]);
|
|
191
134
|
}
|
|
192
135
|
if (protocolImports) {
|
|
193
|
-
const { ProtocolImportsPlugin
|
|
194
|
-
chain.plugin("protocol-imports").use(
|
|
136
|
+
const { ProtocolImportsPlugin } = await import("./ProtocolImportsPlugin-HUSWFIAE.js");
|
|
137
|
+
chain.plugin("protocol-imports").use(ProtocolImportsPlugin);
|
|
195
138
|
}
|
|
196
139
|
});
|
|
197
140
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-node-polyfill",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
5
|
-
"homepage": "https://rsbuild.dev",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "https://github.com/web-infra-dev/rsbuild",
|
|
9
|
-
"directory": "packages/plugin-node-polyfill"
|
|
10
|
-
},
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"repository": "https://github.com/rspack-contrib/rsbuild-plugin-template",
|
|
11
5
|
"license": "MIT",
|
|
12
6
|
"type": "module",
|
|
13
7
|
"exports": {
|
|
@@ -17,11 +11,20 @@
|
|
|
17
11
|
"require": "./dist/index.cjs"
|
|
18
12
|
}
|
|
19
13
|
},
|
|
20
|
-
"main": "./dist/index.
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.mjs",
|
|
21
16
|
"types": "./dist/index.d.ts",
|
|
22
17
|
"files": [
|
|
23
18
|
"dist"
|
|
24
19
|
],
|
|
20
|
+
"simple-git-hooks": {
|
|
21
|
+
"pre-commit": "npx nano-staged"
|
|
22
|
+
},
|
|
23
|
+
"nano-staged": {
|
|
24
|
+
"*.{js,jsx,ts,tsx,mjs,cjs}": [
|
|
25
|
+
"biome check --write --no-errors-on-unmatched"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
25
28
|
"dependencies": {
|
|
26
29
|
"assert": "^2.1.0",
|
|
27
30
|
"browserify-zlib": "^0.2.0",
|
|
@@ -48,19 +51,33 @@
|
|
|
48
51
|
"vm-browserify": "^1.1.2"
|
|
49
52
|
},
|
|
50
53
|
"devDependencies": {
|
|
51
|
-
"
|
|
52
|
-
"@
|
|
54
|
+
"@biomejs/biome": "^1.8.3",
|
|
55
|
+
"@playwright/test": "^1.44.1",
|
|
56
|
+
"@rsbuild/core": "^0.7.10",
|
|
57
|
+
"@types/node": "^20.14.1",
|
|
58
|
+
"nano-staged": "^0.8.0",
|
|
59
|
+
"playwright": "^1.44.1",
|
|
60
|
+
"simple-git-hooks": "^2.11.1",
|
|
61
|
+
"tsup": "^8.0.2",
|
|
62
|
+
"typescript": "^5.5.2"
|
|
53
63
|
},
|
|
54
64
|
"peerDependencies": {
|
|
55
|
-
"@rsbuild/core": "
|
|
65
|
+
"@rsbuild/core": "0.x || 1.x"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"@rsbuild/core": {
|
|
69
|
+
"optional": true
|
|
70
|
+
}
|
|
56
71
|
},
|
|
57
72
|
"publishConfig": {
|
|
58
73
|
"access": "public",
|
|
59
|
-
"provenance": true,
|
|
60
74
|
"registry": "https://registry.npmjs.org/"
|
|
61
75
|
},
|
|
62
76
|
"scripts": {
|
|
63
|
-
"build": "
|
|
64
|
-
"dev": "
|
|
77
|
+
"build": "tsup",
|
|
78
|
+
"dev": "tsup --watch",
|
|
79
|
+
"lint": "biome check .",
|
|
80
|
+
"lint:write": "biome check . --write",
|
|
81
|
+
"test": "playwright test"
|
|
65
82
|
}
|
|
66
83
|
}
|
package/dist/libs.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export declare const assert: string;
|
|
2
|
-
export declare const buffer: string;
|
|
3
|
-
export declare const child_process: null;
|
|
4
|
-
export declare const cluster: null;
|
|
5
|
-
export declare const console: string;
|
|
6
|
-
export declare const constants: string;
|
|
7
|
-
export declare const crypto: string;
|
|
8
|
-
export declare const dgram: null;
|
|
9
|
-
export declare const dns: null;
|
|
10
|
-
export declare const domain: string;
|
|
11
|
-
export declare const events: string;
|
|
12
|
-
export declare const fs: null;
|
|
13
|
-
export declare const http: string;
|
|
14
|
-
export declare const https: string;
|
|
15
|
-
export declare const module: null;
|
|
16
|
-
export declare const net: null;
|
|
17
|
-
export declare const os: string;
|
|
18
|
-
export declare const path: string;
|
|
19
|
-
export declare const punycode: string;
|
|
20
|
-
export declare const process: string;
|
|
21
|
-
export declare const querystring: string;
|
|
22
|
-
export declare const readline: null;
|
|
23
|
-
export declare const repl: null;
|
|
24
|
-
export declare const stream: string;
|
|
25
|
-
export declare const _stream_duplex: string;
|
|
26
|
-
export declare const _stream_passthrough: string;
|
|
27
|
-
export declare const _stream_readable: string;
|
|
28
|
-
export declare const _stream_transform: string;
|
|
29
|
-
export declare const _stream_writable: string;
|
|
30
|
-
export declare const string_decoder: string;
|
|
31
|
-
export declare const sys: string;
|
|
32
|
-
export declare const timers: string;
|
|
33
|
-
export declare const tls: null;
|
|
34
|
-
export declare const tty: string;
|
|
35
|
-
export declare const url: string;
|
|
36
|
-
export declare const util: string;
|
|
37
|
-
export declare const vm: string;
|
|
38
|
-
export declare const zlib: string;
|