@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 +1 -1
- package/dist/spawn.cjs.map +1 -1
- package/dist/spawn.d.ts +0 -4
- package/dist/spawn.js +1 -1
- package/dist/spawn.js.map +1 -1
- package/package.json +1 -1
package/dist/spawn.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("node:child_process"),
|
|
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
|
package/dist/spawn.cjs.map
CHANGED
|
@@ -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';\
|
|
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
|
|
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';\
|
|
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"}
|