@willbooster/shared-lib-node 5.2.1 → 5.2.3

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/spawn.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("node:child_process"),t=require("node:timers/promises"),s=require("tree-kill");exports.spawnAsync=async function(r,o,i){return new Promise(((n,d)=>{try{const c=e.spawn(r,o??[],i??{});c.stdout?.setEncoding?.("utf8"),c.stderr?.setEncoding?.("utf8");let p="",a="";c.stdout?.on("data",(e=>{p+=e})),c.stderr?.on("data",(e=>{i?.mergeOutAndError?p+=e:a+=e}));let u=!1;const l=()=>{!u&&c.pid&&(u=!0,i?.verbose&&console.info(`treeKill(${c.pid})`),s(c.pid))};if(i?.killOnExit&&(process.on("beforeExit",l),process.on("SIGINT",l)),c.on("error",(e=>{process.removeListener("beforeExit",l),process.removeListener("SIGINT",l),c.removeAllListeners("close"),d(e)})),c.on("close",((e,t)=>{process.removeListener("beforeExit",l),process.removeListener("SIGINT",l),void 0===c.pid?d(new Error("Process has no pid.")):n({pid:c.pid,stdout:p,stderr:a,status:e,signal:t})})),i?.input)c.stdin?.write(i.input),c.stdin?.end();else if(i?.inputs){const e=i.inputs.sort(((e,t)=>e.time-t.time));(async()=>{const s=Date.now();for(const{data:r,time:o}of e){if(await t.setTimeout(o-(Date.now()-s)),u)return;c.stdin?.write(r)}c.stdin?.end()})()}}catch(e){d(e)}}))};
1
+ "use strict";var e=require("node:child_process"),r=require("tree-kill");exports.spawnAsync=async function(s,t,o){return new Promise(((n,i)=>{try{const d=e.spawn(s,t??[],o??{});d.stdout?.setEncoding?.("utf8"),d.stderr?.setEncoding?.("utf8");let c="",p="";d.stdout?.on("data",(e=>{c+=e})),d.stderr?.on("data",(e=>{o?.mergeOutAndError?c+=e:p+=e}));let l=!1;const u=()=>{!l&&d.pid&&(l=!0,o?.verbose&&console.info(`treeKill(${d.pid})`),r(d.pid))};o?.killOnExit&&(process.on("beforeExit",u),process.on("SIGINT",u)),d.on("error",(e=>{process.removeListener("beforeExit",u),process.removeListener("SIGINT",u),d.removeAllListeners("close"),i(e)})),d.on("close",((e,r)=>{process.removeListener("beforeExit",u),process.removeListener("SIGINT",u),void 0===d.pid?i(new Error("Process has no pid.")):n({pid:d.pid,stdout:c,stderr:p,status:e,signal:r})})),o?.input&&(d.stdin?.write(o.input),d.stdin?.end())}catch(e){i(e)}}))};
2
2
  //# sourceMappingURL=spawn.cjs.map
@@ -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';\nimport { setTimeout } from 'node:timers/promises';\n\nimport treeKill from 'tree-kill';\n\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\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;\n inputs?: { data: string; time: number }[];\n mergeOutAndError?: boolean;\n killOnExit?: boolean;\n verbose?: boolean;\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) => {\n stdout += data;\n });\n proc.stderr?.on('data', (data) => {\n if (options?.mergeOutAndError) {\n stdout += data;\n } else {\n stderr += 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 } else if (options?.inputs) {\n const inputs = options.inputs.sort((a, b) => a.time - b.time);\n void (async () => {\n const startTime = Date.now();\n for (const { data, time } of inputs) {\n await setTimeout(time - (Date.now() - startTime));\n if (stopped) return;\n proc.stdin?.write(data);\n }\n proc.stdin?.end();\n })();\n }\n } catch (error) {\n reject(error);\n }\n });\n}\n"],"names":["async","command","args","options","Promise","resolve","reject","proc","spawn","stdout","setEncoding","stderr","on","data","mergeOutAndError","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status","input","stdin","write","end","inputs","sort","a","b","time","startTime","Date","now","setTimeout"],"mappings":"6HAkCOA,eACLC,EACAC,EACAC,G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WJ,GAAQE,KAAKC,MAAQF,IAClC1B,EAAS,OACbR,EAAK0B,OAAOC,MAAMrB,EACpB,CACAN,EAAK0B,OAAOE,KACb,EARI,EASP,CACD,CAAC,MAAOX,GACPlB,EAAOkB,EACT,IAEJ"}
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\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\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;\n mergeOutAndError?: boolean;\n killOnExit?: boolean;\n verbose?: boolean;\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) => {\n stdout += data;\n });\n proc.stderr?.on('data', (data) => {\n if (options?.mergeOutAndError) {\n stdout += data;\n } else {\n stderr += 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 reject(error);\n }\n });\n}\n"],"names":["async","command","args","options","Promise","resolve","reject","proc","spawn","stdout","setEncoding","stderr","on","data","mergeOutAndError","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status","input","stdin","write","end"],"mappings":"2FAgCOA,eACLC,EACAC,EACAC,GAEA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAAA,MAAMP,EAASC,GAAQ,GAAIC,GAAW,CAAA,GAEnDI,EAAKE,QAAQC,cAAc,QAC3BH,EAAKI,QAAQD,cAAc,QAE3B,IAAID,EAAS,GACTE,EAAS,GACbJ,EAAKE,QAAQG,GAAG,QAASC,IACvBJ,GAAUI,CAAI,IAEhBN,EAAKI,QAAQC,GAAG,QAASC,IACnBV,GAASW,iBACXL,GAAUI,EAEVF,GAAUE,CACZ,IAGF,IAAIE,GAAU,EACd,MAAMC,EAAcA,MACdD,GAAYR,EAAKU,MAErBF,GAAU,EACNZ,GAASe,SACXC,QAAQC,KAAK,YAAYb,EAAKU,QAEhCI,EAASd,EAAKU,KAAI,EAEhBd,GAASmB,aACXC,QAAQX,GAAG,aAAcI,GACzBO,QAAQX,GAAG,SAAUI,IAGvBT,EAAKK,GAAG,SAAUY,IAChBD,QAAQE,eAAe,aAAcT,GACrCO,QAAQE,eAAe,SAAUT,GACjCT,EAAKmB,mBAAmB,SACxBpB,EAAOkB,EAAM,IAEfjB,EAAKK,GAAG,SAAS,CAACe,EAAqBC,KACrCL,QAAQE,eAAe,aAAcT,GACrCO,QAAQE,eAAe,SAAUT,QAChBa,IAAbtB,EAAKU,IACPX,EAAO,IAAIwB,MAAM,wBAEjBzB,EAAQ,CACNY,IAAKV,EAAKU,IACVR,SACAE,SACAoB,OAAQJ,EACRC,UAEJ,IAGEzB,GAAS6B,QACXzB,EAAK0B,OAAOC,MAAM/B,EAAQ6B,OAC1BzB,EAAK0B,OAAOE,MAEf,CAAC,MAAOX,GACPlB,EAAOkB,EACT,IAEJ"}
package/dist/spawn.d.ts CHANGED
@@ -3,10 +3,6 @@ import type { SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple
3
3
  export type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;
4
4
  export type SpawnAsyncOptions = (SpawnOptionsWithoutStdio | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe> | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull> | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe> | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe> | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull> | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull> | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe> | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull> | SpawnOptions) & {
5
5
  input?: string;
6
- inputs?: {
7
- data: string;
8
- time: number;
9
- }[];
10
6
  mergeOutAndError?: boolean;
11
7
  killOnExit?: boolean;
12
8
  verbose?: boolean;
package/dist/spawn.js CHANGED
@@ -1,2 +1,2 @@
1
- import{spawn as e}from"node:child_process";import{setTimeout as t}from"node:timers/promises";import o from"tree-kill";async function r(r,s,i){return new Promise(((n,d)=>{try{const c=e(r,s??[],i??{});c.stdout?.setEncoding?.("utf8"),c.stderr?.setEncoding?.("utf8");let p="",m="";c.stdout?.on("data",(e=>{p+=e})),c.stderr?.on("data",(e=>{i?.mergeOutAndError?p+=e:m+=e}));let a=!1;const l=()=>{!a&&c.pid&&(a=!0,i?.verbose&&console.info(`treeKill(${c.pid})`),o(c.pid))};if(i?.killOnExit&&(process.on("beforeExit",l),process.on("SIGINT",l)),c.on("error",(e=>{process.removeListener("beforeExit",l),process.removeListener("SIGINT",l),c.removeAllListeners("close"),d(e)})),c.on("close",((e,t)=>{process.removeListener("beforeExit",l),process.removeListener("SIGINT",l),void 0===c.pid?d(new Error("Process has no pid.")):n({pid:c.pid,stdout:p,stderr:m,status:e,signal:t})})),i?.input)c.stdin?.write(i.input),c.stdin?.end();else if(i?.inputs){const e=i.inputs.sort(((e,t)=>e.time-t.time));(async()=>{const o=Date.now();for(const{data:r,time:s}of e){if(await t(s-(Date.now()-o)),a)return;c.stdin?.write(r)}c.stdin?.end()})()}}catch(e){d(e)}}))}export{r as spawnAsync};
1
+ import{spawn as e}from"node:child_process";import r from"tree-kill";async function o(o,t,s){return new Promise(((n,i)=>{try{const d=e(o,t??[],s??{});d.stdout?.setEncoding?.("utf8"),d.stderr?.setEncoding?.("utf8");let c="",p="";d.stdout?.on("data",(e=>{c+=e})),d.stderr?.on("data",(e=>{s?.mergeOutAndError?c+=e:p+=e}));let l=!1;const m=()=>{!l&&d.pid&&(l=!0,s?.verbose&&console.info(`treeKill(${d.pid})`),r(d.pid))};s?.killOnExit&&(process.on("beforeExit",m),process.on("SIGINT",m)),d.on("error",(e=>{process.removeListener("beforeExit",m),process.removeListener("SIGINT",m),d.removeAllListeners("close"),i(e)})),d.on("close",((e,r)=>{process.removeListener("beforeExit",m),process.removeListener("SIGINT",m),void 0===d.pid?i(new Error("Process has no pid.")):n({pid:d.pid,stdout:c,stderr:p,status:e,signal:r})})),s?.input&&(d.stdin?.write(s.input),d.stdin?.end())}catch(e){i(e)}}))}export{o as spawnAsync};
2
2
  //# sourceMappingURL=spawn.js.map
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';\nimport { setTimeout } from 'node:timers/promises';\n\nimport treeKill from 'tree-kill';\n\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\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;\n inputs?: { data: string; time: number }[];\n mergeOutAndError?: boolean;\n killOnExit?: boolean;\n verbose?: boolean;\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) => {\n stdout += data;\n });\n proc.stderr?.on('data', (data) => {\n if (options?.mergeOutAndError) {\n stdout += data;\n } else {\n stderr += 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 } else if (options?.inputs) {\n const inputs = options.inputs.sort((a, b) => a.time - b.time);\n void (async () => {\n const startTime = Date.now();\n for (const { data, time } of inputs) {\n await setTimeout(time - (Date.now() - startTime));\n if (stopped) return;\n proc.stdin?.write(data);\n }\n proc.stdin?.end();\n })();\n }\n } catch (error) {\n reject(error);\n }\n });\n}\n"],"names":["async","spawnAsync","command","args","options","Promise","resolve","reject","proc","spawn","stdout","setEncoding","stderr","on","data","mergeOutAndError","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status","input","stdin","write","end","inputs","sort","a","b","time","startTime","Date","now","setTimeout"],"mappings":"sHAkCOA,eAAeC,EACpBC,EACAC,EACAC,GAEA,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MAAQF,IAClC1B,EAAS,OACbR,EAAK0B,OAAOC,MAAMrB,EACpB,CACAN,EAAK0B,OAAOE,KACb,EARI,EASP,CACD,CAAC,MAAOX,GACPlB,EAAOkB,EACT,IAEJ"}
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\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\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;\n mergeOutAndError?: boolean;\n killOnExit?: boolean;\n verbose?: boolean;\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) => {\n stdout += data;\n });\n proc.stderr?.on('data', (data) => {\n if (options?.mergeOutAndError) {\n stdout += data;\n } else {\n stderr += 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 reject(error);\n }\n });\n}\n"],"names":["async","spawnAsync","command","args","options","Promise","resolve","reject","proc","spawn","stdout","setEncoding","stderr","on","data","mergeOutAndError","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status","input","stdin","write","end"],"mappings":"oEAgCOA,eAAeC,EACpBC,EACAC,EACAC,GAEA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAMP,EAASC,GAAQ,GAAIC,GAAW,CAAA,GAEnDI,EAAKE,QAAQC,cAAc,QAC3BH,EAAKI,QAAQD,cAAc,QAE3B,IAAID,EAAS,GACTE,EAAS,GACbJ,EAAKE,QAAQG,GAAG,QAASC,IACvBJ,GAAUI,CAAI,IAEhBN,EAAKI,QAAQC,GAAG,QAASC,IACnBV,GAASW,iBACXL,GAAUI,EAEVF,GAAUE,CACZ,IAGF,IAAIE,GAAU,EACd,MAAMC,EAAcA,MACdD,GAAYR,EAAKU,MAErBF,GAAU,EACNZ,GAASe,SACXC,QAAQC,KAAK,YAAYb,EAAKU,QAEhCI,EAASd,EAAKU,KAAI,EAEhBd,GAASmB,aACXC,QAAQX,GAAG,aAAcI,GACzBO,QAAQX,GAAG,SAAUI,IAGvBT,EAAKK,GAAG,SAAUY,IAChBD,QAAQE,eAAe,aAAcT,GACrCO,QAAQE,eAAe,SAAUT,GACjCT,EAAKmB,mBAAmB,SACxBpB,EAAOkB,EAAM,IAEfjB,EAAKK,GAAG,SAAS,CAACe,EAAqBC,KACrCL,QAAQE,eAAe,aAAcT,GACrCO,QAAQE,eAAe,SAAUT,QAChBa,IAAbtB,EAAKU,IACPX,EAAO,IAAIwB,MAAM,wBAEjBzB,EAAQ,CACNY,IAAKV,EAAKU,IACVR,SACAE,SACAoB,OAAQJ,EACRC,UAEJ,IAGEzB,GAAS6B,QACXzB,EAAK0B,OAAOC,MAAM/B,EAAQ6B,OAC1BzB,EAAK0B,OAAOE,MAEf,CAAC,MAAOX,GACPlB,EAAOkB,EACT,IAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/shared-lib-node",
3
- "version": "5.2.1",
3
+ "version": "5.2.3",
4
4
  "license": "Apache-2.0",
5
5
  "author": "WillBooster Inc.",
6
6
  "sideEffects": false,
@@ -42,9 +42,9 @@
42
42
  "devDependencies": {
43
43
  "@types/eslint": "8.56.10",
44
44
  "@types/micromatch": "4.0.7",
45
- "@types/node": "20.13.0",
46
- "@typescript-eslint/eslint-plugin": "7.12.0",
47
- "@typescript-eslint/parser": "7.12.0",
45
+ "@types/node": "20.14.7",
46
+ "@typescript-eslint/eslint-plugin": "7.13.1",
47
+ "@typescript-eslint/parser": "7.13.1",
48
48
  "@willbooster/eslint-config-ts": "10.6.0",
49
49
  "@willbooster/prettier-config": "9.1.2",
50
50
  "build-ts": "13.1.8",
@@ -54,12 +54,12 @@
54
54
  "eslint-plugin-import": "2.29.1",
55
55
  "eslint-plugin-sort-class-members": "1.20.0",
56
56
  "eslint-plugin-sort-destructure-keys": "2.0.0",
57
- "eslint-plugin-unicorn": "53.0.0",
58
- "lint-staged": "15.2.5",
57
+ "eslint-plugin-unicorn": "54.0.0",
58
+ "lint-staged": "15.2.7",
59
59
  "micromatch": "4.0.7",
60
- "prettier": "3.3.1",
60
+ "prettier": "3.3.2",
61
61
  "sort-package-json": "2.10.0",
62
- "typescript": "5.4.5",
62
+ "typescript": "5.5.2",
63
63
  "vitest": "1.6.0"
64
64
  },
65
65
  "publishConfig": {