@willbooster/shared-lib-node 1.2.0 → 1.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.
@@ -1,2 +1,2 @@
1
- "use strict";var s=require("node:child_process");exports.spawnAsync=async function(r,t,o){return new Promise(((n,e)=>{try{const d=s.spawn(r,t??[],o??{});let a="",c="";d.stdout?.on("data",(s=>{a+=s})),d.stderr?.on("data",(s=>{c+=s})),d.on("error",(s=>{e(s)})),d.on("close",((s,r)=>{void 0===d.pid?e(new Error("Process has no pid.")):n({pid:d.pid,stdout:a,stderr:c,status:s,signal:r})}))}catch(s){e(s)}}))};
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,c)=>{try{const i=e.spawn(t,n??[],o??{});let a="",p="";i.stdout?.on("data",(e=>{a+=e})),i.stderr?.on("data",(e=>{p+=e}));const d=()=>{try{let t,n;"darwin"===r.platform()?(t=e.execSync(`pstree ${i.pid}`).toString(),n=/\d+/):(t=e.execSync(`pstree -p ${i.pid}`).toString(),n=/\d+/g);const o=t.split("\n").flatMap((e=>(e.match(n)??[]).map(Number))),s=[];for(const e of o)e>0&&(e===i.pid||s.length>0)&&s.push(e);e.execSync(`kill ${s.join(" ")}`)}catch{}};process.on("exit",d),i.on("error",(e=>{process.removeListener("exit",d),i.removeAllListeners("close"),c(e)})),i.on("close",((e,t)=>{process.removeListener("exit",d),void 0===i.pid?c(new Error("Process has no pid.")):s({pid:i.pid,stdout:a,stderr:p,status:e,signal:t})}))}catch(e){c(e)}}))};
2
2
  //# sourceMappingURL=spawn.cjs.map
@@ -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","pid","Error","status"],"mappings":"oEAYOA,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,IAGhBL,EAAKI,GAAG,SAAUE,IAChBP,EAAOO,EAAM,IAEfN,EAAKI,GAAG,SAAS,CAACG,EAAqBC,UACpBC,IAAbT,EAAKU,IACPX,EAAO,IAAIY,MAAM,wBAEjBb,EAAQ,CACNY,IAAKV,EAAKU,IACVR,SACAC,SACAS,OAAQL,EACRC,UAEJ,GAIJ,CAFE,MAAOF,GACPP,EAAOO,EACT,IAEJ"}
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';\nimport * as os from 'node:os';\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 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 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","pstreeOutput","regex","os","platform","execSync","pid","toString","procIds","split","flatMap","line","match","map","Number","descendantProcIds","length","push","join","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status"],"mappings":"mWAcOA,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,IAAIC,EACAC,EACkB,WAAlBC,EAAGC,YACLH,EAAeI,EAAAA,SAAU,UAASX,EAAKY,OAAOC,WAC9CL,EAAQ,QAERD,EAAeI,EAAAA,SAAU,aAAYX,EAAKY,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,IAAQZ,EAAKY,KAAOS,EAAkBC,OAAS,IAC7DD,EAAkBE,KAAKX,GAG3BD,EAAQA,SAAE,QAAOU,EAAkBG,KAAK,OAExC,CADA,MACA,GAGJC,QAAQrB,GAAG,OAAQE,GAEnBN,EAAKI,GAAG,SAAUsB,IAChBD,QAAQE,eAAe,OAAQrB,GAC/BN,EAAK4B,mBAAmB,SACxB7B,EAAO2B,EAAM,IAEf1B,EAAKI,GAAG,SAAS,CAACyB,EAAqBC,KACrCL,QAAQE,eAAe,OAAQrB,QACdyB,IAAb/B,EAAKY,IACPb,EAAO,IAAIiC,MAAM,wBAEjBlC,EAAQ,CACNc,IAAKZ,EAAKY,IACVV,SACAC,SACA8B,OAAQJ,EACRC,UAEJ,GAIJ,CAFE,MAAOJ,GACP3B,EAAO2B,EACT,IAEJ"}
package/dist/esm/spawn.js CHANGED
@@ -1,2 +1,2 @@
1
- import{spawn as o}from"node:child_process";async function r(r,t,s){return new Promise(((n,d)=>{try{const e=o(r,t??[],s??{});let i="",a="";e.stdout?.on("data",(o=>{i+=o})),e.stderr?.on("data",(o=>{a+=o})),e.on("error",(o=>{d(o)})),e.on("close",((o,r)=>{void 0===e.pid?d(new Error("Process has no pid.")):n({pid:e.pid,stdout:i,stderr:a,status:o,signal:r})}))}catch(o){d(o)}}))}export{r as spawnAsync};
1
+ import{spawn as t,execSync as o}from"node:child_process";import*as e from"node:os";async function r(r,s,n){return new Promise(((i,p)=>{try{const d=t(r,s??[],n??{});let c="",a="";d.stdout?.on("data",(t=>{c+=t})),d.stderr?.on("data",(t=>{a+=t}));const l=()=>{try{let t,r;"darwin"===e.platform()?(t=o(`pstree ${d.pid}`).toString(),r=/\d+/):(t=o(`pstree -p ${d.pid}`).toString(),r=/\d+/g);const s=t.split("\n").flatMap((t=>(t.match(r)??[]).map(Number))),n=[];for(const t of s)t>0&&(t===d.pid||n.length>0)&&n.push(t);o(`kill ${n.join(" ")}`)}catch{}};process.on("exit",l),d.on("error",(t=>{process.removeListener("exit",l),d.removeAllListeners("close"),p(t)})),d.on("close",((t,o)=>{process.removeListener("exit",l),void 0===d.pid?p(new Error("Process has no pid.")):i({pid:d.pid,stdout:c,stderr:a,status:t,signal:o})}))}catch(t){p(t)}}))}export{r as spawnAsync};
2
2
  //# sourceMappingURL=spawn.js.map
@@ -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","pid","Error","status"],"mappings":"2CAYOA,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,IAGhBL,EAAKI,GAAG,SAAUE,IAChBP,EAAOO,EAAM,IAEfN,EAAKI,GAAG,SAAS,CAACG,EAAqBC,UACpBC,IAAbT,EAAKU,IACPX,EAAO,IAAIY,MAAM,wBAEjBb,EAAQ,CACNY,IAAKV,EAAKU,IACVR,SACAC,SACAS,OAAQL,EACRC,UAEJ,GAIJ,CAFE,MAAOF,GACPP,EAAOO,EACT,IAEJ"}
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';\nimport * as os from 'node:os';\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 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 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","pstreeOutput","regex","os","platform","execSync","pid","toString","procIds","split","flatMap","line","match","map","Number","descendantProcIds","length","push","join","process","error","removeListener","removeAllListeners","code","signal","undefined","Error","status"],"mappings":"mFAcOA,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,IAAIC,EACAC,EACkB,WAAlBC,EAAGC,YACLH,EAAeI,EAAU,UAASX,EAAKY,OAAOC,WAC9CL,EAAQ,QAERD,EAAeI,EAAU,aAAYX,EAAKY,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,IAAQZ,EAAKY,KAAOS,EAAkBC,OAAS,IAC7DD,EAAkBE,KAAKX,GAG3BD,EAAU,QAAOU,EAAkBG,KAAK,OAExC,CADA,MACA,GAGJC,QAAQrB,GAAG,OAAQE,GAEnBN,EAAKI,GAAG,SAAUsB,IAChBD,QAAQE,eAAe,OAAQrB,GAC/BN,EAAK4B,mBAAmB,SACxB7B,EAAO2B,EAAM,IAEf1B,EAAKI,GAAG,SAAS,CAACyB,EAAqBC,KACrCL,QAAQE,eAAe,OAAQrB,QACdyB,IAAb/B,EAAKY,IACPb,EAAO,IAAIiC,MAAM,wBAEjBlC,EAAQ,CACNc,IAAKZ,EAAKY,IACVV,SACAC,SACA8B,OAAQJ,EACRC,UAEJ,GAIJ,CAFE,MAAOJ,GACP3B,EAAO2B,EACT,IAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/shared-lib-node",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "license": "Apache-2.0",
5
5
  "author": "WillBooster Inc.",
6
6
  "sideEffects": false,