@willbooster/shared-lib-node 2.2.1 → 2.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.
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("node:child_process");function t(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var r=t(require("node:os"));exports.spawnAsync=async function(t,n,o){return new Promise(((s,i)=>{try{const c=e.spawn(t,n??[],o??{});let p="",a="";o?.input&&(c.stdin?.write(o.input),c.stdin?.end()),c.stdout?.on("data",(e=>{p+=e})),c.stderr?.on("data",(e=>{o?.mergeOutAndError?p+=e:a+=e}));let d=!1;const l=()=>{if(!d){d=!0;try{let t,n;"darwin"===r.platform()?(t=e.execSync(`pstree ${c.pid}`).toString(),n=/\d+/):(t=e.execSync(`pstree -p ${c.pid}`).toString(),n=/\d+/g);const s=t.split("\n").flatMap((e=>(e.match(n)??[]).map(Number))),i=[];for(const e of s)e>0&&(e===c.pid||i.length>0)&&i.push(e);const p=`kill ${i.join(" ")}`;o?.verbose&&(console.info(t),console.info(`$ ${p}`)),e.execSync(p)}catch{}}};o?.killOnExit&&(process.on("beforeExit",l),process.on("SIGINT",l)),c.on("error",(e=>{process.removeListener("exit",l),c.removeAllListeners("close"),i(e)})),c.on("close",((e,t)=>{process.removeListener("exit",l),void 0===c.pid?i(new Error("Process has no pid.")):s({pid:c.pid,stdout:p,stderr:a,status:e,signal:t})}))}catch(e){i(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??{});let c="",p="";o?.input&&(d.stdin?.write(o.input),d.stdin?.end()),d.stdout?.on("data",(e=>{c+=e})),d.stderr?.on("data",(e=>{o?.mergeOutAndError?c+=e:p+=e}));let l=!1;const a=()=>{!l&&d.pid&&(l=!0,o?.verbose&&console.info(`treeKill(${d.pid})`),r(d.pid))};o?.killOnExit&&(process.on("beforeExit",a),process.on("SIGINT",a)),d.on("error",(e=>{process.removeListener("exit",a),d.removeAllListeners("close"),i(e)})),d.on("close",((e,r)=>{process.removeListener("exit",a),void 0===d.pid?i(new Error("Process has no pid.")):n({pid:d.pid,stdout:c,stderr:p,status:e,signal:r})}))}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, execSync } from 'node:child_process';\nimport * as os from 'node:os';\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 let stdout = '';\n let stderr = '';\n\n if (options?.input) {\n proc.stdin?.write(options.input);\n proc.stdin?.end();\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) return;\n stopped = true;\n try {\n let pstreeOutput: string;\n let regex: RegExp;\n if (os.platform() === 'darwin') {\n pstreeOutput = execSync(`pstree ${proc.pid}`).toString();\n regex = /\\d+/;\n } else {\n pstreeOutput = execSync(`pstree -p ${proc.pid}`).toString();\n regex = /\\d+/g;\n }\n const procIds = pstreeOutput.split('\\n').flatMap((line) => (line.match(regex) ?? []).map(Number));\n const descendantProcIds: number[] = [];\n for (const pid of procIds) {\n if (pid > 0 && (pid === proc.pid || descendantProcIds.length > 0)) {\n descendantProcIds.push(pid);\n }\n }\n\n const killScript = `kill ${descendantProcIds.join(' ')}`;\n if (options?.verbose) {\n console.info(pstreeOutput);\n console.info(`$ ${killScript}`);\n }\n execSync(killScript);\n } catch {\n // do nothing.\n }\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('exit', stopProcess);\n proc.removeAllListeners('close');\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n process.removeListener('exit', 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","stderr","input","stdin","write","end","on","data","mergeOutAndError","stopped","stopProcess","pstreeOutput","regex","os","platform","execSync","pid","toString","procIds","split","flatMap","line","match","map","Number","descendantProcIds","length","push","killScript","join","verbose","console","info","killOnExit","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status"],"mappings":"mWA+BOA,eACLC,EACAC,EACAC,GAEA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAAA,MAAMP,EAASC,GAAQ,GAAIC,GAAW,CAAA,GACnD,IAAIM,EAAS,GACTC,EAAS,GAETP,GAASQ,QACXJ,EAAKK,OAAOC,MAAMV,EAAQQ,OAC1BJ,EAAKK,OAAOE,OAEdP,EAAKE,QAAQM,GAAG,QAASC,IACvBP,GAAUO,CAAI,IAEhBT,EAAKG,QAAQK,GAAG,QAASC,IACnBb,GAASc,iBACXR,GAAUO,EAEVN,GAAUM,CACZ,IAGF,IAAIE,GAAU,EACd,MAAMC,EAAcA,KAClB,IAAID,EAAJ,CACAA,GAAU,EACV,IACE,IAAIE,EACAC,EACkB,WAAlBC,EAAGC,YACLH,EAAeI,EAAAA,SAAU,UAASjB,EAAKkB,OAAOC,WAC9CL,EAAQ,QAERD,EAAeI,EAAAA,SAAU,aAAYjB,EAAKkB,OAAOC,WACjDL,EAAQ,QAEV,MAAMM,EAAUP,EAAaQ,MAAM,MAAMC,SAASC,IAAUA,EAAKC,MAAMV,IAAU,IAAIW,IAAIC,UACnFC,EAA8B,GACpC,IAAK,MAAMT,KAAOE,EACZF,EAAM,IAAMA,IAAQlB,EAAKkB,KAAOS,EAAkBC,OAAS,IAC7DD,EAAkBE,KAAKX,GAI3B,MAAMY,EAAc,QAAOH,EAAkBI,KAAK,OAC9CnC,GAASoC,UACXC,QAAQC,KAAKrB,GACboB,QAAQC,KAAM,KAAIJ,MAEpBb,EAAQA,SAACa,EACX,CAAE,MACA,CA3BW,CA2BX,EAGAlC,GAASuC,aACXC,QAAQ5B,GAAG,aAAcI,GACzBwB,QAAQ5B,GAAG,SAAUI,IAGvBZ,EAAKQ,GAAG,SAAU6B,IAChBD,QAAQE,eAAe,OAAQ1B,GAC/BZ,EAAKuC,mBAAmB,SACxBxC,EAAOsC,EAAM,IAEfrC,EAAKQ,GAAG,SAAS,CAACgC,EAAqBC,KACrCL,QAAQE,eAAe,OAAQ1B,QACd8B,IAAb1C,EAAKkB,IACPnB,EAAO,IAAI4C,MAAM,wBAEjB7C,EAAQ,CACNoB,IAAKlB,EAAKkB,IACVhB,SACAC,SACAyC,OAAQJ,EACRC,UAEJ,GAEH,CAAC,MAAOJ,GACPtC,EAAOsC,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 let stdout = '';\n let stderr = '';\n\n if (options?.input) {\n proc.stdin?.write(options.input);\n proc.stdin?.end();\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('exit', stopProcess);\n proc.removeAllListeners('close');\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n process.removeListener('exit', 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","stderr","input","stdin","write","end","on","data","mergeOutAndError","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status"],"mappings":"2FAgCOA,eACLC,EACAC,EACAC,GAEA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAAA,MAAMP,EAASC,GAAQ,GAAIC,GAAW,CAAA,GACnD,IAAIM,EAAS,GACTC,EAAS,GAETP,GAASQ,QACXJ,EAAKK,OAAOC,MAAMV,EAAQQ,OAC1BJ,EAAKK,OAAOE,OAEdP,EAAKE,QAAQM,GAAG,QAASC,IACvBP,GAAUO,CAAI,IAEhBT,EAAKG,QAAQK,GAAG,QAASC,IACnBb,GAASc,iBACXR,GAAUO,EAEVN,GAAUM,CACZ,IAGF,IAAIE,GAAU,EACd,MAAMC,EAAcA,MACdD,GAAYX,EAAKa,MAErBF,GAAU,EACNf,GAASkB,SACXC,QAAQC,KAAM,YAAWhB,EAAKa,QAEhCI,EAASjB,EAAKa,KAAI,EAEhBjB,GAASsB,aACXC,QAAQX,GAAG,aAAcI,GACzBO,QAAQX,GAAG,SAAUI,IAGvBZ,EAAKQ,GAAG,SAAUY,IAChBD,QAAQE,eAAe,OAAQT,GAC/BZ,EAAKsB,mBAAmB,SACxBvB,EAAOqB,EAAM,IAEfpB,EAAKQ,GAAG,SAAS,CAACe,EAAqBC,KACrCL,QAAQE,eAAe,OAAQT,QACda,IAAbzB,EAAKa,IACPd,EAAO,IAAI2B,MAAM,wBAEjB5B,EAAQ,CACNe,IAAKb,EAAKa,IACVX,SACAC,SACAwB,OAAQJ,EACRC,UAEJ,GAEH,CAAC,MAAOJ,GACPrB,EAAOqB,EACT,IAEJ"}
package/dist/esm/spawn.js CHANGED
@@ -1,2 +1,2 @@
1
- import{spawn as o,execSync as e}from"node:child_process";import*as t from"node:os";async function r(r,s,n){return new Promise(((i,p)=>{try{const d=o(r,s??[],n??{});let c="",l="";n?.input&&(d.stdin?.write(n.input),d.stdin?.end()),d.stdout?.on("data",(o=>{c+=o})),d.stderr?.on("data",(o=>{n?.mergeOutAndError?c+=o:l+=o}));let a=!1;const m=()=>{if(!a){a=!0;try{let o,r;"darwin"===t.platform()?(o=e(`pstree ${d.pid}`).toString(),r=/\d+/):(o=e(`pstree -p ${d.pid}`).toString(),r=/\d+/g);const s=o.split("\n").flatMap((o=>(o.match(r)??[]).map(Number))),i=[];for(const o of s)o>0&&(o===d.pid||i.length>0)&&i.push(o);const p=`kill ${i.join(" ")}`;n?.verbose&&(console.info(o),console.info(`$ ${p}`)),e(p)}catch{}}};n?.killOnExit&&(process.on("beforeExit",m),process.on("SIGINT",m)),d.on("error",(o=>{process.removeListener("exit",m),d.removeAllListeners("close"),p(o)})),d.on("close",((o,e)=>{process.removeListener("exit",m),void 0===d.pid?p(new Error("Process has no pid.")):i({pid:d.pid,stdout:c,stderr:l,status:o,signal:e})}))}catch(o){p(o)}}))}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(((i,n)=>{try{const d=e(o,t??[],s??{});let p="",c="";s?.input&&(d.stdin?.write(s.input),d.stdin?.end()),d.stdout?.on("data",(e=>{p+=e})),d.stderr?.on("data",(e=>{s?.mergeOutAndError?p+=e:c+=e}));let l=!1;const a=()=>{!l&&d.pid&&(l=!0,s?.verbose&&console.info(`treeKill(${d.pid})`),r(d.pid))};s?.killOnExit&&(process.on("beforeExit",a),process.on("SIGINT",a)),d.on("error",(e=>{process.removeListener("exit",a),d.removeAllListeners("close"),n(e)})),d.on("close",((e,r)=>{process.removeListener("exit",a),void 0===d.pid?n(new Error("Process has no pid.")):i({pid:d.pid,stdout:p,stderr:c,status:e,signal:r})}))}catch(e){n(e)}}))}export{o as spawnAsync};
2
2
  //# sourceMappingURL=spawn.js.map
@@ -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, execSync } from 'node:child_process';\nimport * as os from 'node:os';\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 let stdout = '';\n let stderr = '';\n\n if (options?.input) {\n proc.stdin?.write(options.input);\n proc.stdin?.end();\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) return;\n stopped = true;\n try {\n let pstreeOutput: string;\n let regex: RegExp;\n if (os.platform() === 'darwin') {\n pstreeOutput = execSync(`pstree ${proc.pid}`).toString();\n regex = /\\d+/;\n } else {\n pstreeOutput = execSync(`pstree -p ${proc.pid}`).toString();\n regex = /\\d+/g;\n }\n const procIds = pstreeOutput.split('\\n').flatMap((line) => (line.match(regex) ?? []).map(Number));\n const descendantProcIds: number[] = [];\n for (const pid of procIds) {\n if (pid > 0 && (pid === proc.pid || descendantProcIds.length > 0)) {\n descendantProcIds.push(pid);\n }\n }\n\n const killScript = `kill ${descendantProcIds.join(' ')}`;\n if (options?.verbose) {\n console.info(pstreeOutput);\n console.info(`$ ${killScript}`);\n }\n execSync(killScript);\n } catch {\n // do nothing.\n }\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('exit', stopProcess);\n proc.removeAllListeners('close');\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n process.removeListener('exit', 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","stderr","input","stdin","write","end","on","data","mergeOutAndError","stopped","stopProcess","pstreeOutput","regex","os","platform","execSync","pid","toString","procIds","split","flatMap","line","match","map","Number","descendantProcIds","length","push","killScript","join","verbose","console","info","killOnExit","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status"],"mappings":"mFA+BOA,eAAeC,EACpBC,EACAC,EACAC,GAEA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAMP,EAASC,GAAQ,GAAIC,GAAW,CAAA,GACnD,IAAIM,EAAS,GACTC,EAAS,GAETP,GAASQ,QACXJ,EAAKK,OAAOC,MAAMV,EAAQQ,OAC1BJ,EAAKK,OAAOE,OAEdP,EAAKE,QAAQM,GAAG,QAASC,IACvBP,GAAUO,CAAI,IAEhBT,EAAKG,QAAQK,GAAG,QAASC,IACnBb,GAASc,iBACXR,GAAUO,EAEVN,GAAUM,CACZ,IAGF,IAAIE,GAAU,EACd,MAAMC,EAAcA,KAClB,IAAID,EAAJ,CACAA,GAAU,EACV,IACE,IAAIE,EACAC,EACkB,WAAlBC,EAAGC,YACLH,EAAeI,EAAU,UAASjB,EAAKkB,OAAOC,WAC9CL,EAAQ,QAERD,EAAeI,EAAU,aAAYjB,EAAKkB,OAAOC,WACjDL,EAAQ,QAEV,MAAMM,EAAUP,EAAaQ,MAAM,MAAMC,SAASC,IAAUA,EAAKC,MAAMV,IAAU,IAAIW,IAAIC,UACnFC,EAA8B,GACpC,IAAK,MAAMT,KAAOE,EACZF,EAAM,IAAMA,IAAQlB,EAAKkB,KAAOS,EAAkBC,OAAS,IAC7DD,EAAkBE,KAAKX,GAI3B,MAAMY,EAAc,QAAOH,EAAkBI,KAAK,OAC9CnC,GAASoC,UACXC,QAAQC,KAAKrB,GACboB,QAAQC,KAAM,KAAIJ,MAEpBb,EAASa,EACX,CAAE,MACA,CA3BW,CA2BX,EAGAlC,GAASuC,aACXC,QAAQ5B,GAAG,aAAcI,GACzBwB,QAAQ5B,GAAG,SAAUI,IAGvBZ,EAAKQ,GAAG,SAAU6B,IAChBD,QAAQE,eAAe,OAAQ1B,GAC/BZ,EAAKuC,mBAAmB,SACxBxC,EAAOsC,EAAM,IAEfrC,EAAKQ,GAAG,SAAS,CAACgC,EAAqBC,KACrCL,QAAQE,eAAe,OAAQ1B,QACd8B,IAAb1C,EAAKkB,IACPnB,EAAO,IAAI4C,MAAM,wBAEjB7C,EAAQ,CACNoB,IAAKlB,EAAKkB,IACVhB,SACAC,SACAyC,OAAQJ,EACRC,UAEJ,GAEH,CAAC,MAAOJ,GACPtC,EAAOsC,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 let stdout = '';\n let stderr = '';\n\n if (options?.input) {\n proc.stdin?.write(options.input);\n proc.stdin?.end();\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('exit', stopProcess);\n proc.removeAllListeners('close');\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n process.removeListener('exit', 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","stderr","input","stdin","write","end","on","data","mergeOutAndError","stopped","stopProcess","pid","verbose","console","info","treeKill","killOnExit","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status"],"mappings":"oEAgCOA,eAAeC,EACpBC,EACAC,EACAC,GAEA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAMP,EAASC,GAAQ,GAAIC,GAAW,CAAA,GACnD,IAAIM,EAAS,GACTC,EAAS,GAETP,GAASQ,QACXJ,EAAKK,OAAOC,MAAMV,EAAQQ,OAC1BJ,EAAKK,OAAOE,OAEdP,EAAKE,QAAQM,GAAG,QAASC,IACvBP,GAAUO,CAAI,IAEhBT,EAAKG,QAAQK,GAAG,QAASC,IACnBb,GAASc,iBACXR,GAAUO,EAEVN,GAAUM,CACZ,IAGF,IAAIE,GAAU,EACd,MAAMC,EAAcA,MACdD,GAAYX,EAAKa,MAErBF,GAAU,EACNf,GAASkB,SACXC,QAAQC,KAAM,YAAWhB,EAAKa,QAEhCI,EAASjB,EAAKa,KAAI,EAEhBjB,GAASsB,aACXC,QAAQX,GAAG,aAAcI,GACzBO,QAAQX,GAAG,SAAUI,IAGvBZ,EAAKQ,GAAG,SAAUY,IAChBD,QAAQE,eAAe,OAAQT,GAC/BZ,EAAKsB,mBAAmB,SACxBvB,EAAOqB,EAAM,IAEfpB,EAAKQ,GAAG,SAAS,CAACe,EAAqBC,KACrCL,QAAQE,eAAe,OAAQT,QACda,IAAbzB,EAAKa,IACPd,EAAO,IAAI2B,MAAM,wBAEjB5B,EAAQ,CACNe,IAAKb,EAAKa,IACVX,SACAC,SACAwB,OAAQJ,EACRC,UAEJ,GAEH,CAAC,MAAOJ,GACPrB,EAAOqB,EACT,IAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/shared-lib-node",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "license": "Apache-2.0",
5
5
  "author": "WillBooster Inc.",
6
6
  "sideEffects": false,
@@ -35,6 +35,9 @@
35
35
  "typecheck": "tsc --noEmit --Pretty"
36
36
  },
37
37
  "prettier": "@willbooster/prettier-config",
38
+ "dependencies": {
39
+ "tree-kill": "1.2.2"
40
+ },
38
41
  "devDependencies": {
39
42
  "@types/eslint": "8.40.2",
40
43
  "@types/micromatch": "4.0.2",