@naturalcycles/nodejs-lib 13.39.1 → 13.40.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.
@@ -10,6 +10,11 @@ export interface RunScriptOptions {
10
10
  * Default to `console`
11
11
  */
12
12
  logger?: CommonLogger;
13
+ /**
14
+ * Defaults to true.
15
+ * Set to false if you already have your handlers elsewhere and don't need them here.
16
+ */
17
+ registerUncaughtExceptionHandlers?: boolean;
13
18
  }
14
19
  /**
15
20
  * Use it in your top-level scripts like this:
@@ -24,13 +24,15 @@ const { DEBUG_RUN_SCRIPT } = process.env;
24
24
  */
25
25
  function runScript(fn, opt = {}) {
26
26
  (0, js_lib_1.setGlobalStringifyFunction)(inspect_1.inspectStringifyFn);
27
- const { logger = console, noExit } = opt;
28
- process.on('uncaughtException', err => {
29
- logger.error('uncaughtException:', err);
30
- });
31
- process.on('unhandledRejection', err => {
32
- logger.error('unhandledRejection:', err);
33
- });
27
+ const { logger = console, noExit, registerUncaughtExceptionHandlers = true } = opt;
28
+ if (registerUncaughtExceptionHandlers || DEBUG_RUN_SCRIPT) {
29
+ process.on('uncaughtException', err => {
30
+ logger.error('runScript uncaughtException:', err);
31
+ });
32
+ process.on('unhandledRejection', err => {
33
+ logger.error('runScript unhandledRejection:', err);
34
+ });
35
+ }
34
36
  if (DEBUG_RUN_SCRIPT) {
35
37
  process.on('exit', code => logger.log(`process.exit event, code=${code}`));
36
38
  process.on('beforeExit', code => logger.log(`process.beforeExit event, code=${code}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.39.1",
3
+ "version": "13.40.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build",
@@ -20,29 +20,29 @@
20
20
  "json2env-debug": "tsn ./src/bin/json2env.ts ./src/test/someFile.json"
21
21
  },
22
22
  "dependencies": {
23
- "@naturalcycles/js-lib": "^14.244.0",
24
- "@types/js-yaml": "^4.0.9",
25
- "@types/jsonwebtoken": "^9.0.0",
26
- "ajv": "^8.6.2",
27
- "ajv-formats": "^3.0.1",
28
- "ajv-keywords": "^5.0.0",
29
- "chalk": "^4.0.0",
30
- "dotenv": "^16.0.0",
31
- "fast-glob": "^3.2.11",
32
- "joi": "^17.9.2",
33
- "js-yaml": "^4.1.0",
34
- "jsonwebtoken": "^9.0.0",
35
- "lru-cache": "^11.0.0",
36
- "through2-concurrent": "^2.0.0",
37
- "yargs": "^17.0.0"
23
+ "@naturalcycles/js-lib": "^14",
24
+ "@types/js-yaml": "^4",
25
+ "@types/jsonwebtoken": "^9",
26
+ "ajv": "^8",
27
+ "ajv-formats": "^3",
28
+ "ajv-keywords": "^5",
29
+ "chalk": "^4",
30
+ "dotenv": "^16",
31
+ "fast-glob": "^3",
32
+ "joi": "^17",
33
+ "js-yaml": "^4",
34
+ "jsonwebtoken": "^9",
35
+ "lru-cache": "^11",
36
+ "through2-concurrent": "^2",
37
+ "yargs": "^17"
38
38
  },
39
39
  "devDependencies": {
40
- "@naturalcycles/bench-lib": "^3.0.0",
41
- "@naturalcycles/dev-lib": "^15.0.3",
42
- "@types/node": "^22.1.0",
43
- "@types/through2-concurrent": "^2.0.0",
44
- "@types/yargs": "^16.0.0",
45
- "jest": "^29.0.0"
40
+ "@naturalcycles/bench-lib": "^3",
41
+ "@naturalcycles/dev-lib": "^15",
42
+ "@types/node": "^22",
43
+ "@types/through2-concurrent": "^2",
44
+ "@types/yargs": "^16",
45
+ "jest": "^29"
46
46
  },
47
47
  "bin": {
48
48
  "kpy": "dist/bin/kpy.js",
@@ -14,6 +14,12 @@ export interface RunScriptOptions {
14
14
  * Default to `console`
15
15
  */
16
16
  logger?: CommonLogger
17
+
18
+ /**
19
+ * Defaults to true.
20
+ * Set to false if you already have your handlers elsewhere and don't need them here.
21
+ */
22
+ registerUncaughtExceptionHandlers?: boolean
17
23
  }
18
24
 
19
25
  const { DEBUG_RUN_SCRIPT } = process.env
@@ -39,14 +45,16 @@ const { DEBUG_RUN_SCRIPT } = process.env
39
45
  export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {}): void {
40
46
  setGlobalStringifyFunction(inspectStringifyFn)
41
47
 
42
- const { logger = console, noExit } = opt
48
+ const { logger = console, noExit, registerUncaughtExceptionHandlers = true } = opt
43
49
 
44
- process.on('uncaughtException', err => {
45
- logger.error('uncaughtException:', err)
46
- })
47
- process.on('unhandledRejection', err => {
48
- logger.error('unhandledRejection:', err)
49
- })
50
+ if (registerUncaughtExceptionHandlers || DEBUG_RUN_SCRIPT) {
51
+ process.on('uncaughtException', err => {
52
+ logger.error('runScript uncaughtException:', err)
53
+ })
54
+ process.on('unhandledRejection', err => {
55
+ logger.error('runScript unhandledRejection:', err)
56
+ })
57
+ }
50
58
 
51
59
  if (DEBUG_RUN_SCRIPT) {
52
60
  process.on('exit', code => logger.log(`process.exit event, code=${code}`))