@naturalcycles/nodejs-lib 13.39.2 → 13.41.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}`));
@@ -4,5 +4,9 @@ export interface GenerateBuildInfoOptions {
4
4
  * If set - this timestamp will be used, instead of "current time".
5
5
  */
6
6
  overrideTimestamp?: UnixTimestamp;
7
+ /**
8
+ * Defaults to currently checked out git branch.
9
+ */
10
+ overrideBranchName?: string;
7
11
  }
8
12
  export declare function generateBuildInfo(opt?: GenerateBuildInfoOptions): BuildInfo;
@@ -8,7 +8,7 @@ function generateBuildInfo(opt = {}) {
8
8
  const now = js_lib_1.localTime.orNow(opt.overrideTimestamp);
9
9
  const ts = now.unix;
10
10
  const rev = git2_1.git2.getCurrentCommitSha();
11
- const branchName = git2_1.git2.getCurrentBranchName();
11
+ const branchName = opt.overrideBranchName || git2_1.git2.getCurrentBranchName();
12
12
  const repoName = git2_1.git2.getCurrentRepoName();
13
13
  const tsCommit = git2_1.git2.getCurrentCommitTimestamp();
14
14
  const ver = [now.toStringCompact(), repoName, branchName, rev].join('_');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.39.2",
3
+ "version": "13.41.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build",
@@ -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}`))
@@ -13,6 +13,11 @@ export interface GenerateBuildInfoOptions {
13
13
  * If set - this timestamp will be used, instead of "current time".
14
14
  */
15
15
  overrideTimestamp?: UnixTimestamp
16
+
17
+ /**
18
+ * Defaults to currently checked out git branch.
19
+ */
20
+ overrideBranchName?: string
16
21
  }
17
22
 
18
23
  export function generateBuildInfo(opt: GenerateBuildInfoOptions = {}): BuildInfo {
@@ -20,7 +25,7 @@ export function generateBuildInfo(opt: GenerateBuildInfoOptions = {}): BuildInfo
20
25
  const ts = now.unix
21
26
 
22
27
  const rev = git2.getCurrentCommitSha()
23
- const branchName = git2.getCurrentBranchName()
28
+ const branchName = opt.overrideBranchName || git2.getCurrentBranchName()
24
29
  const repoName = git2.getCurrentRepoName()
25
30
  const tsCommit = git2.getCurrentCommitTimestamp()
26
31