@nmakarov/cli-toolkit 0.73.0 → 0.75.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/cli-runner.cjs +13 -1
- package/dist/cli-runner.cjs.map +1 -1
- package/dist/cli-runner.js +13 -1
- package/dist/cli-runner.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/init.cjs +13 -1
- package/dist/init.cjs.map +1 -1
- package/dist/init.js +13 -1
- package/dist/init.js.map +1 -1
- package/package.json +1 -1
package/dist/cli-runner.js
CHANGED
|
@@ -2794,6 +2794,7 @@ function setup(opts = {}) {
|
|
|
2794
2794
|
const partialContext = {
|
|
2795
2795
|
emitter: new EventEmitter(),
|
|
2796
2796
|
isStop: () => false,
|
|
2797
|
+
isKill: () => false,
|
|
2797
2798
|
cleanupFunctions: [],
|
|
2798
2799
|
registerCleanup: (fn) => {
|
|
2799
2800
|
partialContext.cleanupFunctions.push(fn);
|
|
@@ -2815,6 +2816,7 @@ function setup(opts = {}) {
|
|
|
2815
2816
|
logger,
|
|
2816
2817
|
emitter: partialContext.emitter,
|
|
2817
2818
|
isStop: partialContext.isStop,
|
|
2819
|
+
isKill: partialContext.isKill,
|
|
2818
2820
|
cleanupFunctions: partialContext.cleanupFunctions,
|
|
2819
2821
|
registerCleanup: partialContext.registerCleanup,
|
|
2820
2822
|
// For long-running scripts (servers): with --showUsedParams=top, print
|
|
@@ -2864,6 +2866,7 @@ function printAllParameters(context) {
|
|
|
2864
2866
|
}
|
|
2865
2867
|
async function init(flow2, opts = {}) {
|
|
2866
2868
|
let stop = false;
|
|
2869
|
+
let kill = false;
|
|
2867
2870
|
let context = null;
|
|
2868
2871
|
let cleanupRan = false;
|
|
2869
2872
|
const runRegisteredCleanups = async (ctx) => {
|
|
@@ -2893,6 +2896,7 @@ async function init(flow2, opts = {}) {
|
|
|
2893
2896
|
}
|
|
2894
2897
|
context = setup(opts);
|
|
2895
2898
|
context.isStop = () => stop;
|
|
2899
|
+
context.isKill = () => kill;
|
|
2896
2900
|
context = await setupModules(context, opts);
|
|
2897
2901
|
const stopAfter = context.args.get("stopAfter");
|
|
2898
2902
|
const stopAllowanceSec = Number(context.params.get("stopAllowance", "number default 60"));
|
|
@@ -2931,6 +2935,14 @@ async function init(flow2, opts = {}) {
|
|
|
2931
2935
|
);
|
|
2932
2936
|
context.emitter.emit("stop", stopAllowanceMs);
|
|
2933
2937
|
});
|
|
2938
|
+
process.on("SIGUSR2", () => {
|
|
2939
|
+
if (!context || kill) return;
|
|
2940
|
+
kill = true;
|
|
2941
|
+
stop = true;
|
|
2942
|
+
context.logger.warn(">> SIGUSR2: emitting kill (urgent stop)");
|
|
2943
|
+
context.emitter.emit("kill");
|
|
2944
|
+
context.emitter.emit("stop", stopAllowanceMs);
|
|
2945
|
+
});
|
|
2934
2946
|
await flow2(context);
|
|
2935
2947
|
} catch (error) {
|
|
2936
2948
|
const errorLocation = error instanceof Error && error.stack ? error.stack.split("\n")[1]?.trim() || "Unknown location" : "Unknown location";
|
|
@@ -2957,7 +2969,7 @@ async function init(flow2, opts = {}) {
|
|
|
2957
2969
|
}
|
|
2958
2970
|
if (process.exitCode && process.exitCode !== 0) {
|
|
2959
2971
|
process.exit(process.exitCode);
|
|
2960
|
-
} else if (stop) {
|
|
2972
|
+
} else if (stop || kill) {
|
|
2961
2973
|
process.exit(0);
|
|
2962
2974
|
}
|
|
2963
2975
|
}
|