@alwatr/exit-hook 6.0.0 → 6.0.2
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/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/package.json +35 -36
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* 📦 @alwatr/exit-hook v6.0.
|
|
1
|
+
/* 📦 @alwatr/exit-hook v6.0.2 */
|
|
2
2
|
var q=null,y=!1;function D(f){if(q===null)B(),q=[];q.push(f)}function u(f){if(console.log("onExit({signal: %s})",f),y===!0||q===null)return;y=!0;for(let z of q)try{z()}catch(A){console.error("Error in exit hook callback:",A)}if(f==="SIGINT"||f==="SIGTERM")setTimeout(()=>{process.exit(0)})}function B(){process.once("exit",u),process.once("SIGTERM",u),process.once("SIGINT",u)}export{D as exitHook};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=089931B63003D65864756E2164756E21
|
|
5
5
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
"/**\n * Array of callback functions to be called when the process is exiting.\n */\nlet callbacks: (() => void)[] | null = null;\n\n/**\n * True whether the process is exiting to prevent calling the callbacks more than once.\n */\nlet exiting = false;\n\n/**\n * Add a callback function to be called when the process is exiting.\n *\n * @param callback The callback function to be called when the process is exiting.\n *\n * @example\n * ```typescript\n * const saveAllData = () => {\n * // save all data\n * };\n *\n * existHook(saveAllData);\n * ```\n */\nexport function exitHook(callback: () => void): void {\n if (callbacks === null) {\n registerExitEvents();\n callbacks = [];\n }\n callbacks.push(callback);\n}\n\n/**\n * A once callback to be called on process exit event.\n */\nfunction onExit_(signal: number | 'SIGINT' | 'SIGTERM') {\n console.log('onExit({signal: %s})', signal);\n if (exiting === true || callbacks === null) return;\n\n exiting = true;\n\n for (const callback of callbacks) {\n try {\n callback();\n }\n catch (error) {\n console.error('Error in exit hook callback:', error);\n }\n }\n\n if (signal === 'SIGINT' || signal === 'SIGTERM') {\n setTimeout(() => {\n process.exit(0);\n });\n }\n}\n\n/**\n * Register process exit events.\n */\nfunction registerExitEvents(): void {\n /**\n * This event emitted when Node.js empties its event loop and has no additional work to schedule.\n * Normally, the Node.js process will exit when there is no work scheduled,\n * but a listener registered on the 'beforeExit' event can make **asynchronous calls**, and thereby cause the Node.js process to continue.\n *\n * @see https://nodejs.org/api/process.html#event-beforeexit\n */\n // process.once('beforeExit', onExit_);\n\n /**\n * This event is emitted when the Node.js process is about to exit as a result of either:\n * 1- The `process.exit()` method being called explicitly.\n * 2- The Node.js event loop no longer having any additional work to perform.\n *\n * @see https://nodejs.org/api/process.html#event-exit\n */\n process.once('exit', onExit_);\n\n /**\n * This event is emitted in terminal mode before exiting with code 128 + signal number.\n *\n * @see https://nodejs.org/api/process.html#signal-events\n */\n process.once('SIGTERM', onExit_);\n\n /**\n * This event is emitted when `Ctrl+C` is pressed.\n *\n * @see https://nodejs.org/api/process.html#signal-events\n */\n process.once('SIGINT', onExit_);\n}\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AAGA,IAAI,EAAmC,KAKnC,EAAU,GAgBP,SAAS,CAAQ,CAAC,EAA4B,CACnD,GAAI,IAAc,KAChB,EAAmB,EACnB,EAAY,CAAC,EAEf,EAAU,KAAK,CAAQ,EAMzB,SAAS,CAAO,CAAC,EAAuC,CAEtD,GADA,QAAQ,IAAI,uBAAwB,CAAM,EACtC,IAAY,IAAQ,IAAc,KAAM,OAE5C,EAAU,GAEV,QAAW,KAAY,EACrB,GAAI,CACF,EAAS,EAEX,MAAO,EAAO,CACZ,QAAQ,MAAM,+BAAgC,CAAK,EAIvD,GAAI,IAAW,UAAY,IAAW,UACpC,WAAW,IAAM,CACf,QAAQ,KAAK,CAAC,EACf,EAOL,SAAS,CAAkB,EAAS,CAiBlC,QAAQ,KAAK,OAAQ,CAAO,EAO5B,QAAQ,KAAK,UAAW,CAAO,EAO/B,QAAQ,KAAK,SAAU,CAAO",
|
|
8
|
-
"debugId": "
|
|
8
|
+
"debugId": "089931B63003D65864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/exit-hook",
|
|
3
|
+
"version": "6.0.2",
|
|
3
4
|
"description": "A utility for registering exit handlers in Node.js.",
|
|
4
|
-
"
|
|
5
|
+
"license": "MPL-2.0",
|
|
5
6
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"@types/node": "^24.12.0",
|
|
12
|
-
"typescript": "^5.9.3"
|
|
7
|
+
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"directory": "packages/exit-hook",
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/Alwatr/nanolib"
|
|
13
12
|
},
|
|
13
|
+
"homepage": "https://github.com/Alwatr/nanolib/tree/next/packages/exit-hook#readme",
|
|
14
|
+
"bugs": "https://github.com/Alwatr/nanolib/issues",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"types": "./dist/main.d.ts",
|
|
17
18
|
"default": "./dist/main.js"
|
|
18
19
|
}
|
|
19
20
|
},
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@alwatr/nano-build": "7.0.1",
|
|
24
|
+
"@alwatr/prettier-config": "7.0.1",
|
|
25
|
+
"@alwatr/tsconfig-base": "8.0.0",
|
|
26
|
+
"@types/node": "^24.12.0",
|
|
27
|
+
"typescript": "^6.0.2"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"b": "bun run build",
|
|
31
|
+
"build": "bun run build:ts && bun run build:es",
|
|
32
|
+
"build:es": "nano-build --preset=module src/main.ts",
|
|
33
|
+
"build:ts": "tsc --build",
|
|
34
|
+
"c": "bun run clean",
|
|
35
|
+
"cb": "bun run clean && bun run build",
|
|
36
|
+
"clean": "rm -rfv dist *.tsbuildinfo",
|
|
37
|
+
"d": "bun run build:es && bun",
|
|
38
|
+
"w": "bun run watch",
|
|
39
|
+
"watch": "bun run watch:ts & bun run watch:es",
|
|
40
|
+
"watch:es": "bun run build:es --watch",
|
|
41
|
+
"watch:ts": "bun run build:ts --watch --preserveWatchOutput"
|
|
42
|
+
},
|
|
20
43
|
"files": [
|
|
21
44
|
"**/*.{js,mjs,cjs,ts,map,d.ts,html,LEGAL.txt}",
|
|
22
45
|
"README.md",
|
|
@@ -24,7 +47,9 @@
|
|
|
24
47
|
"!demo/**/*",
|
|
25
48
|
"!**/*.test.js"
|
|
26
49
|
],
|
|
27
|
-
"
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
28
53
|
"keywords": [
|
|
29
54
|
"alwatr",
|
|
30
55
|
"cross-platform",
|
|
@@ -43,32 +68,6 @@
|
|
|
43
68
|
"utility",
|
|
44
69
|
"utils"
|
|
45
70
|
],
|
|
46
|
-
"license": "MPL-2.0",
|
|
47
71
|
"prettier": "@alwatr/prettier-config",
|
|
48
|
-
"
|
|
49
|
-
"access": "public"
|
|
50
|
-
},
|
|
51
|
-
"repository": {
|
|
52
|
-
"type": "git",
|
|
53
|
-
"url": "https://github.com/Alwatr/nanolib",
|
|
54
|
-
"directory": "packages/exit-hook"
|
|
55
|
-
},
|
|
56
|
-
"scripts": {
|
|
57
|
-
"b": "bun run build",
|
|
58
|
-
"build": "bun run build:ts && bun run build:es",
|
|
59
|
-
"build:es": "nano-build --preset=module src/main.ts",
|
|
60
|
-
"build:ts": "tsc --build",
|
|
61
|
-
"c": "bun run clean",
|
|
62
|
-
"cb": "bun run clean && bun run build",
|
|
63
|
-
"clean": "rm -rfv dist *.tsbuildinfo",
|
|
64
|
-
"d": "bun run build:es && bun",
|
|
65
|
-
"w": "bun run watch",
|
|
66
|
-
"watch": "bun run watch:ts & bun run watch:es",
|
|
67
|
-
"watch:es": "bun run build:es --watch",
|
|
68
|
-
"watch:ts": "bun run build:ts --watch --preserveWatchOutput"
|
|
69
|
-
},
|
|
70
|
-
"sideEffects": false,
|
|
71
|
-
"type": "module",
|
|
72
|
-
"types": "./dist/main.d.ts",
|
|
73
|
-
"gitHead": "056102a1c8a563bbae8a290b6830450f467322a3"
|
|
72
|
+
"gitHead": "95bb13efd0a5f485c6b09f1a911b99492017aed1"
|
|
74
73
|
}
|