@rspack/cli 1.0.14 → 1.1.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 +22 -0
- package/dist/629.js +214 -0
- package/dist/629.mjs +210 -0
- package/dist/index.js +887 -20
- package/dist/index.mjs +822 -0
- package/dist/utils/crossImport.d.ts +1 -1
- package/package.json +14 -9
- package/bin/rspack +0 -3
- package/dist/bootstrap.d.ts +0 -1
- package/dist/bootstrap.js +0 -8
- package/dist/cli.js +0 -257
- package/dist/commands/build.js +0 -132
- package/dist/commands/preview.js +0 -73
- package/dist/commands/serve.js +0 -125
- package/dist/constants.js +0 -12
- package/dist/types.js +0 -2
- package/dist/utils/crossImport.js +0 -26
- package/dist/utils/findConfig.js +0 -15
- package/dist/utils/isEsmFile.js +0 -19
- package/dist/utils/isTsFile.js +0 -11
- package/dist/utils/loadConfig.js +0 -54
- package/dist/utils/options.js +0 -161
- package/dist/utils/profile.js +0 -196
- package/dist/utils/readPackageUp.js +0 -26
package/dist/constants.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_EXTENSIONS = exports.DEFAULT_CONFIG_NAME = void 0;
|
|
4
|
-
exports.DEFAULT_CONFIG_NAME = "rspack.config";
|
|
5
|
-
exports.DEFAULT_EXTENSIONS = [
|
|
6
|
-
".js",
|
|
7
|
-
".ts",
|
|
8
|
-
".mjs",
|
|
9
|
-
".mts",
|
|
10
|
-
".cjs",
|
|
11
|
-
".cts"
|
|
12
|
-
];
|
package/dist/types.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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.dynamicImport = void 0;
|
|
7
|
-
const node_url_1 = require("node:url");
|
|
8
|
-
const isEsmFile_1 = __importDefault(require("./isEsmFile"));
|
|
9
|
-
/**
|
|
10
|
-
* Dynamically import files. It will make sure it's not being compiled away by TS/Rollup.
|
|
11
|
-
*/
|
|
12
|
-
exports.dynamicImport = new Function("path", "return import(path)");
|
|
13
|
-
const crossImport = async (path, cwd = process.cwd()) => {
|
|
14
|
-
if ((0, isEsmFile_1.default)(path, cwd)) {
|
|
15
|
-
const url = (0, node_url_1.pathToFileURL)(path).href;
|
|
16
|
-
const { default: config } = await (0, exports.dynamicImport)(url);
|
|
17
|
-
return config;
|
|
18
|
-
}
|
|
19
|
-
let result = require(path);
|
|
20
|
-
// compatible with export default config in common ts config
|
|
21
|
-
if (result && typeof result === "object" && "default" in result) {
|
|
22
|
-
result = result.default || {};
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
exports.default = crossImport;
|
package/dist/utils/findConfig.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
|
-
const constants_1 = require("../constants");
|
|
8
|
-
/**
|
|
9
|
-
* Takes a basePath like `webpack.config`, return `webpack.config.{ext}` if
|
|
10
|
-
* exists. returns undefined if none of them exists
|
|
11
|
-
*/
|
|
12
|
-
const findConfig = (basePath) => {
|
|
13
|
-
return constants_1.DEFAULT_EXTENSIONS.map(ext => basePath + ext).find(node_fs_1.default.existsSync);
|
|
14
|
-
};
|
|
15
|
-
exports.default = findConfig;
|
package/dist/utils/isEsmFile.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
-
const readPackageUp_1 = __importDefault(require("./readPackageUp"));
|
|
8
|
-
const isEsmFile = (filePath, cwd = process.cwd()) => {
|
|
9
|
-
const ext = node_path_1.default.extname(filePath);
|
|
10
|
-
if (/\.(mjs|mts)$/.test(ext)) {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
if (/\.(cjs|cts)/.test(ext)) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
const packageJson = (0, readPackageUp_1.default)(cwd);
|
|
17
|
-
return packageJson?.type === "module";
|
|
18
|
-
};
|
|
19
|
-
exports.default = isEsmFile;
|
package/dist/utils/isTsFile.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
-
const isTsFile = (configPath) => {
|
|
8
|
-
const ext = node_path_1.default.extname(configPath);
|
|
9
|
-
return /\.(c|m)?ts$/.test(ext);
|
|
10
|
-
};
|
|
11
|
-
exports.default = isTsFile;
|
package/dist/utils/loadConfig.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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.loadRspackConfig = loadRspackConfig;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const interpret_1 = __importDefault(require("interpret"));
|
|
10
|
-
const rechoir_1 = __importDefault(require("rechoir"));
|
|
11
|
-
const crossImport_1 = __importDefault(require("./crossImport"));
|
|
12
|
-
const findConfig_1 = __importDefault(require("./findConfig"));
|
|
13
|
-
const isEsmFile_1 = __importDefault(require("./isEsmFile"));
|
|
14
|
-
const isTsFile_1 = __importDefault(require("./isTsFile"));
|
|
15
|
-
const DEFAULT_CONFIG_NAME = "rspack.config";
|
|
16
|
-
const registerLoader = (configPath) => {
|
|
17
|
-
const ext = node_path_1.default.extname(configPath);
|
|
18
|
-
// TODO implement good `.mts` support after https://github.com/gulpjs/rechoir/issues/43
|
|
19
|
-
// For ESM and `.mts` you need to use: 'NODE_OPTIONS="--loader ts-node/esm" rspack build --config ./rspack.config.mts'
|
|
20
|
-
if ((0, isEsmFile_1.default)(configPath) && (0, isTsFile_1.default)(configPath)) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const extensions = Object.fromEntries(Object.entries(interpret_1.default.extensions).filter(([key]) => key === ext));
|
|
24
|
-
if (Object.keys(extensions).length === 0) {
|
|
25
|
-
throw new Error(`config file "${configPath}" is not supported.`);
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
rechoir_1.default.prepare(extensions, configPath);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
const failures = error?.failures;
|
|
32
|
-
if (failures) {
|
|
33
|
-
const messages = failures.map(failure => failure.error.message);
|
|
34
|
-
throw new Error(`${messages.join("\n")}`);
|
|
35
|
-
}
|
|
36
|
-
throw error;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
40
|
-
if (options.config) {
|
|
41
|
-
const configPath = node_path_1.default.resolve(cwd, options.config);
|
|
42
|
-
if (!node_fs_1.default.existsSync(configPath)) {
|
|
43
|
-
throw new Error(`config file "${configPath}" not found.`);
|
|
44
|
-
}
|
|
45
|
-
(0, isTsFile_1.default)(configPath) && registerLoader(configPath);
|
|
46
|
-
return (0, crossImport_1.default)(configPath, cwd);
|
|
47
|
-
}
|
|
48
|
-
const defaultConfig = (0, findConfig_1.default)(node_path_1.default.resolve(cwd, DEFAULT_CONFIG_NAME));
|
|
49
|
-
if (defaultConfig) {
|
|
50
|
-
(0, isTsFile_1.default)(defaultConfig) && registerLoader(defaultConfig);
|
|
51
|
-
return (0, crossImport_1.default)(defaultConfig, cwd);
|
|
52
|
-
}
|
|
53
|
-
return {};
|
|
54
|
-
}
|
package/dist/utils/options.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.previewOptions = exports.commonOptions = void 0;
|
|
4
|
-
exports.normalizeEnv = normalizeEnv;
|
|
5
|
-
exports.setBuiltinEnvArg = setBuiltinEnvArg;
|
|
6
|
-
exports.ensureEnvObject = ensureEnvObject;
|
|
7
|
-
const commonOptions = (yargs) => {
|
|
8
|
-
return yargs
|
|
9
|
-
.options({
|
|
10
|
-
config: {
|
|
11
|
-
g: true,
|
|
12
|
-
type: "string",
|
|
13
|
-
describe: "config file",
|
|
14
|
-
alias: "c"
|
|
15
|
-
},
|
|
16
|
-
entry: {
|
|
17
|
-
type: "array",
|
|
18
|
-
string: true,
|
|
19
|
-
describe: "entry file"
|
|
20
|
-
},
|
|
21
|
-
"output-path": {
|
|
22
|
-
type: "string",
|
|
23
|
-
describe: "output path dir",
|
|
24
|
-
alias: "o"
|
|
25
|
-
},
|
|
26
|
-
mode: { type: "string", describe: "mode", alias: "m" },
|
|
27
|
-
watch: {
|
|
28
|
-
type: "boolean",
|
|
29
|
-
default: false,
|
|
30
|
-
describe: "watch",
|
|
31
|
-
alias: "w"
|
|
32
|
-
},
|
|
33
|
-
env: {
|
|
34
|
-
type: "array",
|
|
35
|
-
string: true,
|
|
36
|
-
describe: "env passed to config function"
|
|
37
|
-
},
|
|
38
|
-
"node-env": {
|
|
39
|
-
string: true,
|
|
40
|
-
describe: "sets process.env.NODE_ENV to be specified value"
|
|
41
|
-
},
|
|
42
|
-
devtool: {
|
|
43
|
-
type: "boolean",
|
|
44
|
-
default: false,
|
|
45
|
-
describe: "devtool",
|
|
46
|
-
alias: "d"
|
|
47
|
-
},
|
|
48
|
-
configName: {
|
|
49
|
-
type: "array",
|
|
50
|
-
string: true,
|
|
51
|
-
describe: "Name of the configuration to use."
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
.alias({ v: "version", h: "help" });
|
|
55
|
-
};
|
|
56
|
-
exports.commonOptions = commonOptions;
|
|
57
|
-
const previewOptions = (yargs) => {
|
|
58
|
-
return yargs
|
|
59
|
-
.positional("dir", {
|
|
60
|
-
type: "string",
|
|
61
|
-
describe: "directory want to preview"
|
|
62
|
-
})
|
|
63
|
-
.options({
|
|
64
|
-
publicPath: {
|
|
65
|
-
type: "string",
|
|
66
|
-
describe: "static resource server path"
|
|
67
|
-
},
|
|
68
|
-
config: {
|
|
69
|
-
g: true,
|
|
70
|
-
type: "string",
|
|
71
|
-
describe: "config file",
|
|
72
|
-
alias: "c"
|
|
73
|
-
},
|
|
74
|
-
port: {
|
|
75
|
-
type: "number",
|
|
76
|
-
describe: "preview server port"
|
|
77
|
-
},
|
|
78
|
-
host: {
|
|
79
|
-
type: "string",
|
|
80
|
-
describe: "preview server host"
|
|
81
|
-
},
|
|
82
|
-
open: {
|
|
83
|
-
type: "boolean",
|
|
84
|
-
describe: "open browser"
|
|
85
|
-
},
|
|
86
|
-
// same as devServer.server
|
|
87
|
-
server: {
|
|
88
|
-
type: "string",
|
|
89
|
-
describe: "Configuration items for the server."
|
|
90
|
-
},
|
|
91
|
-
configName: {
|
|
92
|
-
type: "array",
|
|
93
|
-
string: true,
|
|
94
|
-
describe: "Name of the configuration to use."
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
exports.previewOptions = previewOptions;
|
|
99
|
-
function normalizeEnv(argv) {
|
|
100
|
-
function parseValue(previous, value) {
|
|
101
|
-
const [allKeys, val] = value.split(/=(.+)/, 2);
|
|
102
|
-
const splitKeys = allKeys.split(/\.(?!$)/);
|
|
103
|
-
let prevRef = previous;
|
|
104
|
-
splitKeys.forEach((key, index) => {
|
|
105
|
-
let someKey = key;
|
|
106
|
-
// https://github.com/webpack/webpack-cli/issues/3284
|
|
107
|
-
if (someKey.endsWith("=")) {
|
|
108
|
-
// remove '=' from key
|
|
109
|
-
someKey = someKey.slice(0, -1);
|
|
110
|
-
prevRef[someKey] = undefined;
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (!prevRef[someKey] || typeof prevRef[someKey] === "string") {
|
|
114
|
-
prevRef[someKey] = {};
|
|
115
|
-
}
|
|
116
|
-
if (index === splitKeys.length - 1) {
|
|
117
|
-
if (typeof val === "string") {
|
|
118
|
-
prevRef[someKey] = val;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
prevRef[someKey] = true;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
prevRef = prevRef[someKey];
|
|
125
|
-
});
|
|
126
|
-
return previous;
|
|
127
|
-
}
|
|
128
|
-
const envObj = (argv.env ?? []).reduce(parseValue, {});
|
|
129
|
-
argv.env = envObj;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* set builtin env from cli - like `WEBPACK_BUNDLE=true`. also for `RSPACK_` prefixed.
|
|
133
|
-
* @param env the `argv.env` object
|
|
134
|
-
* @param envNameSuffix the added env will be `WEBPACK_${envNameSuffix}` and `RSPACK_${envNameSuffix}`
|
|
135
|
-
* @param value
|
|
136
|
-
*/
|
|
137
|
-
function setBuiltinEnvArg(env, envNameSuffix, value) {
|
|
138
|
-
const envNames = [
|
|
139
|
-
// TODO: breaking change
|
|
140
|
-
// `WEBPACK_${envNameSuffix}`,
|
|
141
|
-
`RSPACK_${envNameSuffix}`
|
|
142
|
-
];
|
|
143
|
-
for (const envName of envNames) {
|
|
144
|
-
if (envName in env) {
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
env[envName] = value;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* infer `argv.env` as an object for it was transformed from array to object after `normalizeEnv` middleware
|
|
152
|
-
* @returns the reference of `argv.env` object
|
|
153
|
-
*/
|
|
154
|
-
function ensureEnvObject(options) {
|
|
155
|
-
if (Array.isArray(options.env)) {
|
|
156
|
-
// in case that cli haven't got `normalizeEnv` middleware applied
|
|
157
|
-
normalizeEnv(options);
|
|
158
|
-
}
|
|
159
|
-
options.env = options.env || {};
|
|
160
|
-
return options.env;
|
|
161
|
-
}
|
package/dist/utils/profile.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
The full syntax, remember update this when you change something in this file.
|
|
4
|
-
|
|
5
|
-
`RSPACK_PROFILE='TRACE=filter=trace&output=./rspack.trace&layer=chrome|JSCPU=output=./rspack.jscpuprofile|LOGGING=output=./rspack.logging' rspack build`
|
|
6
|
-
^----------------------------------------------: querystring syntax trace options
|
|
7
|
-
^: | is a delimiter for different profile options
|
|
8
|
-
^---------------------------------: querystring syntax js cpuprofile options
|
|
9
|
-
^: | is a delimiter for different profile options
|
|
10
|
-
^------------------------------: querystring syntax stats.logging options
|
|
11
|
-
^-----------: trace filter, default to `trace`, more syntax: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#example-syntax
|
|
12
|
-
^--------------------: 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`
|
|
13
|
-
^-----------: trace layer, `chrome` or `logger`, default to `chrome`
|
|
14
|
-
^---------------------------: js cpuprofile output, `stderr`, `stdout`, or a file path, default to `./.rspack-profile-${timestamp}/jscpuprofile.json`
|
|
15
|
-
^----------------------: stats.logging output, default to `./.rspack-profile-${timestamp}/logging.json`
|
|
16
|
-
|
|
17
|
-
`RSPACK_PROFILE='TRACE=filter=trace&output=./rspack.trace&layer=chrome' rspack build`: only enable trace
|
|
18
|
-
|
|
19
|
-
`RSPACK_PROFILE=TRACE rspack build`: only enable trace, and use default options for trace
|
|
20
|
-
|
|
21
|
-
`RSPACK_PROFILE='JSCPU=output=./rspack.jscpuprofile' rspack build`: only enable js cpuprofile
|
|
22
|
-
|
|
23
|
-
`RSPACK_PROFILE=JSCPU rspack build`: only enable js cpuprofile, and use default options for js cpuprofile
|
|
24
|
-
|
|
25
|
-
`RSPACK_PROFILE='LOGGING=output=./rspack.logging' rspack build`: only enable stats.logging
|
|
26
|
-
|
|
27
|
-
`RSPACK_PROFILE=LOGGING rspack build`: only enable stats.logging, and use default options for stats.logging
|
|
28
|
-
|
|
29
|
-
`RSPACK_PROFILE=ALL rspack build`: enable all, and use default options
|
|
30
|
-
|
|
31
|
-
`RSPACK_PROFILE=[rspack_node,rspack_core] rspack build`: enable all, but customize trace filter
|
|
32
|
-
|
|
33
|
-
*/
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.applyProfile = applyProfile;
|
|
39
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
40
|
-
const node_inspector_1 = __importDefault(require("node:inspector"));
|
|
41
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
42
|
-
const node_url_1 = require("node:url");
|
|
43
|
-
const core_1 = require("@rspack/core");
|
|
44
|
-
const timestamp = Date.now();
|
|
45
|
-
const defaultOutputDirname = node_path_1.default.resolve(`.rspack-profile-${timestamp}-${process.pid}`);
|
|
46
|
-
const defaultJSCPUProfileOutput = node_path_1.default.join(defaultOutputDirname, "./jscpuprofile.json");
|
|
47
|
-
const defaultRustTraceChromeOutput = node_path_1.default.join(defaultOutputDirname, "./trace.json");
|
|
48
|
-
const defaultRustTraceLoggerOutput = "stdout";
|
|
49
|
-
const defaultRustTraceFilter = "trace";
|
|
50
|
-
const defaultRustTraceLayer = "chrome";
|
|
51
|
-
const defaultLoggingOutput = node_path_1.default.join(defaultOutputDirname, "./logging.json");
|
|
52
|
-
function resolveProfile(value) {
|
|
53
|
-
if (value.toUpperCase() === "ALL") {
|
|
54
|
-
return {
|
|
55
|
-
TRACE: {
|
|
56
|
-
filter: defaultRustTraceFilter,
|
|
57
|
-
layer: defaultRustTraceLayer,
|
|
58
|
-
output: defaultRustTraceChromeOutput
|
|
59
|
-
},
|
|
60
|
-
JSCPU: { output: defaultJSCPUProfileOutput },
|
|
61
|
-
LOGGING: { output: defaultLoggingOutput }
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
if (value.startsWith("[") && value.endsWith("]")) {
|
|
65
|
-
return {
|
|
66
|
-
TRACE: resolveRustTraceOptions(value.slice(1, value.length - 1)),
|
|
67
|
-
JSCPU: { output: defaultJSCPUProfileOutput },
|
|
68
|
-
LOGGING: { output: defaultLoggingOutput }
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
return value.split("|").reduce((acc, cur) => {
|
|
72
|
-
const upperCur = cur.toUpperCase();
|
|
73
|
-
if (upperCur.startsWith("TRACE")) {
|
|
74
|
-
acc.TRACE = resolveRustTraceOptions(cur.slice(6));
|
|
75
|
-
}
|
|
76
|
-
else if (upperCur.startsWith("JSCPU")) {
|
|
77
|
-
acc.JSCPU = resolveJSCPUProfileOptions(cur.slice(6));
|
|
78
|
-
}
|
|
79
|
-
else if (upperCur.startsWith("LOGGING")) {
|
|
80
|
-
acc.LOGGING = resolveLoggingOptions(cur.slice(8));
|
|
81
|
-
}
|
|
82
|
-
return acc;
|
|
83
|
-
}, {});
|
|
84
|
-
}
|
|
85
|
-
// JSCPU=value
|
|
86
|
-
function resolveJSCPUProfileOptions(value) {
|
|
87
|
-
// output=filepath
|
|
88
|
-
if (value.includes("=")) {
|
|
89
|
-
const parsed = new node_url_1.URLSearchParams(value);
|
|
90
|
-
return { output: parsed.get("output") || defaultJSCPUProfileOutput };
|
|
91
|
-
}
|
|
92
|
-
// filepath
|
|
93
|
-
return { output: value || defaultJSCPUProfileOutput };
|
|
94
|
-
}
|
|
95
|
-
// TRACE=value
|
|
96
|
-
function resolveRustTraceOptions(value) {
|
|
97
|
-
// filter=trace&output=stdout&layer=logger
|
|
98
|
-
if (value.includes("=")) {
|
|
99
|
-
const parsed = new node_url_1.URLSearchParams(value);
|
|
100
|
-
const filter = parsed.get("filter") || defaultRustTraceFilter;
|
|
101
|
-
const layer = parsed.get("layer") || defaultRustTraceLayer;
|
|
102
|
-
const output = layer === "chrome"
|
|
103
|
-
? parsed.get("output") || defaultRustTraceChromeOutput
|
|
104
|
-
: parsed.get("output") || defaultRustTraceLoggerOutput;
|
|
105
|
-
if (layer !== "chrome" && layer !== "logger" && layer !== "console") {
|
|
106
|
-
throw new Error(`${layer} is not a valid layer, should be chrome or logger`);
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
filter,
|
|
110
|
-
layer,
|
|
111
|
-
output
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
// trace
|
|
115
|
-
return {
|
|
116
|
-
filter: value || defaultRustTraceFilter,
|
|
117
|
-
layer: defaultRustTraceLayer,
|
|
118
|
-
output: defaultRustTraceChromeOutput
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
// LOGGING=value
|
|
122
|
-
function resolveLoggingOptions(value) {
|
|
123
|
-
// output=filepath
|
|
124
|
-
if (value.includes("=")) {
|
|
125
|
-
const parsed = new node_url_1.URLSearchParams(value);
|
|
126
|
-
return { output: parsed.get("output") || defaultLoggingOutput };
|
|
127
|
-
}
|
|
128
|
-
// filepath
|
|
129
|
-
return { output: value || defaultLoggingOutput };
|
|
130
|
-
}
|
|
131
|
-
class RspackProfileJSCPUProfilePlugin {
|
|
132
|
-
constructor(output) {
|
|
133
|
-
this.output = output;
|
|
134
|
-
}
|
|
135
|
-
apply(compiler) {
|
|
136
|
-
const session = new node_inspector_1.default.Session();
|
|
137
|
-
session.connect();
|
|
138
|
-
session.post("Profiler.enable");
|
|
139
|
-
session.post("Profiler.start");
|
|
140
|
-
compiler.hooks.done.tapAsync(RspackProfileJSCPUProfilePlugin.name, (_stats, callback) => {
|
|
141
|
-
if (compiler.watchMode)
|
|
142
|
-
return callback();
|
|
143
|
-
session.post("Profiler.stop", (error, param) => {
|
|
144
|
-
if (error) {
|
|
145
|
-
console.error("Failed to generate JS CPU profile:", error);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
node_fs_1.default.writeFileSync(this.output, JSON.stringify(param.profile));
|
|
149
|
-
});
|
|
150
|
-
return callback();
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
class RspackProfileLoggingPlugin {
|
|
155
|
-
constructor(output) {
|
|
156
|
-
this.output = output;
|
|
157
|
-
}
|
|
158
|
-
apply(compiler) {
|
|
159
|
-
compiler.hooks.done.tapAsync(RspackProfileLoggingPlugin.name, (stats, callback) => {
|
|
160
|
-
if (compiler.watchMode)
|
|
161
|
-
return callback();
|
|
162
|
-
const logging = stats.toJson({
|
|
163
|
-
all: false,
|
|
164
|
-
logging: "verbose",
|
|
165
|
-
loggingTrace: true
|
|
166
|
-
});
|
|
167
|
-
node_fs_1.default.writeFileSync(this.output, JSON.stringify(logging));
|
|
168
|
-
return callback();
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
async function applyProfile(profileValue, item) {
|
|
173
|
-
const { default: exitHook } = await import("exit-hook");
|
|
174
|
-
const entries = Object.entries(resolveProfile(profileValue));
|
|
175
|
-
if (entries.length <= 0)
|
|
176
|
-
return;
|
|
177
|
-
await node_fs_1.default.promises.mkdir(defaultOutputDirname);
|
|
178
|
-
for (const [kind, value] of entries) {
|
|
179
|
-
await ensureFileDir(value.output);
|
|
180
|
-
if (kind === "TRACE" && "filter" in value) {
|
|
181
|
-
core_1.rspack.experiments.globalTrace.register(value.filter, value.layer, value.output);
|
|
182
|
-
exitHook(core_1.rspack.experiments.globalTrace.cleanup);
|
|
183
|
-
}
|
|
184
|
-
else if (kind === "JSCPU") {
|
|
185
|
-
(item.plugins ??= []).push(new RspackProfileJSCPUProfilePlugin(value.output));
|
|
186
|
-
}
|
|
187
|
-
else if (kind === "LOGGING") {
|
|
188
|
-
(item.plugins ??= []).push(new RspackProfileLoggingPlugin(value.output));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
async function ensureFileDir(outputFilePath) {
|
|
193
|
-
const dir = node_path_1.default.dirname(outputFilePath);
|
|
194
|
-
await node_fs_1.default.promises.mkdir(dir, { recursive: true });
|
|
195
|
-
return dir;
|
|
196
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const readPackageUp = (cwd = process.cwd()) => {
|
|
9
|
-
let currentDir = node_path_1.default.resolve(cwd);
|
|
10
|
-
let packageJsonPath = node_path_1.default.join(currentDir, "package.json");
|
|
11
|
-
while (!node_fs_1.default.existsSync(packageJsonPath)) {
|
|
12
|
-
const parentDir = node_path_1.default.dirname(currentDir);
|
|
13
|
-
if (parentDir === currentDir) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
currentDir = parentDir;
|
|
17
|
-
packageJsonPath = node_path_1.default.join(currentDir, "package.json");
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(node_fs_1.default.readFileSync(packageJsonPath, "utf8"));
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
exports.default = readPackageUp;
|