@rspack/cli 1.0.14 → 1.1.0-beta.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/bin/rspack.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ const { RspackCLI } = require("../dist/index");
3
+
4
+ async function runCLI() {
5
+ const cli = new RspackCLI();
6
+ await cli.run(process.argv);
7
+ }
8
+
9
+ runCLI();
package/dist/629.js ADDED
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ exports.ids = [
3
+ '629'
4
+ ];
5
+ exports.modules = {
6
+ "./src/utils/profile.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
7
+ __webpack_require__.d(__webpack_exports__, {
8
+ applyProfile: function() {
9
+ return applyProfile;
10
+ }
11
+ });
12
+ /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:fs");
13
+ /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/ __webpack_require__.n(node_fs__WEBPACK_IMPORTED_MODULE_0__);
14
+ /* harmony import */ var node_inspector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("node:inspector");
15
+ /* harmony import */ var node_inspector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/ __webpack_require__.n(node_inspector__WEBPACK_IMPORTED_MODULE_1__);
16
+ /* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("node:path");
17
+ /* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/ __webpack_require__.n(node_path__WEBPACK_IMPORTED_MODULE_2__);
18
+ /* harmony import */ var node_url__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("node:url");
19
+ /* harmony import */ var _rspack_core__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("@rspack/core");
20
+ /* harmony import */ var _crossImport__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./src/utils/crossImport.ts");
21
+ /*
22
+ The full syntax, remember update this when you change something in this file.
23
+
24
+ `RSPACK_PROFILE='TRACE=filter=trace&output=./rspack.trace&layer=chrome|JSCPU=output=./rspack.jscpuprofile|LOGGING=output=./rspack.logging' rspack build`
25
+ ^----------------------------------------------: querystring syntax trace options
26
+ ^: | is a delimiter for different profile options
27
+ ^---------------------------------: querystring syntax js cpuprofile options
28
+ ^: | is a delimiter for different profile options
29
+ ^------------------------------: querystring syntax stats.logging options
30
+ ^-----------: trace filter, default to `trace`, more syntax: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#example-syntax
31
+ ^--------------------: trace output, `stderr`, `stdout`, or a file path, default to `./.rspack-profile-${timestamp}/trace.json` for layer `chrome` and default to `stdout` for layer `logger`
32
+ ^-----------: trace layer, `chrome` or `logger`, default to `chrome`
33
+ ^---------------------------: js cpuprofile output, `stderr`, `stdout`, or a file path, default to `./.rspack-profile-${timestamp}/jscpuprofile.json`
34
+ ^----------------------: stats.logging output, default to `./.rspack-profile-${timestamp}/logging.json`
35
+
36
+ `RSPACK_PROFILE='TRACE=filter=trace&output=./rspack.trace&layer=chrome' rspack build`: only enable trace
37
+
38
+ `RSPACK_PROFILE=TRACE rspack build`: only enable trace, and use default options for trace
39
+
40
+ `RSPACK_PROFILE='JSCPU=output=./rspack.jscpuprofile' rspack build`: only enable js cpuprofile
41
+
42
+ `RSPACK_PROFILE=JSCPU rspack build`: only enable js cpuprofile, and use default options for js cpuprofile
43
+
44
+ `RSPACK_PROFILE='LOGGING=output=./rspack.logging' rspack build`: only enable stats.logging
45
+
46
+ `RSPACK_PROFILE=LOGGING rspack build`: only enable stats.logging, and use default options for stats.logging
47
+
48
+ `RSPACK_PROFILE=ALL rspack build`: enable all, and use default options
49
+
50
+ `RSPACK_PROFILE=[rspack_node,rspack_core] rspack build`: enable all, but customize trace filter
51
+
52
+ */ function _define_property(obj, key, value) {
53
+ if (key in obj) Object.defineProperty(obj, key, {
54
+ value: value,
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true
58
+ });
59
+ else obj[key] = value;
60
+ return obj;
61
+ }
62
+ const timestamp = Date.now();
63
+ const defaultOutputDirname = node_path__WEBPACK_IMPORTED_MODULE_2___default().resolve(`.rspack-profile-${timestamp}-${process.pid}`);
64
+ const defaultJSCPUProfileOutput = node_path__WEBPACK_IMPORTED_MODULE_2___default().join(defaultOutputDirname, "./jscpuprofile.json");
65
+ const defaultRustTraceChromeOutput = node_path__WEBPACK_IMPORTED_MODULE_2___default().join(defaultOutputDirname, "./trace.json");
66
+ const defaultRustTraceLoggerOutput = "stdout";
67
+ const defaultRustTraceFilter = "trace";
68
+ const defaultRustTraceLayer = "chrome";
69
+ const defaultLoggingOutput = node_path__WEBPACK_IMPORTED_MODULE_2___default().join(defaultOutputDirname, "./logging.json");
70
+ function resolveProfile(value) {
71
+ if ("ALL" === value.toUpperCase()) return {
72
+ TRACE: {
73
+ filter: defaultRustTraceFilter,
74
+ layer: defaultRustTraceLayer,
75
+ output: defaultRustTraceChromeOutput
76
+ },
77
+ JSCPU: {
78
+ output: defaultJSCPUProfileOutput
79
+ },
80
+ LOGGING: {
81
+ output: defaultLoggingOutput
82
+ }
83
+ };
84
+ if (value.startsWith("[") && value.endsWith("]")) return {
85
+ TRACE: resolveRustTraceOptions(value.slice(1, value.length - 1)),
86
+ JSCPU: {
87
+ output: defaultJSCPUProfileOutput
88
+ },
89
+ LOGGING: {
90
+ output: defaultLoggingOutput
91
+ }
92
+ };
93
+ return value.split("|").reduce((acc, cur)=>{
94
+ const upperCur = cur.toUpperCase();
95
+ if (upperCur.startsWith("TRACE")) acc.TRACE = resolveRustTraceOptions(cur.slice(6));
96
+ else if (upperCur.startsWith("JSCPU")) acc.JSCPU = resolveJSCPUProfileOptions(cur.slice(6));
97
+ else if (upperCur.startsWith("LOGGING")) acc.LOGGING = resolveLoggingOptions(cur.slice(8));
98
+ return acc;
99
+ }, {});
100
+ }
101
+ // JSCPU=value
102
+ function resolveJSCPUProfileOptions(value) {
103
+ // output=filepath
104
+ if (value.includes("=")) {
105
+ const parsed = new node_url__WEBPACK_IMPORTED_MODULE_3__.URLSearchParams(value);
106
+ return {
107
+ output: parsed.get("output") || defaultJSCPUProfileOutput
108
+ };
109
+ }
110
+ // filepath
111
+ return {
112
+ output: value || defaultJSCPUProfileOutput
113
+ };
114
+ }
115
+ // TRACE=value
116
+ function resolveRustTraceOptions(value) {
117
+ // filter=trace&output=stdout&layer=logger
118
+ if (value.includes("=")) {
119
+ const parsed = new node_url__WEBPACK_IMPORTED_MODULE_3__.URLSearchParams(value);
120
+ const filter = parsed.get("filter") || defaultRustTraceFilter;
121
+ const layer = parsed.get("layer") || defaultRustTraceLayer;
122
+ const output = "chrome" === layer ? parsed.get("output") || defaultRustTraceChromeOutput : parsed.get("output") || defaultRustTraceLoggerOutput;
123
+ if ("chrome" !== layer && "logger" !== layer && "console" !== layer) throw new Error(`${layer} is not a valid layer, should be chrome or logger`);
124
+ return {
125
+ filter,
126
+ layer,
127
+ output
128
+ };
129
+ }
130
+ // trace
131
+ return {
132
+ filter: value || defaultRustTraceFilter,
133
+ layer: defaultRustTraceLayer,
134
+ output: defaultRustTraceChromeOutput
135
+ };
136
+ }
137
+ // LOGGING=value
138
+ function resolveLoggingOptions(value) {
139
+ // output=filepath
140
+ if (value.includes("=")) {
141
+ const parsed = new node_url__WEBPACK_IMPORTED_MODULE_3__.URLSearchParams(value);
142
+ return {
143
+ output: parsed.get("output") || defaultLoggingOutput
144
+ };
145
+ }
146
+ // filepath
147
+ return {
148
+ output: value || defaultLoggingOutput
149
+ };
150
+ }
151
+ class RspackProfileJSCPUProfilePlugin {
152
+ apply(compiler) {
153
+ const session = new (node_inspector__WEBPACK_IMPORTED_MODULE_1___default()).Session();
154
+ session.connect();
155
+ session.post("Profiler.enable");
156
+ session.post("Profiler.start");
157
+ compiler.hooks.done.tapAsync(RspackProfileJSCPUProfilePlugin.name, (_stats, callback)=>{
158
+ if (compiler.watchMode) return callback();
159
+ session.post("Profiler.stop", (error, param)=>{
160
+ if (error) {
161
+ console.error("Failed to generate JS CPU profile:", error);
162
+ return;
163
+ }
164
+ node_fs__WEBPACK_IMPORTED_MODULE_0___default().writeFileSync(this.output, JSON.stringify(param.profile));
165
+ });
166
+ return callback();
167
+ });
168
+ }
169
+ constructor(output){
170
+ _define_property(this, "output", void 0);
171
+ this.output = output;
172
+ }
173
+ }
174
+ class RspackProfileLoggingPlugin {
175
+ apply(compiler) {
176
+ compiler.hooks.done.tapAsync(RspackProfileLoggingPlugin.name, (stats, callback)=>{
177
+ if (compiler.watchMode) return callback();
178
+ const logging = stats.toJson({
179
+ all: false,
180
+ logging: "verbose",
181
+ loggingTrace: true
182
+ });
183
+ node_fs__WEBPACK_IMPORTED_MODULE_0___default().writeFileSync(this.output, JSON.stringify(logging));
184
+ return callback();
185
+ });
186
+ }
187
+ constructor(output){
188
+ _define_property(this, "output", void 0);
189
+ this.output = output;
190
+ }
191
+ }
192
+ async function applyProfile(profileValue, item) {
193
+ const { default: exitHook } = await (0, _crossImport__WEBPACK_IMPORTED_MODULE_5__ /* .dynamicImport */ .y)("exit-hook");
194
+ const entries = Object.entries(resolveProfile(profileValue));
195
+ if (entries.length <= 0) return;
196
+ await node_fs__WEBPACK_IMPORTED_MODULE_0___default().promises.mkdir(defaultOutputDirname);
197
+ for (const [kind, value] of entries){
198
+ await ensureFileDir(value.output);
199
+ if ("TRACE" === kind && "filter" in value) {
200
+ _rspack_core__WEBPACK_IMPORTED_MODULE_4__.rspack.experiments.globalTrace.register(value.filter, value.layer, value.output);
201
+ exitHook(_rspack_core__WEBPACK_IMPORTED_MODULE_4__.rspack.experiments.globalTrace.cleanup);
202
+ } else if ("JSCPU" === kind) (item.plugins ??= []).push(new RspackProfileJSCPUProfilePlugin(value.output));
203
+ else if ("LOGGING" === kind) (item.plugins ??= []).push(new RspackProfileLoggingPlugin(value.output));
204
+ }
205
+ }
206
+ async function ensureFileDir(outputFilePath) {
207
+ const dir = node_path__WEBPACK_IMPORTED_MODULE_2___default().dirname(outputFilePath);
208
+ await node_fs__WEBPACK_IMPORTED_MODULE_0___default().promises.mkdir(dir, {
209
+ recursive: true
210
+ });
211
+ return dir;
212
+ }
213
+ }
214
+ };
package/dist/629.mjs ADDED
@@ -0,0 +1,210 @@
1
+ export const ids = [
2
+ '629'
3
+ ];
4
+ export const modules = {
5
+ "./src/utils/profile.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
6
+ __webpack_require__.d(__webpack_exports__, {
7
+ applyProfile: function() {
8
+ return applyProfile;
9
+ }
10
+ });
11
+ /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:fs");
12
+ /* harmony import */ var node_inspector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("node:inspector");
13
+ /* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("node:path");
14
+ /* harmony import */ var node_url__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("node:url");
15
+ /* harmony import */ var _rspack_core__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("@rspack/core");
16
+ /* harmony import */ var _crossImport__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./src/utils/crossImport.ts");
17
+ /*
18
+ The full syntax, remember update this when you change something in this file.
19
+
20
+ `RSPACK_PROFILE='TRACE=filter=trace&output=./rspack.trace&layer=chrome|JSCPU=output=./rspack.jscpuprofile|LOGGING=output=./rspack.logging' rspack build`
21
+ ^----------------------------------------------: querystring syntax trace options
22
+ ^: | is a delimiter for different profile options
23
+ ^---------------------------------: querystring syntax js cpuprofile options
24
+ ^: | is a delimiter for different profile options
25
+ ^------------------------------: querystring syntax stats.logging options
26
+ ^-----------: trace filter, default to `trace`, more syntax: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#example-syntax
27
+ ^--------------------: trace output, `stderr`, `stdout`, or a file path, default to `./.rspack-profile-${timestamp}/trace.json` for layer `chrome` and default to `stdout` for layer `logger`
28
+ ^-----------: trace layer, `chrome` or `logger`, default to `chrome`
29
+ ^---------------------------: js cpuprofile output, `stderr`, `stdout`, or a file path, default to `./.rspack-profile-${timestamp}/jscpuprofile.json`
30
+ ^----------------------: stats.logging output, default to `./.rspack-profile-${timestamp}/logging.json`
31
+
32
+ `RSPACK_PROFILE='TRACE=filter=trace&output=./rspack.trace&layer=chrome' rspack build`: only enable trace
33
+
34
+ `RSPACK_PROFILE=TRACE rspack build`: only enable trace, and use default options for trace
35
+
36
+ `RSPACK_PROFILE='JSCPU=output=./rspack.jscpuprofile' rspack build`: only enable js cpuprofile
37
+
38
+ `RSPACK_PROFILE=JSCPU rspack build`: only enable js cpuprofile, and use default options for js cpuprofile
39
+
40
+ `RSPACK_PROFILE='LOGGING=output=./rspack.logging' rspack build`: only enable stats.logging
41
+
42
+ `RSPACK_PROFILE=LOGGING rspack build`: only enable stats.logging, and use default options for stats.logging
43
+
44
+ `RSPACK_PROFILE=ALL rspack build`: enable all, and use default options
45
+
46
+ `RSPACK_PROFILE=[rspack_node,rspack_core] rspack build`: enable all, but customize trace filter
47
+
48
+ */ function _define_property(obj, key, value) {
49
+ if (key in obj) Object.defineProperty(obj, key, {
50
+ value: value,
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true
54
+ });
55
+ else obj[key] = value;
56
+ return obj;
57
+ }
58
+ const timestamp = Date.now();
59
+ const defaultOutputDirname = node_path__WEBPACK_IMPORTED_MODULE_2__["default"].resolve(`.rspack-profile-${timestamp}-${process.pid}`);
60
+ const defaultJSCPUProfileOutput = node_path__WEBPACK_IMPORTED_MODULE_2__["default"].join(defaultOutputDirname, "./jscpuprofile.json");
61
+ const defaultRustTraceChromeOutput = node_path__WEBPACK_IMPORTED_MODULE_2__["default"].join(defaultOutputDirname, "./trace.json");
62
+ const defaultRustTraceLoggerOutput = "stdout";
63
+ const defaultRustTraceFilter = "trace";
64
+ const defaultRustTraceLayer = "chrome";
65
+ const defaultLoggingOutput = node_path__WEBPACK_IMPORTED_MODULE_2__["default"].join(defaultOutputDirname, "./logging.json");
66
+ function resolveProfile(value) {
67
+ if ("ALL" === value.toUpperCase()) return {
68
+ TRACE: {
69
+ filter: defaultRustTraceFilter,
70
+ layer: defaultRustTraceLayer,
71
+ output: defaultRustTraceChromeOutput
72
+ },
73
+ JSCPU: {
74
+ output: defaultJSCPUProfileOutput
75
+ },
76
+ LOGGING: {
77
+ output: defaultLoggingOutput
78
+ }
79
+ };
80
+ if (value.startsWith("[") && value.endsWith("]")) return {
81
+ TRACE: resolveRustTraceOptions(value.slice(1, value.length - 1)),
82
+ JSCPU: {
83
+ output: defaultJSCPUProfileOutput
84
+ },
85
+ LOGGING: {
86
+ output: defaultLoggingOutput
87
+ }
88
+ };
89
+ return value.split("|").reduce((acc, cur)=>{
90
+ const upperCur = cur.toUpperCase();
91
+ if (upperCur.startsWith("TRACE")) acc.TRACE = resolveRustTraceOptions(cur.slice(6));
92
+ else if (upperCur.startsWith("JSCPU")) acc.JSCPU = resolveJSCPUProfileOptions(cur.slice(6));
93
+ else if (upperCur.startsWith("LOGGING")) acc.LOGGING = resolveLoggingOptions(cur.slice(8));
94
+ return acc;
95
+ }, {});
96
+ }
97
+ // JSCPU=value
98
+ function resolveJSCPUProfileOptions(value) {
99
+ // output=filepath
100
+ if (value.includes("=")) {
101
+ const parsed = new node_url__WEBPACK_IMPORTED_MODULE_3__.URLSearchParams(value);
102
+ return {
103
+ output: parsed.get("output") || defaultJSCPUProfileOutput
104
+ };
105
+ }
106
+ // filepath
107
+ return {
108
+ output: value || defaultJSCPUProfileOutput
109
+ };
110
+ }
111
+ // TRACE=value
112
+ function resolveRustTraceOptions(value) {
113
+ // filter=trace&output=stdout&layer=logger
114
+ if (value.includes("=")) {
115
+ const parsed = new node_url__WEBPACK_IMPORTED_MODULE_3__.URLSearchParams(value);
116
+ const filter = parsed.get("filter") || defaultRustTraceFilter;
117
+ const layer = parsed.get("layer") || defaultRustTraceLayer;
118
+ const output = "chrome" === layer ? parsed.get("output") || defaultRustTraceChromeOutput : parsed.get("output") || defaultRustTraceLoggerOutput;
119
+ if ("chrome" !== layer && "logger" !== layer && "console" !== layer) throw new Error(`${layer} is not a valid layer, should be chrome or logger`);
120
+ return {
121
+ filter,
122
+ layer,
123
+ output
124
+ };
125
+ }
126
+ // trace
127
+ return {
128
+ filter: value || defaultRustTraceFilter,
129
+ layer: defaultRustTraceLayer,
130
+ output: defaultRustTraceChromeOutput
131
+ };
132
+ }
133
+ // LOGGING=value
134
+ function resolveLoggingOptions(value) {
135
+ // output=filepath
136
+ if (value.includes("=")) {
137
+ const parsed = new node_url__WEBPACK_IMPORTED_MODULE_3__.URLSearchParams(value);
138
+ return {
139
+ output: parsed.get("output") || defaultLoggingOutput
140
+ };
141
+ }
142
+ // filepath
143
+ return {
144
+ output: value || defaultLoggingOutput
145
+ };
146
+ }
147
+ class RspackProfileJSCPUProfilePlugin {
148
+ apply(compiler) {
149
+ const session = new node_inspector__WEBPACK_IMPORTED_MODULE_1__["default"].Session();
150
+ session.connect();
151
+ session.post("Profiler.enable");
152
+ session.post("Profiler.start");
153
+ compiler.hooks.done.tapAsync(RspackProfileJSCPUProfilePlugin.name, (_stats, callback)=>{
154
+ if (compiler.watchMode) return callback();
155
+ session.post("Profiler.stop", (error, param)=>{
156
+ if (error) {
157
+ console.error("Failed to generate JS CPU profile:", error);
158
+ return;
159
+ }
160
+ node_fs__WEBPACK_IMPORTED_MODULE_0__["default"].writeFileSync(this.output, JSON.stringify(param.profile));
161
+ });
162
+ return callback();
163
+ });
164
+ }
165
+ constructor(output){
166
+ _define_property(this, "output", void 0);
167
+ this.output = output;
168
+ }
169
+ }
170
+ class RspackProfileLoggingPlugin {
171
+ apply(compiler) {
172
+ compiler.hooks.done.tapAsync(RspackProfileLoggingPlugin.name, (stats, callback)=>{
173
+ if (compiler.watchMode) return callback();
174
+ const logging = stats.toJson({
175
+ all: false,
176
+ logging: "verbose",
177
+ loggingTrace: true
178
+ });
179
+ node_fs__WEBPACK_IMPORTED_MODULE_0__["default"].writeFileSync(this.output, JSON.stringify(logging));
180
+ return callback();
181
+ });
182
+ }
183
+ constructor(output){
184
+ _define_property(this, "output", void 0);
185
+ this.output = output;
186
+ }
187
+ }
188
+ async function applyProfile(profileValue, item) {
189
+ const { default: exitHook } = await (0, _crossImport__WEBPACK_IMPORTED_MODULE_5__ /* .dynamicImport */ .y)("exit-hook");
190
+ const entries = Object.entries(resolveProfile(profileValue));
191
+ if (entries.length <= 0) return;
192
+ await node_fs__WEBPACK_IMPORTED_MODULE_0__["default"].promises.mkdir(defaultOutputDirname);
193
+ for (const [kind, value] of entries){
194
+ await ensureFileDir(value.output);
195
+ if ("TRACE" === kind && "filter" in value) {
196
+ _rspack_core__WEBPACK_IMPORTED_MODULE_4__.rspack.experiments.globalTrace.register(value.filter, value.layer, value.output);
197
+ exitHook(_rspack_core__WEBPACK_IMPORTED_MODULE_4__.rspack.experiments.globalTrace.cleanup);
198
+ } else if ("JSCPU" === kind) (item.plugins ??= []).push(new RspackProfileJSCPUProfilePlugin(value.output));
199
+ else if ("LOGGING" === kind) (item.plugins ??= []).push(new RspackProfileLoggingPlugin(value.output));
200
+ }
201
+ }
202
+ async function ensureFileDir(outputFilePath) {
203
+ const dir = node_path__WEBPACK_IMPORTED_MODULE_2__["default"].dirname(outputFilePath);
204
+ await node_fs__WEBPACK_IMPORTED_MODULE_0__["default"].promises.mkdir(dir, {
205
+ recursive: true
206
+ });
207
+ return dir;
208
+ }
209
+ }
210
+ };