@willbooster/shared-lib-node 7.0.1 → 7.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.
@@ -1 +1 @@
1
- {"version":3,"file":"spawn.cjs","sources":["../src/spawn.ts"],"sourcesContent":["import type {\n SpawnOptions,\n SpawnOptionsWithoutStdio,\n SpawnOptionsWithStdioTuple,\n SpawnSyncReturns,\n StdioNull,\n StdioPipe,\n} from 'node:child_process';\nimport { spawn } from 'node:child_process';\n\nimport treeKill from 'tree-kill';\n\n/**\n * Return type for spawnAsync function, based on SpawnSyncReturns but without output and error properties\n */\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\n/**\n * Options for spawnAsync function, extending various Node.js spawn options with additional functionality\n */\nexport type SpawnAsyncOptions = (\n | SpawnOptionsWithoutStdio\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>\n | SpawnOptions\n) & {\n /** Input string to write to the spawned process's stdin */\n input?: string;\n /** If true, stderr output will be merged into stdout */\n mergeOutAndError?: boolean;\n /** If true, the spawned process will be killed when the parent process exits */\n killOnExit?: boolean;\n /** If true, enables verbose logging of process operations */\n verbose?: boolean;\n /** If true, stdout data will be printed to console as it's received */\n printingStdout?: boolean;\n /** If true, stderr data will be printed to console as it's received */\n printingStderr?: boolean;\n};\n\n/**\n * Spawns a child process asynchronously and returns a promise that resolves with the process results\n *\n * This function provides a Promise-based wrapper around Node.js's spawn function with additional features:\n * - Automatic encoding of stdout/stderr as UTF-8\n * - Option to merge stderr into stdout\n * - Option to automatically kill the process on parent exit\n * - Option to provide input via stdin\n * - Verbose logging capability\n *\n * @param command - The command to run\n * @param args - List of string arguments\n * @param options - Configuration options for the spawned process\n * @returns Promise that resolves with the process results including pid, stdout, stderr, status, and signal\n * @throws Will reject the promise if the process fails to spawn or encounters an error\n *\n * @example\n * ```typescript\n * const result = await spawnAsync('ls', ['-la'], { verbose: true });\n * console.log(result.stdout);\n * ```\n */\nexport async function spawnAsync(\n command: string,\n args?: ReadonlyArray<string>,\n options?: SpawnAsyncOptions\n): Promise<SpawnAsyncReturns> {\n return new Promise((resolve, reject) => {\n try {\n const proc = spawn(command, args ?? [], options ?? {});\n // `setEncoding` is undefined in Bun\n proc.stdout?.setEncoding?.('utf8');\n proc.stderr?.setEncoding?.('utf8');\n\n let stdout = '';\n let stderr = '';\n proc.stdout?.on('data', (data: string) => {\n stdout += data;\n if (options?.printingStdout) {\n process.stdout.write(data);\n }\n });\n proc.stderr?.on('data', (data: string) => {\n if (options?.mergeOutAndError) {\n stdout += data;\n } else {\n stderr += data;\n }\n if (options?.printingStderr) {\n process.stderr.write(data);\n }\n });\n\n let stopped = false;\n const stopProcess = (): void => {\n if (stopped || !proc.pid) return;\n\n stopped = true;\n if (options?.verbose) {\n console.info(`treeKill(${proc.pid})`);\n }\n treeKill(proc.pid);\n };\n if (options?.killOnExit) {\n process.on('beforeExit', stopProcess);\n process.on('SIGINT', stopProcess);\n }\n\n proc.on('error', (error) => {\n process.removeListener('beforeExit', stopProcess);\n process.removeListener('SIGINT', stopProcess);\n proc.removeAllListeners('close');\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n process.removeListener('beforeExit', stopProcess);\n process.removeListener('SIGINT', stopProcess);\n if (proc.pid === undefined) {\n reject(new Error('Process has no pid.'));\n } else {\n resolve({\n pid: proc.pid,\n stdout,\n stderr,\n status: code,\n signal,\n });\n }\n });\n\n if (options?.input) {\n proc.stdin?.write(options.input);\n proc.stdin?.end();\n }\n } catch (error) {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error);\n }\n });\n}\n"],"names":["async","command","args","options","Promise","resolve","reject","proc","spawn","stdout","setEncoding","stderr","on","data","printingStdout","process","write","mergeOutAndError","printingStderr","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","error","removeListener","removeAllListeners","code","signal","undefined","Error","status","input","stdin","end"],"mappings":"2FAoEOA,eACLC,EACAC,EACAC,GAEA,OAAO,IAAIC,QAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAAA,MAAMP,EAASC,GAAQ,GAAIC,GAAW,IAEnDI,EAAKE,QAAQC,cAAc,QAC3BH,EAAKI,QAAQD,cAAc,QAE3B,IAAID,EAAS,GACTE,EAAS,GACbJ,EAAKE,QAAQG,GAAG,OAASC,IACvBJ,GAAUI,EACNV,GAASW,gBACXC,QAAQN,OAAOO,MAAMH,KAGzBN,EAAKI,QAAQC,GAAG,OAASC,IACnBV,GAASc,iBACXR,GAAUI,EAEVF,GAAUE,EAERV,GAASe,gBACXH,QAAQJ,OAAOK,MAAMH,KAIzB,IAAIM,GAAU,EACd,MAAMC,EAAcA,MACdD,GAAYZ,EAAKc,MAErBF,GAAU,EACNhB,GAASmB,SACXC,QAAQC,KAAK,YAAYjB,EAAKc,QAEhCI,EAASlB,EAAKc,OAEZlB,GAASuB,aACXX,QAAQH,GAAG,aAAcQ,GACzBL,QAAQH,GAAG,SAAUQ,IAGvBb,EAAKK,GAAG,QAAUe,IAChBZ,QAAQa,eAAe,aAAcR,GACrCL,QAAQa,eAAe,SAAUR,GACjCb,EAAKsB,mBAAmB,SACxBvB,EAAOqB,KAETpB,EAAKK,GAAG,QAAS,CAACkB,EAAqBC,KACrChB,QAAQa,eAAe,aAAcR,GACrCL,QAAQa,eAAe,SAAUR,QAChBY,IAAbzB,EAAKc,IACPf,EAAO,IAAI2B,MAAM,wBAEjB5B,EAAQ,CACNgB,IAAKd,EAAKc,IACVZ,SACAE,SACAuB,OAAQJ,EACRC,aAKF5B,GAASgC,QACX5B,EAAK6B,OAAOpB,MAAMb,EAAQgC,OAC1B5B,EAAK6B,OAAOC,OAEd,MAAOV,GAEPrB,EAAOqB,EACT,GAEJ"}
1
+ {"version":3,"file":"spawn.cjs","sources":["../src/spawn.ts"],"sourcesContent":["import type {\n SpawnOptions,\n SpawnOptionsWithoutStdio,\n SpawnOptionsWithStdioTuple,\n SpawnSyncReturns,\n StdioNull,\n StdioPipe,\n} from 'node:child_process';\nimport { spawn } from 'node:child_process';\n\nimport treeKill from 'tree-kill';\n\n/**\n * Return type for spawnAsync function, based on SpawnSyncReturns but without output and error properties\n */\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\n/**\n * Options for spawnAsync function, extending various Node.js spawn options with additional functionality\n */\nexport type SpawnAsyncOptions = (\n | SpawnOptionsWithoutStdio\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>\n | SpawnOptions\n) & {\n /** Input string to write to the spawned process's stdin */\n input?: string;\n /** If true, stderr output will be merged into stdout */\n mergeOutAndError?: boolean;\n /** If true, the spawned process will be killed when the parent process exits */\n killOnExit?: boolean;\n /** If true, enables verbose logging of process operations */\n verbose?: boolean;\n /** If true, stdout data will be printed to console as it's received */\n printingStdout?: boolean;\n /** If true, stderr data will be printed to console as it's received */\n printingStderr?: boolean;\n};\n\n/**\n * Spawns a child process asynchronously and returns a promise that resolves with the process results\n *\n * This function provides a Promise-based wrapper around Node.js's spawn function with additional features:\n * - Automatic encoding of stdout/stderr as UTF-8\n * - Option to merge stderr into stdout\n * - Option to automatically kill the process on parent exit\n * - Option to provide input via stdin\n * - Verbose logging capability\n *\n * @param command - The command to run\n * @param args - List of string arguments\n * @param options - Configuration options for the spawned process\n * @returns Promise that resolves with the process results including pid, stdout, stderr, status, and signal\n * @throws Will reject the promise if the process fails to spawn or encounters an error\n *\n * @example\n * ```typescript\n * const result = await spawnAsync('ls', ['-la'], { verbose: true });\n * console.log(result.stdout);\n * ```\n */\nexport async function spawnAsync(\n command: string,\n args?: ReadonlyArray<string>,\n options?: SpawnAsyncOptions\n): Promise<SpawnAsyncReturns> {\n return new Promise((resolve, reject) => {\n try {\n const proc = spawn(command, args ?? [], options ?? {});\n // `setEncoding` is undefined in Bun\n proc.stdout?.setEncoding?.('utf8');\n proc.stderr?.setEncoding?.('utf8');\n\n let stdout = '';\n let stderr = '';\n proc.stdout?.on('data', (data: string) => {\n stdout += data;\n if (options?.printingStdout) {\n process.stdout.write(data);\n }\n });\n proc.stderr?.on('data', (data: string) => {\n if (options?.mergeOutAndError) {\n stdout += data;\n } else {\n stderr += data;\n }\n if (options?.printingStderr) {\n process.stderr.write(data);\n }\n });\n\n let stopped = false;\n const stopProcess = (): void => {\n if (stopped || !proc.pid) return;\n\n stopped = true;\n if (options?.verbose) {\n console.info(`treeKill(${proc.pid})`);\n }\n treeKill(proc.pid);\n };\n if (options?.killOnExit) {\n process.on('beforeExit', stopProcess);\n process.on('SIGINT', stopProcess);\n }\n\n proc.on('error', (error) => {\n process.removeListener('beforeExit', stopProcess);\n process.removeListener('SIGINT', stopProcess);\n proc.removeAllListeners('close');\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n process.removeListener('beforeExit', stopProcess);\n process.removeListener('SIGINT', stopProcess);\n if (proc.pid === undefined) {\n reject(new Error('Process has no pid.'));\n } else {\n resolve({\n pid: proc.pid,\n stdout,\n stderr,\n status: code,\n signal,\n });\n }\n });\n\n if (options?.input) {\n proc.stdin?.write(options.input);\n proc.stdin?.end();\n }\n } catch (error) {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error);\n }\n });\n}\n"],"names":["async","command","args","options","Promise","resolve","reject","proc","spawn","stdout","setEncoding","stderr","on","data","printingStdout","process","write","mergeOutAndError","printingStderr","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","error","removeListener","removeAllListeners","code","signal","undefined","Error","status","input","stdin","end"],"mappings":"2FAoEOA,eACLC,EACAC,EACAC,GAEA,OAAO,IAAIC,QAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAAA,MAAMP,EAASC,GAAQ,GAAIC,GAAW,IAEnDI,EAAKE,QAAQC,cAAc,QAC3BH,EAAKI,QAAQD,cAAc,QAE3B,IAAID,EAAS,GACTE,EAAS,GACbJ,EAAKE,QAAQG,GAAG,OAASC,IACvBJ,GAAUI,EACNV,GAASW,gBACXC,QAAQN,OAAOO,MAAMH,KAGzBN,EAAKI,QAAQC,GAAG,OAASC,IACnBV,GAASc,iBACXR,GAAUI,EAEVF,GAAUE,EAERV,GAASe,gBACXH,QAAQJ,OAAOK,MAAMH,KAIzB,IAAIM,GAAU,EACd,MAAMC,EAAcA,MACdD,GAAYZ,EAAKc,MAErBF,GAAU,EACNhB,GAASmB,SACXC,QAAQC,KAAK,YAAYjB,EAAKc,QAEhCI,EAASlB,EAAKc,OAEZlB,GAASuB,aACXX,QAAQH,GAAG,aAAcQ,GACzBL,QAAQH,GAAG,SAAUQ,IAGvBb,EAAKK,GAAG,QAAUe,IAChBZ,QAAQa,eAAe,aAAcR,GACrCL,QAAQa,eAAe,SAAUR,GACjCb,EAAKsB,mBAAmB,SACxBvB,EAAOqB,KAETpB,EAAKK,GAAG,QAAS,CAACkB,EAAqBC,KACrChB,QAAQa,eAAe,aAAcR,GACrCL,QAAQa,eAAe,SAAUR,QAChBY,IAAbzB,EAAKc,IACPf,EAAO,IAAI2B,MAAM,wBAEjB5B,EAAQ,CACNgB,IAAKd,EAAKc,IACVZ,SACAE,SACAuB,OAAQJ,EACRC,aAKF5B,GAASgC,QACX5B,EAAK6B,OAAOpB,MAAMb,EAAQgC,OAC1B5B,EAAK6B,OAAOC,MAEhB,CAAE,MAAOV,GAEPrB,EAAOqB,EACT,GAEJ"}
package/dist/spawn.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"spawn.js","sources":["../src/spawn.ts"],"sourcesContent":["import type {\n SpawnOptions,\n SpawnOptionsWithoutStdio,\n SpawnOptionsWithStdioTuple,\n SpawnSyncReturns,\n StdioNull,\n StdioPipe,\n} from 'node:child_process';\nimport { spawn } from 'node:child_process';\n\nimport treeKill from 'tree-kill';\n\n/**\n * Return type for spawnAsync function, based on SpawnSyncReturns but without output and error properties\n */\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\n/**\n * Options for spawnAsync function, extending various Node.js spawn options with additional functionality\n */\nexport type SpawnAsyncOptions = (\n | SpawnOptionsWithoutStdio\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>\n | SpawnOptions\n) & {\n /** Input string to write to the spawned process's stdin */\n input?: string;\n /** If true, stderr output will be merged into stdout */\n mergeOutAndError?: boolean;\n /** If true, the spawned process will be killed when the parent process exits */\n killOnExit?: boolean;\n /** If true, enables verbose logging of process operations */\n verbose?: boolean;\n /** If true, stdout data will be printed to console as it's received */\n printingStdout?: boolean;\n /** If true, stderr data will be printed to console as it's received */\n printingStderr?: boolean;\n};\n\n/**\n * Spawns a child process asynchronously and returns a promise that resolves with the process results\n *\n * This function provides a Promise-based wrapper around Node.js's spawn function with additional features:\n * - Automatic encoding of stdout/stderr as UTF-8\n * - Option to merge stderr into stdout\n * - Option to automatically kill the process on parent exit\n * - Option to provide input via stdin\n * - Verbose logging capability\n *\n * @param command - The command to run\n * @param args - List of string arguments\n * @param options - Configuration options for the spawned process\n * @returns Promise that resolves with the process results including pid, stdout, stderr, status, and signal\n * @throws Will reject the promise if the process fails to spawn or encounters an error\n *\n * @example\n * ```typescript\n * const result = await spawnAsync('ls', ['-la'], { verbose: true });\n * console.log(result.stdout);\n * ```\n */\nexport async function spawnAsync(\n command: string,\n args?: ReadonlyArray<string>,\n options?: SpawnAsyncOptions\n): Promise<SpawnAsyncReturns> {\n return new Promise((resolve, reject) => {\n try {\n const proc = spawn(command, args ?? [], options ?? {});\n // `setEncoding` is undefined in Bun\n proc.stdout?.setEncoding?.('utf8');\n proc.stderr?.setEncoding?.('utf8');\n\n let stdout = '';\n let stderr = '';\n proc.stdout?.on('data', (data: string) => {\n stdout += data;\n if (options?.printingStdout) {\n process.stdout.write(data);\n }\n });\n proc.stderr?.on('data', (data: string) => {\n if (options?.mergeOutAndError) {\n stdout += data;\n } else {\n stderr += data;\n }\n if (options?.printingStderr) {\n process.stderr.write(data);\n }\n });\n\n let stopped = false;\n const stopProcess = (): void => {\n if (stopped || !proc.pid) return;\n\n stopped = true;\n if (options?.verbose) {\n console.info(`treeKill(${proc.pid})`);\n }\n treeKill(proc.pid);\n };\n if (options?.killOnExit) {\n process.on('beforeExit', stopProcess);\n process.on('SIGINT', stopProcess);\n }\n\n proc.on('error', (error) => {\n process.removeListener('beforeExit', stopProcess);\n process.removeListener('SIGINT', stopProcess);\n proc.removeAllListeners('close');\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n process.removeListener('beforeExit', stopProcess);\n process.removeListener('SIGINT', stopProcess);\n if (proc.pid === undefined) {\n reject(new Error('Process has no pid.'));\n } else {\n resolve({\n pid: proc.pid,\n stdout,\n stderr,\n status: code,\n signal,\n });\n }\n });\n\n if (options?.input) {\n proc.stdin?.write(options.input);\n proc.stdin?.end();\n }\n } catch (error) {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error);\n }\n });\n}\n"],"names":["async","spawnAsync","command","args","options","Promise","resolve","reject","proc","spawn","stdout","setEncoding","stderr","on","data","printingStdout","process","write","mergeOutAndError","printingStderr","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","error","removeListener","removeAllListeners","code","signal","undefined","Error","status","input","stdin","end"],"mappings":"oEAoEOA,eAAeC,EACpBC,EACAC,EACAC,GAEA,OAAO,IAAIC,QAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAMP,EAASC,GAAQ,GAAIC,GAAW,IAEnDI,EAAKE,QAAQC,cAAc,QAC3BH,EAAKI,QAAQD,cAAc,QAE3B,IAAID,EAAS,GACTE,EAAS,GACbJ,EAAKE,QAAQG,GAAG,OAASC,IACvBJ,GAAUI,EACNV,GAASW,gBACXC,QAAQN,OAAOO,MAAMH,KAGzBN,EAAKI,QAAQC,GAAG,OAASC,IACnBV,GAASc,iBACXR,GAAUI,EAEVF,GAAUE,EAERV,GAASe,gBACXH,QAAQJ,OAAOK,MAAMH,KAIzB,IAAIM,GAAU,EACd,MAAMC,EAAcA,MACdD,GAAYZ,EAAKc,MAErBF,GAAU,EACNhB,GAASmB,SACXC,QAAQC,KAAK,YAAYjB,EAAKc,QAEhCI,EAASlB,EAAKc,OAEZlB,GAASuB,aACXX,QAAQH,GAAG,aAAcQ,GACzBL,QAAQH,GAAG,SAAUQ,IAGvBb,EAAKK,GAAG,QAAUe,IAChBZ,QAAQa,eAAe,aAAcR,GACrCL,QAAQa,eAAe,SAAUR,GACjCb,EAAKsB,mBAAmB,SACxBvB,EAAOqB,KAETpB,EAAKK,GAAG,QAAS,CAACkB,EAAqBC,KACrChB,QAAQa,eAAe,aAAcR,GACrCL,QAAQa,eAAe,SAAUR,QAChBY,IAAbzB,EAAKc,IACPf,EAAO,IAAI2B,MAAM,wBAEjB5B,EAAQ,CACNgB,IAAKd,EAAKc,IACVZ,SACAE,SACAuB,OAAQJ,EACRC,aAKF5B,GAASgC,QACX5B,EAAK6B,OAAOpB,MAAMb,EAAQgC,OAC1B5B,EAAK6B,OAAOC,OAEd,MAAOV,GAEPrB,EAAOqB,EACT,GAEJ"}
1
+ {"version":3,"file":"spawn.js","sources":["../src/spawn.ts"],"sourcesContent":["import type {\n SpawnOptions,\n SpawnOptionsWithoutStdio,\n SpawnOptionsWithStdioTuple,\n SpawnSyncReturns,\n StdioNull,\n StdioPipe,\n} from 'node:child_process';\nimport { spawn } from 'node:child_process';\n\nimport treeKill from 'tree-kill';\n\n/**\n * Return type for spawnAsync function, based on SpawnSyncReturns but without output and error properties\n */\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\n/**\n * Options for spawnAsync function, extending various Node.js spawn options with additional functionality\n */\nexport type SpawnAsyncOptions = (\n | SpawnOptionsWithoutStdio\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>\n | SpawnOptions\n) & {\n /** Input string to write to the spawned process's stdin */\n input?: string;\n /** If true, stderr output will be merged into stdout */\n mergeOutAndError?: boolean;\n /** If true, the spawned process will be killed when the parent process exits */\n killOnExit?: boolean;\n /** If true, enables verbose logging of process operations */\n verbose?: boolean;\n /** If true, stdout data will be printed to console as it's received */\n printingStdout?: boolean;\n /** If true, stderr data will be printed to console as it's received */\n printingStderr?: boolean;\n};\n\n/**\n * Spawns a child process asynchronously and returns a promise that resolves with the process results\n *\n * This function provides a Promise-based wrapper around Node.js's spawn function with additional features:\n * - Automatic encoding of stdout/stderr as UTF-8\n * - Option to merge stderr into stdout\n * - Option to automatically kill the process on parent exit\n * - Option to provide input via stdin\n * - Verbose logging capability\n *\n * @param command - The command to run\n * @param args - List of string arguments\n * @param options - Configuration options for the spawned process\n * @returns Promise that resolves with the process results including pid, stdout, stderr, status, and signal\n * @throws Will reject the promise if the process fails to spawn or encounters an error\n *\n * @example\n * ```typescript\n * const result = await spawnAsync('ls', ['-la'], { verbose: true });\n * console.log(result.stdout);\n * ```\n */\nexport async function spawnAsync(\n command: string,\n args?: ReadonlyArray<string>,\n options?: SpawnAsyncOptions\n): Promise<SpawnAsyncReturns> {\n return new Promise((resolve, reject) => {\n try {\n const proc = spawn(command, args ?? [], options ?? {});\n // `setEncoding` is undefined in Bun\n proc.stdout?.setEncoding?.('utf8');\n proc.stderr?.setEncoding?.('utf8');\n\n let stdout = '';\n let stderr = '';\n proc.stdout?.on('data', (data: string) => {\n stdout += data;\n if (options?.printingStdout) {\n process.stdout.write(data);\n }\n });\n proc.stderr?.on('data', (data: string) => {\n if (options?.mergeOutAndError) {\n stdout += data;\n } else {\n stderr += data;\n }\n if (options?.printingStderr) {\n process.stderr.write(data);\n }\n });\n\n let stopped = false;\n const stopProcess = (): void => {\n if (stopped || !proc.pid) return;\n\n stopped = true;\n if (options?.verbose) {\n console.info(`treeKill(${proc.pid})`);\n }\n treeKill(proc.pid);\n };\n if (options?.killOnExit) {\n process.on('beforeExit', stopProcess);\n process.on('SIGINT', stopProcess);\n }\n\n proc.on('error', (error) => {\n process.removeListener('beforeExit', stopProcess);\n process.removeListener('SIGINT', stopProcess);\n proc.removeAllListeners('close');\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n process.removeListener('beforeExit', stopProcess);\n process.removeListener('SIGINT', stopProcess);\n if (proc.pid === undefined) {\n reject(new Error('Process has no pid.'));\n } else {\n resolve({\n pid: proc.pid,\n stdout,\n stderr,\n status: code,\n signal,\n });\n }\n });\n\n if (options?.input) {\n proc.stdin?.write(options.input);\n proc.stdin?.end();\n }\n } catch (error) {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error);\n }\n });\n}\n"],"names":["async","spawnAsync","command","args","options","Promise","resolve","reject","proc","spawn","stdout","setEncoding","stderr","on","data","printingStdout","process","write","mergeOutAndError","printingStderr","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","error","removeListener","removeAllListeners","code","signal","undefined","Error","status","input","stdin","end"],"mappings":"oEAoEOA,eAAeC,EACpBC,EACAC,EACAC,GAEA,OAAO,IAAIC,QAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAMP,EAASC,GAAQ,GAAIC,GAAW,IAEnDI,EAAKE,QAAQC,cAAc,QAC3BH,EAAKI,QAAQD,cAAc,QAE3B,IAAID,EAAS,GACTE,EAAS,GACbJ,EAAKE,QAAQG,GAAG,OAASC,IACvBJ,GAAUI,EACNV,GAASW,gBACXC,QAAQN,OAAOO,MAAMH,KAGzBN,EAAKI,QAAQC,GAAG,OAASC,IACnBV,GAASc,iBACXR,GAAUI,EAEVF,GAAUE,EAERV,GAASe,gBACXH,QAAQJ,OAAOK,MAAMH,KAIzB,IAAIM,GAAU,EACd,MAAMC,EAAcA,MACdD,GAAYZ,EAAKc,MAErBF,GAAU,EACNhB,GAASmB,SACXC,QAAQC,KAAK,YAAYjB,EAAKc,QAEhCI,EAASlB,EAAKc,OAEZlB,GAASuB,aACXX,QAAQH,GAAG,aAAcQ,GACzBL,QAAQH,GAAG,SAAUQ,IAGvBb,EAAKK,GAAG,QAAUe,IAChBZ,QAAQa,eAAe,aAAcR,GACrCL,QAAQa,eAAe,SAAUR,GACjCb,EAAKsB,mBAAmB,SACxBvB,EAAOqB,KAETpB,EAAKK,GAAG,QAAS,CAACkB,EAAqBC,KACrChB,QAAQa,eAAe,aAAcR,GACrCL,QAAQa,eAAe,SAAUR,QAChBY,IAAbzB,EAAKc,IACPf,EAAO,IAAI2B,MAAM,wBAEjB5B,EAAQ,CACNgB,IAAKd,EAAKc,IACVZ,SACAE,SACAuB,OAAQJ,EACRC,aAKF5B,GAASgC,QACX5B,EAAK6B,OAAOpB,MAAMb,EAAQgC,OAC1B5B,EAAK6B,OAAOC,MAEhB,CAAE,MAAOV,GAEPrB,EAAOqB,EACT,GAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/shared-lib-node",
3
- "version": "7.0.1",
3
+ "version": "7.0.2",
4
4
  "license": "Apache-2.0",
5
5
  "author": "WillBooster Inc.",
6
6
  "sideEffects": false,
@@ -38,17 +38,17 @@
38
38
  },
39
39
  "prettier": "@willbooster/prettier-config",
40
40
  "dependencies": {
41
- "dotenv": "17.0.1",
41
+ "dotenv": "17.2.0",
42
42
  "tree-kill": "1.2.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/bun": "1.2.18",
46
46
  "@types/eslint": "9.6.1",
47
47
  "@types/micromatch": "4.0.9",
48
- "@types/node": "24.0.10",
48
+ "@types/node": "24.0.13",
49
49
  "@willbooster/eslint-config-ts": "11.4.0",
50
50
  "@willbooster/prettier-config": "10.2.0",
51
- "build-ts": "15.0.9",
51
+ "build-ts": "15.0.12",
52
52
  "eslint": "9.30.1",
53
53
  "eslint-config-flat-gitignore": "2.1.0",
54
54
  "eslint-config-prettier": "10.1.5",
@@ -65,7 +65,7 @@
65
65
  "prettier-plugin-java": "2.7.1",
66
66
  "sort-package-json": "3.4.0",
67
67
  "typescript": "5.8.3",
68
- "typescript-eslint": "8.35.1",
68
+ "typescript-eslint": "8.36.0",
69
69
  "vitest": "3.2.4"
70
70
  },
71
71
  "publishConfig": {