@naturalcycles/nodejs-lib 13.8.0 → 13.9.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.
@@ -1,4 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  import type { SpawnOptions } from 'node:child_process';
3
- export declare function execVoidCommand(cmd: string, args?: string[], opt?: SpawnOptions): Promise<void>;
4
- export declare function execVoidCommandSync(cmd: string, args?: string[], opt?: SpawnOptions): void;
3
+ export interface ExecOptions extends SpawnOptions {
4
+ /**
5
+ * Defaults to true.
6
+ * Set to false to skip logging.
7
+ */
8
+ log?: boolean;
9
+ }
10
+ export declare function execVoidCommand(cmd: string, args?: string[], opt?: ExecOptions): Promise<void>;
11
+ export declare function execVoidCommandSync(cmd: string, args?: string[], opt?: ExecOptions): void;
@@ -48,6 +48,8 @@ function execVoidCommandSync(cmd, args = [], opt = {}) {
48
48
  }
49
49
  exports.execVoidCommandSync = execVoidCommandSync;
50
50
  function logExec(cmd, args = [], opt = {}) {
51
+ if (opt.log === false)
52
+ return;
51
53
  const cmdline = [
52
54
  ...Object.entries(opt.env || {}).map(([k, v]) => [k, v].join('=')),
53
55
  cmd,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.8.0",
3
+ "version": "13.9.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -1,10 +1,18 @@
1
1
  import type { ProcessEnvOptions, SpawnOptions } from 'node:child_process'
2
2
  import cp from 'node:child_process'
3
3
 
4
+ export interface ExecOptions extends SpawnOptions {
5
+ /**
6
+ * Defaults to true.
7
+ * Set to false to skip logging.
8
+ */
9
+ log?: boolean
10
+ }
11
+
4
12
  export async function execVoidCommand(
5
13
  cmd: string,
6
14
  args: string[] = [],
7
- opt: SpawnOptions = {},
15
+ opt: ExecOptions = {},
8
16
  ): Promise<void> {
9
17
  logExec(cmd, args, opt)
10
18
 
@@ -29,11 +37,7 @@ export async function execVoidCommand(
29
37
  })
30
38
  }
31
39
 
32
- export function execVoidCommandSync(
33
- cmd: string,
34
- args: string[] = [],
35
- opt: SpawnOptions = {},
36
- ): void {
40
+ export function execVoidCommandSync(cmd: string, args: string[] = [], opt: ExecOptions = {}): void {
37
41
  logExec(cmd, args, opt)
38
42
 
39
43
  const r = cp.spawnSync(cmd, [...args], {
@@ -58,7 +62,13 @@ export function execVoidCommandSync(
58
62
  }
59
63
  }
60
64
 
61
- function logExec(cmd: string, args: string[] = [], opt: ProcessEnvOptions = {}): void {
65
+ function logExec(
66
+ cmd: string,
67
+ args: string[] = [],
68
+ opt: ProcessEnvOptions & ExecOptions = {},
69
+ ): void {
70
+ if (opt.log === false) return
71
+
62
72
  const cmdline = [
63
73
  ...Object.entries(opt.env || {}).map(([k, v]) => [k, v].join('=')),
64
74
  cmd,