@willbooster/shared-lib-node 6.0.5 → 6.1.0
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/glob.cjs +2 -0
- package/dist/glob.cjs.map +1 -0
- package/dist/glob.d.ts +15 -0
- package/dist/glob.js +2 -0
- package/dist/glob.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/spawn.cjs.map +1 -1
- package/dist/spawn.d.ts +32 -0
- package/dist/spawn.js.map +1 -1
- package/package.json +11 -10
package/dist/glob.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("node:fs"),s=require("node:path");function n(e,n){return n?.some((n=>{const o=n.replaceAll("\\","/");return s.join(e.parentPath,e.name).replaceAll("\\","/").includes(o)}))}exports.glob=async function*(o,l){if(process.versions.bun){const e=new((await import("bun")).Glob)(o);for await(const o of e.scan({cwd:l.cwd,onlyFiles:l.onlyFiles})){const e=s.parse(o),r={name:e.base,parentPath:s.resolve(l.cwd??".",e.dir)};n(r,l.excludes)||(yield r)}}else for await(const s of e.promises.glob(o,{...l,withFileTypes:!0}))l.onlyFiles&&!s.isFile()||n(s,l.excludes)||(yield s)},exports.globSync=function(o,l){if(process.versions.bun){const e=new(require("bun").Glob)(o),r=[];for(const o of e.scanSync({cwd:l.cwd,onlyFiles:l.onlyFiles})){const e=s.parse(o),i={name:e.base,parentPath:s.resolve(l.cwd??".",e.dir)};n(i,l.excludes)||r.push(i)}return r}return e.globSync(o,{...l,withFileTypes:!0}).filter((e=>(!l.onlyFiles||e.isFile())&&!n(e,l.excludes)))};
|
|
2
|
+
//# sourceMappingURL=glob.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.cjs","sources":["../src/glob.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport type { Glob } from 'bun';\n\ntype NodeJsDirentLike = {\n name: string;\n parentPath: string;\n};\n\nexport async function* glob(\n pattern: string,\n options: { cwd?: string; excludes?: string[]; onlyFiles: boolean }\n): NodeJS.AsyncIterator<NodeJsDirentLike> {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n const bun = await import('bun');\n const bunGlob = new bun.Glob(pattern);\n for await (const direntPath of bunGlob.scan({ cwd: options.cwd, onlyFiles: options.onlyFiles })) {\n const parsedDirentPath = path.parse(direntPath);\n const dirent = {\n name: parsedDirentPath.base,\n parentPath: path.resolve(options.cwd ?? '.', parsedDirentPath.dir),\n };\n if (isExcluded(dirent, options.excludes)) continue;\n\n yield dirent;\n }\n } else {\n for await (const dirent of fs.promises.glob(pattern, { ...options, withFileTypes: true })) {\n if (options.onlyFiles && !dirent.isFile()) continue;\n if (isExcluded(dirent, options.excludes)) continue;\n\n yield dirent;\n }\n }\n}\n\nexport function globSync(\n pattern: string,\n options: { cwd?: string; excludes?: string[]; onlyFiles: boolean }\n): NodeJsDirentLike[] {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n // eslint-disable-next-line @typescript-eslint/no-require-imports,unicorn/prefer-module\n const bun = require('bun');\n const bunGlob = new bun.Glob(pattern) as Glob;\n const dirents: NodeJsDirentLike[] = [];\n for (const direntPath of bunGlob.scanSync({ cwd: options.cwd, onlyFiles: options.onlyFiles })) {\n const parsedDirentPath = path.parse(direntPath);\n const dirent = {\n name: parsedDirentPath.base,\n parentPath: path.resolve(options.cwd ?? '.', parsedDirentPath.dir),\n };\n if (isExcluded(dirent, options.excludes)) continue;\n\n dirents.push(dirent);\n }\n return dirents;\n } else {\n return fs\n .globSync(pattern, { ...options, withFileTypes: true })\n .filter((dirent) => (!options.onlyFiles || dirent.isFile()) && !isExcluded(dirent, options.excludes));\n }\n}\n\nfunction isExcluded(dirent: NodeJsDirentLike, excludes?: string[]): boolean | undefined {\n return excludes?.some((exclude) => {\n const pattern = exclude.replaceAll('\\\\', '/');\n return path.join(dirent.parentPath, dirent.name).replaceAll('\\\\', '/').includes(pattern);\n });\n}\n"],"names":["isExcluded","dirent","excludes","some","exclude","pattern","replaceAll","path","join","parentPath","name","includes","async","options","process","versions","bun","bunGlob","import","Glob","direntPath","scan","cwd","onlyFiles","parsedDirentPath","parse","base","resolve","dir","fs","promises","glob","withFileTypes","isFile","require","dirents","scanSync","push","globSync","filter"],"mappings":"6DAkEA,SAASA,EAAWC,EAA0BC,GAC5C,OAAOA,GAAUC,MAAMC,IACrB,MAAMC,EAAUD,EAAQE,WAAW,KAAM,KACzC,OAAOC,EAAKC,KAAKP,EAAOQ,WAAYR,EAAOS,MAAMJ,WAAW,KAAM,KAAKK,SAASN,EAAQ,GAE5F,cA7DOO,gBACLP,EACAQ,GAGA,GAAIC,QAAQC,SAASC,IAAK,CACxB,MACMC,EAAU,WADEC,OAAO,QACDC,MAAKd,GAC7B,UAAW,MAAMe,KAAcH,EAAQI,KAAK,CAAEC,IAAKT,EAAQS,IAAKC,UAAWV,EAAQU,YAAc,CAC/F,MAAMC,EAAmBjB,EAAKkB,MAAML,GAC9BnB,EAAS,CACbS,KAAMc,EAAiBE,KACvBjB,WAAYF,EAAKoB,QAAQd,EAAQS,KAAO,IAAKE,EAAiBI,MAE5D5B,EAAWC,EAAQY,EAAQX,kBAEzBD,EACR,CACF,MACE,UAAW,MAAMA,KAAU4B,EAAGC,SAASC,KAAK1B,EAAS,IAAKQ,EAASmB,eAAe,IAC5EnB,EAAQU,YAActB,EAAOgC,UAC7BjC,EAAWC,EAAQY,EAAQX,kBAEzBD,EAGZ,mBAEO,SACLI,EACAQ,GAGA,GAAIC,QAAQC,SAASC,IAAK,CAExB,MACMC,EAAU,IADJiB,QAAQ,OACIf,MAAKd,GACvB8B,EAA8B,GACpC,IAAK,MAAMf,KAAcH,EAAQmB,SAAS,CAAEd,IAAKT,EAAQS,IAAKC,UAAWV,EAAQU,YAAc,CAC7F,MAAMC,EAAmBjB,EAAKkB,MAAML,GAC9BnB,EAAS,CACbS,KAAMc,EAAiBE,KACvBjB,WAAYF,EAAKoB,QAAQd,EAAQS,KAAO,IAAKE,EAAiBI,MAE5D5B,EAAWC,EAAQY,EAAQX,WAE/BiC,EAAQE,KAAKpC,EACf,CACA,OAAOkC,CACT,CACE,OAAON,EACJS,SAASjC,EAAS,IAAKQ,EAASmB,eAAe,IAC/CO,QAAQtC,KAAaY,EAAQU,WAAatB,EAAOgC,YAAcjC,EAAWC,EAAQY,EAAQX,WAEjG"}
|
package/dist/glob.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type NodeJsDirentLike = {
|
|
2
|
+
name: string;
|
|
3
|
+
parentPath: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function glob(pattern: string, options: {
|
|
6
|
+
cwd?: string;
|
|
7
|
+
excludes?: string[];
|
|
8
|
+
onlyFiles: boolean;
|
|
9
|
+
}): NodeJS.AsyncIterator<NodeJsDirentLike>;
|
|
10
|
+
export declare function globSync(pattern: string, options: {
|
|
11
|
+
cwd?: string;
|
|
12
|
+
excludes?: string[];
|
|
13
|
+
onlyFiles: boolean;
|
|
14
|
+
}): NodeJsDirentLike[];
|
|
15
|
+
export {};
|
package/dist/glob.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"node:fs";import n from"node:path";async function*s(s,o){if(process.versions.bun){const e=new((await import("bun")).Glob)(s);for await(const s of e.scan({cwd:o.cwd,onlyFiles:o.onlyFiles})){const e=n.parse(s),i={name:e.base,parentPath:n.resolve(o.cwd??".",e.dir)};l(i,o.excludes)||(yield i)}}else for await(const n of e.promises.glob(s,{...o,withFileTypes:!0}))o.onlyFiles&&!n.isFile()||l(n,o.excludes)||(yield n)}function o(s,o){if(process.versions.bun){const e=new(require("bun").Glob)(s),i=[];for(const s of e.scanSync({cwd:o.cwd,onlyFiles:o.onlyFiles})){const e=n.parse(s),r={name:e.base,parentPath:n.resolve(o.cwd??".",e.dir)};l(r,o.excludes)||i.push(r)}return i}return e.globSync(s,{...o,withFileTypes:!0}).filter((e=>(!o.onlyFiles||e.isFile())&&!l(e,o.excludes)))}function l(e,s){return s?.some((s=>{const o=s.replaceAll("\\","/");return n.join(e.parentPath,e.name).replaceAll("\\","/").includes(o)}))}export{s as glob,o as globSync};
|
|
2
|
+
//# sourceMappingURL=glob.js.map
|
package/dist/glob.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.js","sources":["../src/glob.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport type { Glob } from 'bun';\n\ntype NodeJsDirentLike = {\n name: string;\n parentPath: string;\n};\n\nexport async function* glob(\n pattern: string,\n options: { cwd?: string; excludes?: string[]; onlyFiles: boolean }\n): NodeJS.AsyncIterator<NodeJsDirentLike> {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n const bun = await import('bun');\n const bunGlob = new bun.Glob(pattern);\n for await (const direntPath of bunGlob.scan({ cwd: options.cwd, onlyFiles: options.onlyFiles })) {\n const parsedDirentPath = path.parse(direntPath);\n const dirent = {\n name: parsedDirentPath.base,\n parentPath: path.resolve(options.cwd ?? '.', parsedDirentPath.dir),\n };\n if (isExcluded(dirent, options.excludes)) continue;\n\n yield dirent;\n }\n } else {\n for await (const dirent of fs.promises.glob(pattern, { ...options, withFileTypes: true })) {\n if (options.onlyFiles && !dirent.isFile()) continue;\n if (isExcluded(dirent, options.excludes)) continue;\n\n yield dirent;\n }\n }\n}\n\nexport function globSync(\n pattern: string,\n options: { cwd?: string; excludes?: string[]; onlyFiles: boolean }\n): NodeJsDirentLike[] {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n // eslint-disable-next-line @typescript-eslint/no-require-imports,unicorn/prefer-module\n const bun = require('bun');\n const bunGlob = new bun.Glob(pattern) as Glob;\n const dirents: NodeJsDirentLike[] = [];\n for (const direntPath of bunGlob.scanSync({ cwd: options.cwd, onlyFiles: options.onlyFiles })) {\n const parsedDirentPath = path.parse(direntPath);\n const dirent = {\n name: parsedDirentPath.base,\n parentPath: path.resolve(options.cwd ?? '.', parsedDirentPath.dir),\n };\n if (isExcluded(dirent, options.excludes)) continue;\n\n dirents.push(dirent);\n }\n return dirents;\n } else {\n return fs\n .globSync(pattern, { ...options, withFileTypes: true })\n .filter((dirent) => (!options.onlyFiles || dirent.isFile()) && !isExcluded(dirent, options.excludes));\n }\n}\n\nfunction isExcluded(dirent: NodeJsDirentLike, excludes?: string[]): boolean | undefined {\n return excludes?.some((exclude) => {\n const pattern = exclude.replaceAll('\\\\', '/');\n return path.join(dirent.parentPath, dirent.name).replaceAll('\\\\', '/').includes(pattern);\n });\n}\n"],"names":["async","glob","pattern","options","process","versions","bun","bunGlob","import","Glob","direntPath","scan","cwd","onlyFiles","parsedDirentPath","path","parse","dirent","name","base","parentPath","resolve","dir","isExcluded","excludes","fs","promises","withFileTypes","isFile","globSync","require","dirents","scanSync","push","filter","some","exclude","replaceAll","join","includes"],"mappings":"gDAUOA,eAAgBC,EACrBC,EACAC,GAGA,GAAIC,QAAQC,SAASC,IAAK,CACxB,MACMC,EAAU,WADEC,OAAO,QACDC,MAAKP,GAC7B,UAAW,MAAMQ,KAAcH,EAAQI,KAAK,CAAEC,IAAKT,EAAQS,IAAKC,UAAWV,EAAQU,YAAc,CAC/F,MAAMC,EAAmBC,EAAKC,MAAMN,GAC9BO,EAAS,CACbC,KAAMJ,EAAiBK,KACvBC,WAAYL,EAAKM,QAAQlB,EAAQS,KAAO,IAAKE,EAAiBQ,MAE5DC,EAAWN,EAAQd,EAAQqB,kBAEzBP,EACR,CACF,MACE,UAAW,MAAMA,KAAUQ,EAAGC,SAASzB,KAAKC,EAAS,IAAKC,EAASwB,eAAe,IAC5ExB,EAAQU,YAAcI,EAAOW,UAC7BL,EAAWN,EAAQd,EAAQqB,kBAEzBP,EAGZ,CAEO,SAASY,EACd3B,EACAC,GAGA,GAAIC,QAAQC,SAASC,IAAK,CAExB,MACMC,EAAU,IADJuB,QAAQ,OACIrB,MAAKP,GACvB6B,EAA8B,GACpC,IAAK,MAAMrB,KAAcH,EAAQyB,SAAS,CAAEpB,IAAKT,EAAQS,IAAKC,UAAWV,EAAQU,YAAc,CAC7F,MAAMC,EAAmBC,EAAKC,MAAMN,GAC9BO,EAAS,CACbC,KAAMJ,EAAiBK,KACvBC,WAAYL,EAAKM,QAAQlB,EAAQS,KAAO,IAAKE,EAAiBQ,MAE5DC,EAAWN,EAAQd,EAAQqB,WAE/BO,EAAQE,KAAKhB,EACf,CACA,OAAOc,CACT,CACE,OAAON,EACJI,SAAS3B,EAAS,IAAKC,EAASwB,eAAe,IAC/CO,QAAQjB,KAAad,EAAQU,WAAaI,EAAOW,YAAcL,EAAWN,EAAQd,EAAQqB,WAEjG,CAEA,SAASD,EAAWN,EAA0BO,GAC5C,OAAOA,GAAUW,MAAMC,IACrB,MAAMlC,EAAUkC,EAAQC,WAAW,KAAM,KACzC,OAAOtB,EAAKuB,KAAKrB,EAAOG,WAAYH,EAAOC,MAAMmB,WAAW,KAAM,KAAKE,SAASrC,EAAQ,GAE5F"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("./env.cjs"),r=require("./exists.cjs"),s=require("./
|
|
1
|
+
"use strict";var e=require("./env.cjs"),r=require("./exists.cjs"),s=require("./glob.cjs"),n=require("./hash.cjs"),a=require("./spawn.cjs");exports.readAndApplyEnvironmentVariables=e.readAndApplyEnvironmentVariables,exports.readEnvironmentVariables=e.readEnvironmentVariables,exports.removeNpmAndYarnEnvironmentVariables=e.removeNpmAndYarnEnvironmentVariables,exports.yargsOptionsBuilderForEnv=e.yargsOptionsBuilderForEnv,exports.existsAsync=r.existsAsync,exports.glob=s.glob,exports.globSync=s.globSync,exports.calculateHashFromFiles=n.calculateHashFromFiles,exports.canSkipSeed=n.canSkipSeed,exports.updateHashFromFiles=n.updateHashFromFiles,exports.spawnAsync=a.spawnAsync;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { readEnvironmentVariables, readAndApplyEnvironmentVariables, removeNpmAndYarnEnvironmentVariables, yargsOptionsBuilderForEnv, } from './env.js';
|
|
2
2
|
export type { EnvReaderOptions } from './env.js';
|
|
3
3
|
export { existsAsync } from './exists.js';
|
|
4
|
+
export { glob, globSync } from './glob.js';
|
|
4
5
|
export { calculateHashFromFiles, canSkipSeed, updateHashFromFiles } from './hash.js';
|
|
5
6
|
export { spawnAsync } from './spawn.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{readAndApplyEnvironmentVariables,readEnvironmentVariables,removeNpmAndYarnEnvironmentVariables,yargsOptionsBuilderForEnv}from"./env.js";export{existsAsync}from"./exists.js";export{calculateHashFromFiles,canSkipSeed,updateHashFromFiles}from"./hash.js";export{spawnAsync}from"./spawn.js";
|
|
1
|
+
export{readAndApplyEnvironmentVariables,readEnvironmentVariables,removeNpmAndYarnEnvironmentVariables,yargsOptionsBuilderForEnv}from"./env.js";export{existsAsync}from"./exists.js";export{glob,globSync}from"./glob.js";export{calculateHashFromFiles,canSkipSeed,updateHashFromFiles}from"./hash.js";export{spawnAsync}from"./spawn.js";
|
|
2
2
|
//# sourceMappingURL=index.js.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';\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":"
|
|
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\n/**\n * Return type for spawnAsync function, based on SpawnSyncReturns but without output and error properties\n */\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\n/**\n * Options for spawnAsync function, extending various Node.js spawn options with additional functionality\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 to write to the spawned process's stdin */\n input?: string;\n /** If true, stderr output will be merged into stdout */\n mergeOutAndError?: boolean;\n /** If true, the spawned process will be killed when the parent process exits */\n killOnExit?: boolean;\n /** If true, enables verbose logging of process operations */\n verbose?: boolean;\n};\n\n/**\n * Spawns a child process asynchronously and returns a promise that resolves with the process results\n *\n * This function provides a Promise-based wrapper around Node.js's spawn function with additional features:\n * - Automatic encoding of stdout/stderr as UTF-8\n * - Option to merge stderr into stdout\n * - Option to automatically kill the process on parent exit\n * - Option to provide input via stdin\n * - Verbose logging capability\n *\n * @param command - The command to run\n * @param args - List of string arguments\n * @param options - Configuration options for the spawned process\n * @returns Promise that resolves with the process results including pid, stdout, stderr, status, and signal\n * @throws Will reject the promise if the process fails to spawn or encounters an error\n *\n * @example\n * ```typescript\n * const result = await spawnAsync('ls', ['-la'], { verbose: true });\n * console.log(result.stdout);\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":"2FAgEOA,eACLC,EACAC,EACAC,GAEA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAAA,MAAMP,EAASC,GAAQ,GAAIC,GAAW,IAEnDI,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
|
@@ -1,9 +1,41 @@
|
|
|
1
1
|
import type { SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, SpawnSyncReturns, StdioNull, StdioPipe } from 'node:child_process';
|
|
2
|
+
/**
|
|
3
|
+
* Return type for spawnAsync function, based on SpawnSyncReturns but without output and error properties
|
|
4
|
+
*/
|
|
2
5
|
export type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;
|
|
6
|
+
/**
|
|
7
|
+
* Options for spawnAsync function, extending various Node.js spawn options with additional functionality
|
|
8
|
+
*/
|
|
3
9
|
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) & {
|
|
10
|
+
/** Input string to write to the spawned process's stdin */
|
|
4
11
|
input?: string;
|
|
12
|
+
/** If true, stderr output will be merged into stdout */
|
|
5
13
|
mergeOutAndError?: boolean;
|
|
14
|
+
/** If true, the spawned process will be killed when the parent process exits */
|
|
6
15
|
killOnExit?: boolean;
|
|
16
|
+
/** If true, enables verbose logging of process operations */
|
|
7
17
|
verbose?: boolean;
|
|
8
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Spawns a child process asynchronously and returns a promise that resolves with the process results
|
|
21
|
+
*
|
|
22
|
+
* This function provides a Promise-based wrapper around Node.js's spawn function with additional features:
|
|
23
|
+
* - Automatic encoding of stdout/stderr as UTF-8
|
|
24
|
+
* - Option to merge stderr into stdout
|
|
25
|
+
* - Option to automatically kill the process on parent exit
|
|
26
|
+
* - Option to provide input via stdin
|
|
27
|
+
* - Verbose logging capability
|
|
28
|
+
*
|
|
29
|
+
* @param command - The command to run
|
|
30
|
+
* @param args - List of string arguments
|
|
31
|
+
* @param options - Configuration options for the spawned process
|
|
32
|
+
* @returns Promise that resolves with the process results including pid, stdout, stderr, status, and signal
|
|
33
|
+
* @throws Will reject the promise if the process fails to spawn or encounters an error
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const result = await spawnAsync('ls', ['-la'], { verbose: true });
|
|
38
|
+
* console.log(result.stdout);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
9
41
|
export declare function spawnAsync(command: string, args?: ReadonlyArray<string>, options?: SpawnAsyncOptions): Promise<SpawnAsyncReturns>;
|
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';\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":"
|
|
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\n/**\n * Return type for spawnAsync function, based on SpawnSyncReturns but without output and error properties\n */\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\n/**\n * Options for spawnAsync function, extending various Node.js spawn options with additional functionality\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 to write to the spawned process's stdin */\n input?: string;\n /** If true, stderr output will be merged into stdout */\n mergeOutAndError?: boolean;\n /** If true, the spawned process will be killed when the parent process exits */\n killOnExit?: boolean;\n /** If true, enables verbose logging of process operations */\n verbose?: boolean;\n};\n\n/**\n * Spawns a child process asynchronously and returns a promise that resolves with the process results\n *\n * This function provides a Promise-based wrapper around Node.js's spawn function with additional features:\n * - Automatic encoding of stdout/stderr as UTF-8\n * - Option to merge stderr into stdout\n * - Option to automatically kill the process on parent exit\n * - Option to provide input via stdin\n * - Verbose logging capability\n *\n * @param command - The command to run\n * @param args - List of string arguments\n * @param options - Configuration options for the spawned process\n * @returns Promise that resolves with the process results including pid, stdout, stderr, status, and signal\n * @throws Will reject the promise if the process fails to spawn or encounters an error\n *\n * @example\n * ```typescript\n * const result = await spawnAsync('ls', ['-la'], { verbose: true });\n * console.log(result.stdout);\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":"oEAgEOA,eAAeC,EACpBC,EACAC,EACAC,GAEA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IACE,MAAMC,EAAOC,EAAMP,EAASC,GAAQ,GAAIC,GAAW,IAEnDI,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": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "WillBooster Inc.",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -31,36 +31,37 @@
|
|
|
31
31
|
"lint": "eslint --color \"./{scripts,src,tests}/**/*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}\"",
|
|
32
32
|
"lint-fix": "yarn lint --fix",
|
|
33
33
|
"prettify": "prettier --cache --color --write \"**/{.*/,}*.{cjs,css,cts,htm,html,js,json,json5,jsonc,jsx,md,mjs,mts,scss,ts,tsx,vue,yaml,yml}\" \"!**/test-fixtures/**\"",
|
|
34
|
-
"test": "vitest",
|
|
34
|
+
"test": "vitest tests/",
|
|
35
35
|
"typecheck": "tsc --noEmit --Pretty"
|
|
36
36
|
},
|
|
37
37
|
"prettier": "@willbooster/prettier-config",
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@types/bun": "1.1.17",
|
|
39
40
|
"dotenv": "16.4.7",
|
|
40
41
|
"tree-kill": "1.2.2"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@types/eslint": "8.56.10",
|
|
44
45
|
"@types/micromatch": "4.0.9",
|
|
45
|
-
"@types/node": "22.10.
|
|
46
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
47
|
-
"@typescript-eslint/parser": "8.
|
|
46
|
+
"@types/node": "22.10.7",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "8.20.0",
|
|
48
|
+
"@typescript-eslint/parser": "8.20.0",
|
|
48
49
|
"@willbooster/eslint-config-ts": "10.6.1",
|
|
49
50
|
"@willbooster/prettier-config": "9.1.3",
|
|
50
|
-
"build-ts": "13.1.
|
|
51
|
+
"build-ts": "13.1.12",
|
|
51
52
|
"eslint": "8.57.0",
|
|
52
|
-
"eslint-config-prettier": "
|
|
53
|
+
"eslint-config-prettier": "10.0.1",
|
|
53
54
|
"eslint-import-resolver-typescript": "3.7.0",
|
|
54
55
|
"eslint-plugin-import": "2.31.0",
|
|
55
56
|
"eslint-plugin-sort-class-members": "1.21.0",
|
|
56
57
|
"eslint-plugin-sort-destructure-keys": "2.0.0",
|
|
57
58
|
"eslint-plugin-unicorn": "56.0.1",
|
|
58
|
-
"lint-staged": "15.
|
|
59
|
+
"lint-staged": "15.4.1",
|
|
59
60
|
"micromatch": "4.0.8",
|
|
60
61
|
"prettier": "3.4.2",
|
|
61
|
-
"sort-package-json": "2.
|
|
62
|
+
"sort-package-json": "2.14.0",
|
|
62
63
|
"typescript": "5.7.3",
|
|
63
|
-
"vitest": "
|
|
64
|
+
"vitest": "3.0.2"
|
|
64
65
|
},
|
|
65
66
|
"publishConfig": {
|
|
66
67
|
"access": "public"
|