@willbooster/shared-lib-node 1.2.0 → 1.2.1
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/cjs/spawn.cjs +1 -1
- package/dist/cjs/spawn.cjs.map +1 -1
- package/dist/esm/spawn.js +1 -1
- package/dist/esm/spawn.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/spawn.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var e=require("node:child_process");exports.spawnAsync=async function(s,t,r){return new Promise(((o,n)=>{try{const c=e.spawn(s,t??[],r??{});let i="",p="";c.stdout?.on("data",(e=>{i+=e})),c.stderr?.on("data",(e=>{p+=e}));const d=()=>{try{const s=e.execSync(`pstree -p ${c.pid}`).toString().split("\n").map((e=>{const[s]=e.match(/\d+/)??[];return Number(s)})),t=[];for(const e of s)e>0&&(e===c.pid||t.length>0)&&t.push(e);e.execSync(`kill ${t.join(" ")}`)}catch{}};process.on("exit",d),c.on("error",(e=>{process.removeListener("exit",d),c.removeAllListeners("close"),n(e)})),c.on("close",((e,s)=>{process.removeListener("exit",d),void 0===c.pid?n(new Error("Process has no pid.")):o({pid:c.pid,stdout:i,stderr:p,status:e,signal:s})}))}catch(e){n(e)}}))};
|
|
2
2
|
//# sourceMappingURL=spawn.cjs.map
|
package/dist/cjs/spawn.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn.cjs","sources":["../../src/spawn.ts"],"sourcesContent":["import {\n spawn,\n SpawnOptions,\n SpawnOptionsWithoutStdio,\n SpawnOptionsWithStdioTuple,\n SpawnSyncReturns,\n StdioNull,\n StdioPipe,\n} from 'node:child_process';\n\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\nexport async function spawnAsync(\n command: string,\n args?: ReadonlyArray<string>,\n options?:\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): 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 proc.stdout?.on('data', (data) => {\n stdout += data;\n });\n proc.stderr?.on('data', (data) => {\n stderr += data;\n });\n\n proc.on('error', (error) => {\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\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","on","data","error","code","signal","undefined","
|
|
1
|
+
{"version":3,"file":"spawn.cjs","sources":["../../src/spawn.ts"],"sourcesContent":["import {\n spawn,\n SpawnOptions,\n SpawnOptionsWithoutStdio,\n SpawnOptionsWithStdioTuple,\n SpawnSyncReturns,\n StdioNull,\n StdioPipe,\n execSync,\n} from 'node:child_process';\n\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\nexport async function spawnAsync(\n command: string,\n args?: ReadonlyArray<string>,\n options?:\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): 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 proc.stdout?.on('data', (data) => {\n stdout += data;\n });\n proc.stderr?.on('data', (data) => {\n stderr += data;\n });\n\n const stopProcess = (): void => {\n try {\n const procIdLines = execSync(`pstree -p ${proc.pid}`).toString();\n const procIds = procIdLines.split('\\n').map((line) => {\n const [pid] = line.match(/\\d+/) ?? [];\n return Number(pid);\n });\n const descendantProcIds = [];\n for (const pid of procIds) {\n if (pid > 0 && (pid === proc.pid || descendantProcIds.length > 0)) {\n descendantProcIds.push(pid);\n }\n }\n execSync(`kill ${descendantProcIds.join(' ')}`);\n } catch {\n // do nothing.\n }\n };\n process.on('exit', stopProcess);\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","on","data","stopProcess","procIds","execSync","pid","toString","split","map","line","match","Number","descendantProcIds","length","push","join","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status"],"mappings":"oEAaOA,eACLC,EACAC,EACAC,GAYA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAAA,MAAMP,EAASC,GAAQ,GAAIC,GAAW,CAAA,GACnD,IAAIM,EAAS,GACTC,EAAS,GAEbH,EAAKE,QAAQE,GAAG,QAASC,IACvBH,GAAUG,CAAI,IAEhBL,EAAKG,QAAQC,GAAG,QAASC,IACvBF,GAAUE,CAAI,IAGhB,MAAMC,EAAc,KAClB,IACE,MACMC,EADcC,EAAQA,SAAE,aAAYR,EAAKS,OAAOC,WAC1BC,MAAM,MAAMC,KAAKC,IAC3C,MAAOJ,GAAOI,EAAKC,MAAM,QAAU,GACnC,OAAOC,OAAON,EAAI,IAEdO,EAAoB,GAC1B,IAAK,MAAMP,KAAOF,EACZE,EAAM,IAAMA,IAAQT,EAAKS,KAAOO,EAAkBC,OAAS,IAC7DD,EAAkBE,KAAKT,GAG3BD,EAAQA,SAAE,QAAOQ,EAAkBG,KAAK,OAExC,CADA,MACA,GAGJC,QAAQhB,GAAG,OAAQE,GAEnBN,EAAKI,GAAG,SAAUiB,IAChBD,QAAQE,eAAe,OAAQhB,GAC/BN,EAAKuB,mBAAmB,SACxBxB,EAAOsB,EAAM,IAEfrB,EAAKI,GAAG,SAAS,CAACoB,EAAqBC,KACrCL,QAAQE,eAAe,OAAQhB,QACdoB,IAAb1B,EAAKS,IACPV,EAAO,IAAI4B,MAAM,wBAEjB7B,EAAQ,CACNW,IAAKT,EAAKS,IACVP,SACAC,SACAyB,OAAQJ,EACRC,UAEJ,GAIJ,CAFE,MAAOJ,GACPtB,EAAOsB,EACT,IAEJ"}
|
package/dist/esm/spawn.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{spawn as
|
|
1
|
+
import{spawn as e,execSync as t}from"node:child_process";async function o(o,r,s){return new Promise(((n,i)=>{try{const c=e(o,r??[],s??{});let p="",d="";c.stdout?.on("data",(e=>{p+=e})),c.stderr?.on("data",(e=>{d+=e}));const a=()=>{try{const e=t(`pstree -p ${c.pid}`).toString().split("\n").map((e=>{const[t]=e.match(/\d+/)??[];return Number(t)})),o=[];for(const t of e)t>0&&(t===c.pid||o.length>0)&&o.push(t);t(`kill ${o.join(" ")}`)}catch{}};process.on("exit",a),c.on("error",(e=>{process.removeListener("exit",a),c.removeAllListeners("close"),i(e)})),c.on("close",((e,t)=>{process.removeListener("exit",a),void 0===c.pid?i(new Error("Process has no pid.")):n({pid:c.pid,stdout:p,stderr:d,status:e,signal:t})}))}catch(e){i(e)}}))}export{o as spawnAsync};
|
|
2
2
|
//# sourceMappingURL=spawn.js.map
|
package/dist/esm/spawn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn.js","sources":["../../src/spawn.ts"],"sourcesContent":["import {\n spawn,\n SpawnOptions,\n SpawnOptionsWithoutStdio,\n SpawnOptionsWithStdioTuple,\n SpawnSyncReturns,\n StdioNull,\n StdioPipe,\n} from 'node:child_process';\n\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\nexport async function spawnAsync(\n command: string,\n args?: ReadonlyArray<string>,\n options?:\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): 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 proc.stdout?.on('data', (data) => {\n stdout += data;\n });\n proc.stderr?.on('data', (data) => {\n stderr += data;\n });\n\n proc.on('error', (error) => {\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\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","on","data","error","code","signal","undefined","
|
|
1
|
+
{"version":3,"file":"spawn.js","sources":["../../src/spawn.ts"],"sourcesContent":["import {\n spawn,\n SpawnOptions,\n SpawnOptionsWithoutStdio,\n SpawnOptionsWithStdioTuple,\n SpawnSyncReturns,\n StdioNull,\n StdioPipe,\n execSync,\n} from 'node:child_process';\n\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\nexport async function spawnAsync(\n command: string,\n args?: ReadonlyArray<string>,\n options?:\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): 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 proc.stdout?.on('data', (data) => {\n stdout += data;\n });\n proc.stderr?.on('data', (data) => {\n stderr += data;\n });\n\n const stopProcess = (): void => {\n try {\n const procIdLines = execSync(`pstree -p ${proc.pid}`).toString();\n const procIds = procIdLines.split('\\n').map((line) => {\n const [pid] = line.match(/\\d+/) ?? [];\n return Number(pid);\n });\n const descendantProcIds = [];\n for (const pid of procIds) {\n if (pid > 0 && (pid === proc.pid || descendantProcIds.length > 0)) {\n descendantProcIds.push(pid);\n }\n }\n execSync(`kill ${descendantProcIds.join(' ')}`);\n } catch {\n // do nothing.\n }\n };\n process.on('exit', stopProcess);\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","on","data","stopProcess","procIds","execSync","pid","toString","split","map","line","match","Number","descendantProcIds","length","push","join","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status"],"mappings":"yDAaOA,eAAeC,EACpBC,EACAC,EACAC,GAYA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAMP,EAASC,GAAQ,GAAIC,GAAW,CAAA,GACnD,IAAIM,EAAS,GACTC,EAAS,GAEbH,EAAKE,QAAQE,GAAG,QAASC,IACvBH,GAAUG,CAAI,IAEhBL,EAAKG,QAAQC,GAAG,QAASC,IACvBF,GAAUE,CAAI,IAGhB,MAAMC,EAAc,KAClB,IACE,MACMC,EADcC,EAAU,aAAYR,EAAKS,OAAOC,WAC1BC,MAAM,MAAMC,KAAKC,IAC3C,MAAOJ,GAAOI,EAAKC,MAAM,QAAU,GACnC,OAAOC,OAAON,EAAI,IAEdO,EAAoB,GAC1B,IAAK,MAAMP,KAAOF,EACZE,EAAM,IAAMA,IAAQT,EAAKS,KAAOO,EAAkBC,OAAS,IAC7DD,EAAkBE,KAAKT,GAG3BD,EAAU,QAAOQ,EAAkBG,KAAK,OAExC,CADA,MACA,GAGJC,QAAQhB,GAAG,OAAQE,GAEnBN,EAAKI,GAAG,SAAUiB,IAChBD,QAAQE,eAAe,OAAQhB,GAC/BN,EAAKuB,mBAAmB,SACxBxB,EAAOsB,EAAM,IAEfrB,EAAKI,GAAG,SAAS,CAACoB,EAAqBC,KACrCL,QAAQE,eAAe,OAAQhB,QACdoB,IAAb1B,EAAKS,IACPV,EAAO,IAAI4B,MAAM,wBAEjB7B,EAAQ,CACNW,IAAKT,EAAKS,IACVP,SACAC,SACAyB,OAAQJ,EACRC,UAEJ,GAIJ,CAFE,MAAOJ,GACPtB,EAAOsB,EACT,IAEJ"}
|