@rspack/cli 2.0.0-rc.0 → 2.0.0-rc.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/bin/rspack.js +5 -1
- package/dist/697.js +1406 -0
- package/dist/cli.d.ts +7 -0
- package/dist/exit-hook.js +61 -0
- package/dist/index.js +1 -1319
- package/dist/json-ext.js +772 -0
- package/dist/profile.js +1 -1
- package/package.json +7 -9
package/dist/cli.d.ts
CHANGED
|
@@ -9,7 +9,14 @@ declare global {
|
|
|
9
9
|
export declare class RspackCLI {
|
|
10
10
|
colors: RspackCLIColors;
|
|
11
11
|
program: CAC;
|
|
12
|
+
_actionPromise: Promise<void> | undefined;
|
|
12
13
|
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Wraps an async action handler so its promise is captured and can be
|
|
16
|
+
* awaited in `run()`. CAC's `parse()` does not await async actions,
|
|
17
|
+
* so without this wrapper, rejections become unhandled.
|
|
18
|
+
*/
|
|
19
|
+
wrapAction<T extends (...args: any[]) => Promise<void>>(fn: T): T;
|
|
13
20
|
buildCompilerConfig(options: CommonOptionsForBuildAndServe, rspackCommand: Command): Promise<RspackOptions | MultiRspackOptions>;
|
|
14
21
|
createCompiler(config: RspackOptions | MultiRspackOptions, callback?: (e: Error | null, res?: Stats | MultiStats) => void): Promise<MultiCompiler | Compiler | null>;
|
|
15
22
|
private createColors;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import node_process from "node:process";
|
|
2
|
+
const asyncCallbacks = new Set();
|
|
3
|
+
const callbacks = new Set();
|
|
4
|
+
let isCalled = false;
|
|
5
|
+
let isRegistered = false;
|
|
6
|
+
async function exit(shouldManuallyExit, isSynchronous, signal) {
|
|
7
|
+
if (isCalled) return;
|
|
8
|
+
isCalled = true;
|
|
9
|
+
if (asyncCallbacks.size > 0 && isSynchronous) console.error("SYNCHRONOUS TERMINATION NOTICE: When explicitly exiting the process via process.exit or via a parent process, asynchronous tasks in your exitHooks will not run. Either remove these tasks, use gracefulExit() instead of process.exit(), or ensure your parent process sends a SIGINT to the process running this code.");
|
|
10
|
+
const exitCode = 128 + signal;
|
|
11
|
+
const done = (force = false)=>{
|
|
12
|
+
if (true === force || true === shouldManuallyExit) node_process.exit(exitCode);
|
|
13
|
+
};
|
|
14
|
+
for (const callback of callbacks)callback(exitCode);
|
|
15
|
+
if (isSynchronous) return void done();
|
|
16
|
+
const promises = [];
|
|
17
|
+
let forceAfter = 0;
|
|
18
|
+
for (const [callback, wait] of asyncCallbacks){
|
|
19
|
+
forceAfter = Math.max(forceAfter, wait);
|
|
20
|
+
promises.push(Promise.resolve(callback(exitCode)));
|
|
21
|
+
}
|
|
22
|
+
const asyncTimer = setTimeout(()=>{
|
|
23
|
+
done(true);
|
|
24
|
+
}, forceAfter);
|
|
25
|
+
await Promise.all(promises);
|
|
26
|
+
clearTimeout(asyncTimer);
|
|
27
|
+
done();
|
|
28
|
+
}
|
|
29
|
+
function addHook(options) {
|
|
30
|
+
const { onExit, wait, isSynchronous } = options;
|
|
31
|
+
const asyncCallbackConfig = [
|
|
32
|
+
onExit,
|
|
33
|
+
wait
|
|
34
|
+
];
|
|
35
|
+
if (isSynchronous) callbacks.add(onExit);
|
|
36
|
+
else asyncCallbacks.add(asyncCallbackConfig);
|
|
37
|
+
if (!isRegistered) {
|
|
38
|
+
isRegistered = true;
|
|
39
|
+
node_process.once('beforeExit', exit.bind(void 0, true, false, -128));
|
|
40
|
+
node_process.once('SIGINT', exit.bind(void 0, true, false, 2));
|
|
41
|
+
node_process.once('SIGTERM', exit.bind(void 0, true, false, 15));
|
|
42
|
+
node_process.once('exit', exit.bind(void 0, false, true, 0));
|
|
43
|
+
node_process.on('message', (message)=>{
|
|
44
|
+
if ('shutdown' === message) exit(true, true, -128);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return ()=>{
|
|
48
|
+
if (isSynchronous) callbacks.delete(onExit);
|
|
49
|
+
else asyncCallbacks.delete(asyncCallbackConfig);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function asyncExitHook(onExit, options = {}) {
|
|
53
|
+
if ('function' != typeof onExit) throw new TypeError('onExit must be a function');
|
|
54
|
+
if (!('number' == typeof options.wait && options.wait > 0)) throw new TypeError('wait must be set to a positive numeric value');
|
|
55
|
+
return addHook({
|
|
56
|
+
onExit,
|
|
57
|
+
wait: options.wait,
|
|
58
|
+
isSynchronous: false
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export { asyncExitHook };
|