@willbooster/shared-lib-node 5.2.0 → 5.2.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.
package/dist/spawn.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("node:child_process"),s=require("node:timers/promises"),t=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="";if(i?.input)c.stdin?.write(i.input),c.stdin?.end();else if(i?.inputs){const e=i.inputs.sort(((e,s)=>e.time-s.time));(async()=>{const t=Date.now();for(const{data:r,time:o}of e)await s.setTimeout(o-(Date.now()-t)),c.stdin?.write(r);c.stdin?.end()})()}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})`),t(c.pid))};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,s)=>{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:s})}))}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 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 proc.stdin?.write(data);\n }\n proc.stdin?.end();\n })();\n }\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 } catch (error) {\n reject(error);\n }\n });\n}\n"],"names":["async","command","args","options","Promise","resolve","reject","proc","spawn","stdout","setEncoding","stderr","input","stdin","write","end","inputs","sort","a","b","time","startTime","Date","now","data","setTimeout","on","mergeOutAndError","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status"],"mappings":"6HAkCOA,eACLC,EACAC,EACAC,GAEA,OAAO,IAAIC,SAAQ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ACNyB,IAAKvB,EAAKuB,IACVrB,SACAE,SACAiC,OAAQJ,EACRC,UAEJ,GAEH,CAAC,MAAOJ,GACP/B,EAAO+B,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="";if(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)await t(s-(Date.now()-o)),c.stdin?.write(r);c.stdin?.end()})()}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))};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})}))}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 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 proc.stdin?.write(data);\n }\n proc.stdin?.end();\n })();\n }\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 } catch (error) {\n reject(error);\n }\n });\n}\n"],"names":["async","spawnAsync","command","args","options","Promise","resolve","reject","proc","spawn","stdout","setEncoding","stderr","input","stdin","write","end","inputs","sort","a","b","time","startTime","Date","now","data","setTimeout","on","mergeOutAndError","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status"],"mappings":"sHAkCOA,eAAeC,EACpBC,EACAC,EACAC,GAEA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAMP,EA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GAEH,CAAC,MAAOJ,GACP/B,EAAO+B,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.0",
3
+ "version": "5.2.2",
4
4
  "license": "Apache-2.0",
5
5
  "author": "WillBooster Inc.",
6
6
  "sideEffects": false,