@rspack/cli 0.2.12 → 0.3.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/dist/rspack-cli.js +4 -0
- package/dist/utils/profile.d.ts +2 -0
- package/dist/utils/profile.js +159 -0
- package/package.json +4 -3
package/dist/rspack-cli.js
CHANGED
|
@@ -115,6 +115,10 @@ class RspackCLI {
|
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
|
+
if (process.env.RSPACK_PROFILE) {
|
|
119
|
+
const { applyProfile } = await import("./utils/profile.js");
|
|
120
|
+
await applyProfile(process.env.RSPACK_PROFILE, item);
|
|
121
|
+
}
|
|
118
122
|
// cli --watch overrides the watch config
|
|
119
123
|
if (options.watch) {
|
|
120
124
|
item.watch = options.watch;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.applyProfile = void 0;
|
|
7
|
+
const inspector_1 = __importDefault(require("inspector"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const url_1 = require("url");
|
|
11
|
+
const core_1 = require("@rspack/core");
|
|
12
|
+
const timestamp = Date.now();
|
|
13
|
+
const defaultOutputDirname = path_1.default.resolve(`.rspack-profile-${timestamp}`);
|
|
14
|
+
const defaultJSCPUProfileOutput = path_1.default.join(defaultOutputDirname, `./jscpuprofile.json`);
|
|
15
|
+
const defaultRustTraceChromeOutput = path_1.default.join(defaultOutputDirname, `./trace.json`);
|
|
16
|
+
const defaultRustTraceLoggerOutput = `stdout`;
|
|
17
|
+
const defaultRustTraceFilter = "trace";
|
|
18
|
+
const defaultRustTraceLayer = "chrome";
|
|
19
|
+
const defaultLoggingOutput = path_1.default.join(defaultOutputDirname, `./logging.json`);
|
|
20
|
+
function resolveProfile(value) {
|
|
21
|
+
if (value.toUpperCase() === "ALL") {
|
|
22
|
+
return {
|
|
23
|
+
TRACE: {
|
|
24
|
+
filter: defaultRustTraceFilter,
|
|
25
|
+
layer: defaultRustTraceLayer,
|
|
26
|
+
output: defaultRustTraceChromeOutput
|
|
27
|
+
},
|
|
28
|
+
JSCPU: { output: defaultJSCPUProfileOutput },
|
|
29
|
+
LOGGING: { output: defaultLoggingOutput }
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
33
|
+
return {
|
|
34
|
+
TRACE: resolveRustTraceOptions(value.slice(1, value.length - 1)),
|
|
35
|
+
JSCPU: { output: defaultJSCPUProfileOutput },
|
|
36
|
+
LOGGING: { output: defaultLoggingOutput }
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return value.split("|").reduce((acc, cur) => {
|
|
40
|
+
if (cur.toUpperCase().startsWith("TRACE")) {
|
|
41
|
+
acc.TRACE = resolveRustTraceOptions(cur.slice(6));
|
|
42
|
+
}
|
|
43
|
+
if (cur.toUpperCase().startsWith("JSCPU")) {
|
|
44
|
+
acc.JSCPU = resolveJSCPUProfileOptions(cur.slice(6));
|
|
45
|
+
}
|
|
46
|
+
if (cur.toUpperCase().startsWith("LOGGING")) {
|
|
47
|
+
acc.LOGGING = resolveLoggingOptions(cur.slice(8));
|
|
48
|
+
}
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
}
|
|
52
|
+
// JSCPU=value
|
|
53
|
+
function resolveJSCPUProfileOptions(value) {
|
|
54
|
+
// output=filepath
|
|
55
|
+
if (value.includes("=")) {
|
|
56
|
+
const parsed = new url_1.URLSearchParams(value);
|
|
57
|
+
return { output: parsed.get("output") || defaultJSCPUProfileOutput };
|
|
58
|
+
}
|
|
59
|
+
// filepath
|
|
60
|
+
return { output: value || defaultJSCPUProfileOutput };
|
|
61
|
+
}
|
|
62
|
+
// TRACE=value
|
|
63
|
+
function resolveRustTraceOptions(value) {
|
|
64
|
+
// filter=trace&output=stdout&layer=logger
|
|
65
|
+
if (value.includes("=")) {
|
|
66
|
+
const parsed = new url_1.URLSearchParams(value);
|
|
67
|
+
const filter = parsed.get("filter") || defaultRustTraceFilter;
|
|
68
|
+
const layer = parsed.get("layer") || defaultRustTraceLayer;
|
|
69
|
+
const output = layer === "chrome"
|
|
70
|
+
? parsed.get("output") || defaultRustTraceChromeOutput
|
|
71
|
+
: parsed.get("output") || defaultRustTraceLoggerOutput;
|
|
72
|
+
if (layer !== "chrome" && layer !== "logger") {
|
|
73
|
+
throw new Error(`${layer} is not a valid layer, should be chrome or logger`);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
filter,
|
|
77
|
+
layer,
|
|
78
|
+
output
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// trace
|
|
82
|
+
return {
|
|
83
|
+
filter: value || defaultRustTraceFilter,
|
|
84
|
+
layer: defaultRustTraceLayer,
|
|
85
|
+
output: defaultRustTraceChromeOutput
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
// LOGGING=value
|
|
89
|
+
function resolveLoggingOptions(value) {
|
|
90
|
+
// output=filepath
|
|
91
|
+
if (value.includes("=")) {
|
|
92
|
+
const parsed = new url_1.URLSearchParams(value);
|
|
93
|
+
return { output: parsed.get("output") || defaultLoggingOutput };
|
|
94
|
+
}
|
|
95
|
+
// filepath
|
|
96
|
+
return { output: value || defaultLoggingOutput };
|
|
97
|
+
}
|
|
98
|
+
class RspackProfileJSCPUProfilePlugin {
|
|
99
|
+
constructor(output) {
|
|
100
|
+
this.output = output;
|
|
101
|
+
}
|
|
102
|
+
apply(compiler) {
|
|
103
|
+
const session = new inspector_1.default.Session();
|
|
104
|
+
session.connect();
|
|
105
|
+
session.post("Profiler.enable");
|
|
106
|
+
session.post("Profiler.start");
|
|
107
|
+
compiler.hooks.done.tapAsync(RspackProfileJSCPUProfilePlugin.name, (stats, callback) => {
|
|
108
|
+
if (compiler.watchMode)
|
|
109
|
+
return callback();
|
|
110
|
+
session.post("Profiler.stop", (error, param) => {
|
|
111
|
+
if (error) {
|
|
112
|
+
console.error("Failed to generate JS CPU profile:", error);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
fs_1.default.writeFileSync(this.output, JSON.stringify(param.profile));
|
|
116
|
+
});
|
|
117
|
+
return callback();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
class RspackProfileLoggingPlugin {
|
|
122
|
+
constructor(output) {
|
|
123
|
+
this.output = output;
|
|
124
|
+
}
|
|
125
|
+
apply(compiler) {
|
|
126
|
+
compiler.hooks.done.tapAsync(RspackProfileLoggingPlugin.name, (stats, callback) => {
|
|
127
|
+
if (compiler.watchMode)
|
|
128
|
+
return callback();
|
|
129
|
+
const logging = stats.toJson({
|
|
130
|
+
all: false,
|
|
131
|
+
logging: "verbose",
|
|
132
|
+
loggingTrace: true
|
|
133
|
+
});
|
|
134
|
+
fs_1.default.writeFileSync(this.output, JSON.stringify(logging));
|
|
135
|
+
return callback();
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function applyProfile(profileValue, item) {
|
|
140
|
+
const { default: exitHook } = await import("exit-hook");
|
|
141
|
+
const entries = Object.entries(resolveProfile(profileValue));
|
|
142
|
+
if (entries.length <= 0)
|
|
143
|
+
return;
|
|
144
|
+
await fs_1.default.promises.mkdir(defaultOutputDirname);
|
|
145
|
+
entries.forEach(([kind, value]) => {
|
|
146
|
+
var _a, _b;
|
|
147
|
+
if (kind === "TRACE" && "filter" in value) {
|
|
148
|
+
(0, core_1.experimental_registerGlobalTrace)(value.filter, value.layer, value.output);
|
|
149
|
+
exitHook(core_1.experimental_cleanupGlobalTrace);
|
|
150
|
+
}
|
|
151
|
+
else if (kind === "JSCPU") {
|
|
152
|
+
((_a = item.plugins) !== null && _a !== void 0 ? _a : (item.plugins = [])).push(new RspackProfileJSCPUProfilePlugin(value.output));
|
|
153
|
+
}
|
|
154
|
+
else if (kind === "LOGGING") {
|
|
155
|
+
((_b = item.plugins) !== null && _b !== void 0 ? _b : (item.plugins = [])).push(new RspackProfileLoggingPlugin(value.output));
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
exports.applyProfile = applyProfile;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "CLI for rspack",
|
|
6
6
|
"bin": {
|
|
@@ -31,13 +31,14 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@discoveryjs/json-ext": "^0.5.7",
|
|
33
33
|
"colorette": "2.0.19",
|
|
34
|
+
"exit-hook": "^3.2.0",
|
|
34
35
|
"interpret": "^3.1.1",
|
|
35
36
|
"rechoir": "^0.8.0",
|
|
36
37
|
"semver": "6.3.0",
|
|
37
38
|
"webpack-bundle-analyzer": "4.6.1",
|
|
38
39
|
"yargs": "17.6.2",
|
|
39
|
-
"@rspack/core": "0.
|
|
40
|
-
"@rspack/dev-server": "0.
|
|
40
|
+
"@rspack/core": "0.3.0",
|
|
41
|
+
"@rspack/dev-server": "0.3.0"
|
|
41
42
|
},
|
|
42
43
|
"scripts": {
|
|
43
44
|
"build": "rimraf dist/ && tsc -b ./tsconfig.build.json --force",
|