@willbooster/shared-lib-node 6.1.14 → 6.1.16

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.map CHANGED
@@ -1 +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\n/**\n * Represents a file system entry with name and parent path information.\n */\ntype NodeJsDirentLike = {\n /** The name of the file or directory */\n name: string;\n /** The absolute path to the parent directory */\n parentPath: string;\n};\n\n/**\n * Asynchronously glob for files and directories.\n * @param pattern - The glob pattern to match files and directories\n * @param options - Configuration options for globbing\n * @param options.cwd - The working directory to start globbing from\n * @param options.excludes - Regular expressions to exclude from the results\n * @param options.onlyFiles - If true, only return files (not directories)\n * @returns An async iterator of matching files and directories\n */\nexport async function* glob(\n pattern: string,\n options: { cwd?: string; excludes?: RegExp[]; onlyFiles: boolean }\n): NodeJS.AsyncIterator<NodeJsDirentLike> {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n // Use require & String to avoid loading bun on Next.js\n // eslint-disable-next-line @typescript-eslint/no-require-imports,unicorn/prefer-module\n const bun = require(String('bun'));\n const bunGlob = new bun.Glob(pattern) as Glob;\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, {\n ...options,\n exclude: options.excludes?.length ? (dirent) => isExcluded(dirent, options.excludes) : undefined,\n withFileTypes: true,\n })) {\n if (options.onlyFiles && !dirent.isFile()) continue;\n // We need double-check here because files are ignored by `exclude` option.\n if (dirent.isFile() && isExcluded(dirent, options.excludes)) continue;\n\n yield dirent;\n }\n }\n}\n\n/**\n * Synchronously glob for files and directories.\n * @param pattern - The glob pattern to match files and directories\n * @param options - Configuration options for globbing\n * @param options.cwd - The working directory to start globbing from\n * @param options.excludes - Regular expressions to exclude from the results\n * @param options.onlyFiles - If true, only return files (not directories)\n * @returns An array of matching files and directories\n */\nexport function globSync(\n pattern: string,\n options: { cwd?: string; excludes?: RegExp[]; onlyFiles: boolean }\n): NodeJsDirentLike[] {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n // Use require & String to avoid loading bun on Next.js\n // eslint-disable-next-line @typescript-eslint/no-require-imports,unicorn/prefer-module\n const bun = require(String('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 (\n fs\n .globSync(pattern, {\n ...options,\n exclude: options.excludes ? (dirent) => isExcluded(dirent, options.excludes) : undefined,\n withFileTypes: true,\n })\n // We need double-check here because files are ignored by `exclude` option.\n .filter(\n (dirent) =>\n !(options.onlyFiles && !dirent.isFile()) && !(dirent.isFile() && isExcluded(dirent, options.excludes))\n )\n );\n }\n}\n\nfunction isExcluded(dirent: NodeJsDirentLike, excludes?: RegExp[]): boolean {\n if (!excludes) return false;\n\n const targetPath = path.join(dirent.parentPath, dirent.name).replaceAll('\\\\', '/');\n return excludes.some((pattern) => pattern.test(targetPath));\n}\n"],"names":["isExcluded","dirent","excludes","targetPath","path","join","parentPath","name","replaceAll","some","pattern","test","async","options","process","versions","bun","bunGlob","require","String","Glob","direntPath","scan","cwd","onlyFiles","parsedDirentPath","parse","base","resolve","dir","fs","promises","glob","exclude","length","undefined","withFileTypes","isFile","dirents","scanSync","push","globSync","filter"],"mappings":"6DA2GA,SAASA,EAAWC,EAA0BC,GAC5C,IAAKA,EAAU,OAAO,EAEtB,MAAMC,EAAaC,EAAKC,KAAKJ,EAAOK,WAAYL,EAAOM,MAAMC,WAAW,KAAM,KAC9E,OAAON,EAASO,MAAMC,GAAYA,EAAQC,KAAKR,IACjD,cAxFOS,gBACLF,EACAG,GAGA,GAAIC,QAAQC,SAASC,IAAK,CAGxB,MACMC,EAAU,IADJC,QAAQC,OAAO,QACHC,MAAKV,GAC7B,UAAW,MAAMW,KAAcJ,EAAQK,KAAK,CAAEC,IAAKV,EAAQU,IAAKC,UAAWX,EAAQW,YAAc,CAC/F,MAAMC,EAAmBrB,EAAKsB,MAAML,GAC9BpB,EAAS,CACbM,KAAMkB,EAAiBE,KACvBrB,WAAYF,EAAKwB,QAAQf,EAAQU,KAAO,IAAKE,EAAiBI,MAE5D7B,EAAWC,EAAQY,EAAQX,kBAEzBD,EACR,CACF,MACE,UAAW,MAAMA,KAAU6B,EAAGC,SAASC,KAAKtB,EAAS,IAChDG,EACHoB,QAASpB,EAAQX,UAAUgC,OAAUjC,GAAWD,EAAWC,EAAQY,EAAQX,eAAYiC,EACvFC,eAAe,IAEXvB,EAAQW,YAAcvB,EAAOoC,UAE7BpC,EAAOoC,UAAYrC,EAAWC,EAAQY,EAAQX,kBAE5CD,EAGZ,mBAWO,SACLS,EACAG,GAGA,GAAIC,QAAQC,SAASC,IAAK,CAGxB,MACMC,EAAU,IADJC,QAAQC,OAAO,QACHC,MAAKV,GACvB4B,EAA8B,GACpC,IAAK,MAAMjB,KAAcJ,EAAQsB,SAAS,CAAEhB,IAAKV,EAAQU,IAAKC,UAAWX,EAAQW,YAAc,CAC7F,MAAMC,EAAmBrB,EAAKsB,MAAML,GAC9BpB,EAAS,CACbM,KAAMkB,EAAiBE,KACvBrB,WAAYF,EAAKwB,QAAQf,EAAQU,KAAO,IAAKE,EAAiBI,MAE5D7B,EAAWC,EAAQY,EAAQX,WAE/BoC,EAAQE,KAAKvC,EACf,CACA,OAAOqC,CACT,CACE,OACER,EACGW,SAAS/B,EAAS,IACdG,EACHoB,QAASpB,EAAQX,SAAYD,GAAWD,EAAWC,EAAQY,EAAQX,eAAYiC,EAC/EC,eAAe,IAGhBM,QACEzC,KACGY,EAAQW,YAAcvB,EAAOoC,UAAepC,EAAOoC,UAAYrC,EAAWC,EAAQY,EAAQX,YAIxG"}
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\n/**\n * Represents a file system entry with name and parent path information.\n */\ntype NodeJsDirentLike = {\n /** The name of the file or directory */\n name: string;\n /** The absolute path to the parent directory */\n parentPath: string;\n};\n\n/**\n * Asynchronously glob for files and directories.\n * @param pattern - The glob pattern to match files and directories\n * @param options - Configuration options for globbing\n * @param options.cwd - The working directory to start globbing from\n * @param options.excludes - Regular expressions to exclude from the results\n * @param options.onlyFiles - If true, only return files (not directories)\n * @returns An async iterator of matching files and directories\n */\nexport async function* glob(\n pattern: string,\n options: { cwd?: string; excludes?: RegExp[]; onlyFiles: boolean }\n): NodeJS.AsyncIterator<NodeJsDirentLike> {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n // Use require & String to avoid loading bun on Next.js\n // eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-unsafe-assignment,unicorn/prefer-module\n const bun = require(String('bun'));\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n const bunGlob = new bun.Glob(pattern) as Glob;\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, {\n ...options,\n exclude: options.excludes?.length ? (dirent) => isExcluded(dirent, options.excludes) : undefined,\n withFileTypes: true,\n })) {\n if (options.onlyFiles && !dirent.isFile()) continue;\n // We need double-check here because files are ignored by `exclude` option.\n if (dirent.isFile() && isExcluded(dirent, options.excludes)) continue;\n\n yield dirent;\n }\n }\n}\n\n/**\n * Synchronously glob for files and directories.\n * @param pattern - The glob pattern to match files and directories\n * @param options - Configuration options for globbing\n * @param options.cwd - The working directory to start globbing from\n * @param options.excludes - Regular expressions to exclude from the results\n * @param options.onlyFiles - If true, only return files (not directories)\n * @returns An array of matching files and directories\n */\nexport function globSync(\n pattern: string,\n options: { cwd?: string; excludes?: RegExp[]; onlyFiles: boolean }\n): NodeJsDirentLike[] {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n // Use require & String to avoid loading bun on Next.js\n // eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-unsafe-assignment,unicorn/prefer-module\n const bun = require(String('bun'));\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\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 (\n fs\n .globSync(pattern, {\n ...options,\n exclude: options.excludes ? (dirent) => isExcluded(dirent, options.excludes) : undefined,\n withFileTypes: true,\n })\n // We need double-check here because files are ignored by `exclude` option.\n .filter(\n (dirent) =>\n !(options.onlyFiles && !dirent.isFile()) && !(dirent.isFile() && isExcluded(dirent, options.excludes))\n )\n );\n }\n}\n\nfunction isExcluded(dirent: NodeJsDirentLike, excludes?: RegExp[]): boolean {\n if (!excludes) return false;\n\n const targetPath = path.join(dirent.parentPath, dirent.name).replaceAll('\\\\', '/');\n return excludes.some((pattern) => pattern.test(targetPath));\n}\n"],"names":["isExcluded","dirent","excludes","targetPath","path","join","parentPath","name","replaceAll","some","pattern","test","async","options","process","versions","bun","bunGlob","require","String","Glob","direntPath","scan","cwd","onlyFiles","parsedDirentPath","parse","base","resolve","dir","fs","promises","glob","exclude","length","undefined","withFileTypes","isFile","dirents","scanSync","push","globSync","filter"],"mappings":"6DA6GA,SAASA,EAAWC,EAA0BC,GAC5C,IAAKA,EAAU,OAAO,EAEtB,MAAMC,EAAaC,EAAKC,KAAKJ,EAAOK,WAAYL,EAAOM,MAAMC,WAAW,KAAM,KAC9E,OAAON,EAASO,MAAMC,GAAYA,EAAQC,KAAKR,IACjD,cA1FOS,gBACLF,EACAG,GAGA,GAAIC,QAAQC,SAASC,IAAK,CAGxB,MAEMC,EAAU,IAFJC,QAAQC,OAAO,QAEHC,MAAKV,GAC7B,UAAW,MAAMW,KAAcJ,EAAQK,KAAK,CAAEC,IAAKV,EAAQU,IAAKC,UAAWX,EAAQW,YAAc,CAC/F,MAAMC,EAAmBrB,EAAKsB,MAAML,GAC9BpB,EAAS,CACbM,KAAMkB,EAAiBE,KACvBrB,WAAYF,EAAKwB,QAAQf,EAAQU,KAAO,IAAKE,EAAiBI,MAE5D7B,EAAWC,EAAQY,EAAQX,kBAEzBD,EACR,CACF,MACE,UAAW,MAAMA,KAAU6B,EAAGC,SAASC,KAAKtB,EAAS,IAChDG,EACHoB,QAASpB,EAAQX,UAAUgC,OAAUjC,GAAWD,EAAWC,EAAQY,EAAQX,eAAYiC,EACvFC,eAAe,IAEXvB,EAAQW,YAAcvB,EAAOoC,UAE7BpC,EAAOoC,UAAYrC,EAAWC,EAAQY,EAAQX,kBAE5CD,EAGZ,mBAWO,SACLS,EACAG,GAGA,GAAIC,QAAQC,SAASC,IAAK,CAGxB,MAEMC,EAAU,IAFJC,QAAQC,OAAO,QAEHC,MAAKV,GACvB4B,EAA8B,GACpC,IAAK,MAAMjB,KAAcJ,EAAQsB,SAAS,CAAEhB,IAAKV,EAAQU,IAAKC,UAAWX,EAAQW,YAAc,CAC7F,MAAMC,EAAmBrB,EAAKsB,MAAML,GAC9BpB,EAAS,CACbM,KAAMkB,EAAiBE,KACvBrB,WAAYF,EAAKwB,QAAQf,EAAQU,KAAO,IAAKE,EAAiBI,MAE5D7B,EAAWC,EAAQY,EAAQX,WAE/BoC,EAAQE,KAAKvC,EACf,CACA,OAAOqC,CACT,CACE,OACER,EACGW,SAAS/B,EAAS,IACdG,EACHoB,QAASpB,EAAQX,SAAYD,GAAWD,EAAWC,EAAQY,EAAQX,eAAYiC,EAC/EC,eAAe,IAGhBM,QACEzC,KACGY,EAAQW,YAAcvB,EAAOoC,UAAepC,EAAOoC,UAAYrC,EAAWC,EAAQY,EAAQX,YAIxG"}
package/dist/glob.js.map CHANGED
@@ -1 +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\n/**\n * Represents a file system entry with name and parent path information.\n */\ntype NodeJsDirentLike = {\n /** The name of the file or directory */\n name: string;\n /** The absolute path to the parent directory */\n parentPath: string;\n};\n\n/**\n * Asynchronously glob for files and directories.\n * @param pattern - The glob pattern to match files and directories\n * @param options - Configuration options for globbing\n * @param options.cwd - The working directory to start globbing from\n * @param options.excludes - Regular expressions to exclude from the results\n * @param options.onlyFiles - If true, only return files (not directories)\n * @returns An async iterator of matching files and directories\n */\nexport async function* glob(\n pattern: string,\n options: { cwd?: string; excludes?: RegExp[]; onlyFiles: boolean }\n): NodeJS.AsyncIterator<NodeJsDirentLike> {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n // Use require & String to avoid loading bun on Next.js\n // eslint-disable-next-line @typescript-eslint/no-require-imports,unicorn/prefer-module\n const bun = require(String('bun'));\n const bunGlob = new bun.Glob(pattern) as Glob;\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, {\n ...options,\n exclude: options.excludes?.length ? (dirent) => isExcluded(dirent, options.excludes) : undefined,\n withFileTypes: true,\n })) {\n if (options.onlyFiles && !dirent.isFile()) continue;\n // We need double-check here because files are ignored by `exclude` option.\n if (dirent.isFile() && isExcluded(dirent, options.excludes)) continue;\n\n yield dirent;\n }\n }\n}\n\n/**\n * Synchronously glob for files and directories.\n * @param pattern - The glob pattern to match files and directories\n * @param options - Configuration options for globbing\n * @param options.cwd - The working directory to start globbing from\n * @param options.excludes - Regular expressions to exclude from the results\n * @param options.onlyFiles - If true, only return files (not directories)\n * @returns An array of matching files and directories\n */\nexport function globSync(\n pattern: string,\n options: { cwd?: string; excludes?: RegExp[]; onlyFiles: boolean }\n): NodeJsDirentLike[] {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n // Use require & String to avoid loading bun on Next.js\n // eslint-disable-next-line @typescript-eslint/no-require-imports,unicorn/prefer-module\n const bun = require(String('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 (\n fs\n .globSync(pattern, {\n ...options,\n exclude: options.excludes ? (dirent) => isExcluded(dirent, options.excludes) : undefined,\n withFileTypes: true,\n })\n // We need double-check here because files are ignored by `exclude` option.\n .filter(\n (dirent) =>\n !(options.onlyFiles && !dirent.isFile()) && !(dirent.isFile() && isExcluded(dirent, options.excludes))\n )\n );\n }\n}\n\nfunction isExcluded(dirent: NodeJsDirentLike, excludes?: RegExp[]): boolean {\n if (!excludes) return false;\n\n const targetPath = path.join(dirent.parentPath, dirent.name).replaceAll('\\\\', '/');\n return excludes.some((pattern) => pattern.test(targetPath));\n}\n"],"names":["async","glob","pattern","options","process","versions","bun","bunGlob","require","String","Glob","direntPath","scan","cwd","onlyFiles","parsedDirentPath","path","parse","dirent","name","base","parentPath","resolve","dir","isExcluded","excludes","fs","promises","exclude","length","undefined","withFileTypes","isFile","globSync","dirents","scanSync","push","filter","targetPath","join","replaceAll","some","test"],"mappings":"gDAwBOA,eAAgBC,EACrBC,EACAC,GAGA,GAAIC,QAAQC,SAASC,IAAK,CAGxB,MACMC,EAAU,IADJC,QAAQC,OAAO,QACHC,MAAKR,GAC7B,UAAW,MAAMS,KAAcJ,EAAQK,KAAK,CAAEC,IAAKV,EAAQU,IAAKC,UAAWX,EAAQW,YAAc,CAC/F,MAAMC,EAAmBC,EAAKC,MAAMN,GAC9BO,EAAS,CACbC,KAAMJ,EAAiBK,KACvBC,WAAYL,EAAKM,QAAQnB,EAAQU,KAAO,IAAKE,EAAiBQ,MAE5DC,EAAWN,EAAQf,EAAQsB,kBAEzBP,EACR,CACF,MACE,UAAW,MAAMA,KAAUQ,EAAGC,SAAS1B,KAAKC,EAAS,IAChDC,EACHyB,QAASzB,EAAQsB,UAAUI,OAAUX,GAAWM,EAAWN,EAAQf,EAAQsB,eAAYK,EACvFC,eAAe,IAEX5B,EAAQW,YAAcI,EAAOc,UAE7Bd,EAAOc,UAAYR,EAAWN,EAAQf,EAAQsB,kBAE5CP,EAGZ,CAWO,SAASe,EACd/B,EACAC,GAGA,GAAIC,QAAQC,SAASC,IAAK,CAGxB,MACMC,EAAU,IADJC,QAAQC,OAAO,QACHC,MAAKR,GACvBgC,EAA8B,GACpC,IAAK,MAAMvB,KAAcJ,EAAQ4B,SAAS,CAAEtB,IAAKV,EAAQU,IAAKC,UAAWX,EAAQW,YAAc,CAC7F,MAAMC,EAAmBC,EAAKC,MAAMN,GAC9BO,EAAS,CACbC,KAAMJ,EAAiBK,KACvBC,WAAYL,EAAKM,QAAQnB,EAAQU,KAAO,IAAKE,EAAiBQ,MAE5DC,EAAWN,EAAQf,EAAQsB,WAE/BS,EAAQE,KAAKlB,EACf,CACA,OAAOgB,CACT,CACE,OACER,EACGO,SAAS/B,EAAS,IACdC,EACHyB,QAASzB,EAAQsB,SAAYP,GAAWM,EAAWN,EAAQf,EAAQsB,eAAYK,EAC/EC,eAAe,IAGhBM,QACEnB,KACGf,EAAQW,YAAcI,EAAOc,UAAed,EAAOc,UAAYR,EAAWN,EAAQf,EAAQsB,YAIxG,CAEA,SAASD,EAAWN,EAA0BO,GAC5C,IAAKA,EAAU,OAAO,EAEtB,MAAMa,EAAatB,EAAKuB,KAAKrB,EAAOG,WAAYH,EAAOC,MAAMqB,WAAW,KAAM,KAC9E,OAAOf,EAASgB,MAAMvC,GAAYA,EAAQwC,KAAKJ,IACjD"}
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\n/**\n * Represents a file system entry with name and parent path information.\n */\ntype NodeJsDirentLike = {\n /** The name of the file or directory */\n name: string;\n /** The absolute path to the parent directory */\n parentPath: string;\n};\n\n/**\n * Asynchronously glob for files and directories.\n * @param pattern - The glob pattern to match files and directories\n * @param options - Configuration options for globbing\n * @param options.cwd - The working directory to start globbing from\n * @param options.excludes - Regular expressions to exclude from the results\n * @param options.onlyFiles - If true, only return files (not directories)\n * @returns An async iterator of matching files and directories\n */\nexport async function* glob(\n pattern: string,\n options: { cwd?: string; excludes?: RegExp[]; onlyFiles: boolean }\n): NodeJS.AsyncIterator<NodeJsDirentLike> {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n // Use require & String to avoid loading bun on Next.js\n // eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-unsafe-assignment,unicorn/prefer-module\n const bun = require(String('bun'));\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n const bunGlob = new bun.Glob(pattern) as Glob;\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, {\n ...options,\n exclude: options.excludes?.length ? (dirent) => isExcluded(dirent, options.excludes) : undefined,\n withFileTypes: true,\n })) {\n if (options.onlyFiles && !dirent.isFile()) continue;\n // We need double-check here because files are ignored by `exclude` option.\n if (dirent.isFile() && isExcluded(dirent, options.excludes)) continue;\n\n yield dirent;\n }\n }\n}\n\n/**\n * Synchronously glob for files and directories.\n * @param pattern - The glob pattern to match files and directories\n * @param options - Configuration options for globbing\n * @param options.cwd - The working directory to start globbing from\n * @param options.excludes - Regular expressions to exclude from the results\n * @param options.onlyFiles - If true, only return files (not directories)\n * @returns An array of matching files and directories\n */\nexport function globSync(\n pattern: string,\n options: { cwd?: string; excludes?: RegExp[]; onlyFiles: boolean }\n): NodeJsDirentLike[] {\n // cf. https://bun.sh/guides/util/detect-bun\n if (process.versions.bun) {\n // Use require & String to avoid loading bun on Next.js\n // eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-unsafe-assignment,unicorn/prefer-module\n const bun = require(String('bun'));\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\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 (\n fs\n .globSync(pattern, {\n ...options,\n exclude: options.excludes ? (dirent) => isExcluded(dirent, options.excludes) : undefined,\n withFileTypes: true,\n })\n // We need double-check here because files are ignored by `exclude` option.\n .filter(\n (dirent) =>\n !(options.onlyFiles && !dirent.isFile()) && !(dirent.isFile() && isExcluded(dirent, options.excludes))\n )\n );\n }\n}\n\nfunction isExcluded(dirent: NodeJsDirentLike, excludes?: RegExp[]): boolean {\n if (!excludes) return false;\n\n const targetPath = path.join(dirent.parentPath, dirent.name).replaceAll('\\\\', '/');\n return excludes.some((pattern) => pattern.test(targetPath));\n}\n"],"names":["async","glob","pattern","options","process","versions","bun","bunGlob","require","String","Glob","direntPath","scan","cwd","onlyFiles","parsedDirentPath","path","parse","dirent","name","base","parentPath","resolve","dir","isExcluded","excludes","fs","promises","exclude","length","undefined","withFileTypes","isFile","globSync","dirents","scanSync","push","filter","targetPath","join","replaceAll","some","test"],"mappings":"gDAwBOA,eAAgBC,EACrBC,EACAC,GAGA,GAAIC,QAAQC,SAASC,IAAK,CAGxB,MAEMC,EAAU,IAFJC,QAAQC,OAAO,QAEHC,MAAKR,GAC7B,UAAW,MAAMS,KAAcJ,EAAQK,KAAK,CAAEC,IAAKV,EAAQU,IAAKC,UAAWX,EAAQW,YAAc,CAC/F,MAAMC,EAAmBC,EAAKC,MAAMN,GAC9BO,EAAS,CACbC,KAAMJ,EAAiBK,KACvBC,WAAYL,EAAKM,QAAQnB,EAAQU,KAAO,IAAKE,EAAiBQ,MAE5DC,EAAWN,EAAQf,EAAQsB,kBAEzBP,EACR,CACF,MACE,UAAW,MAAMA,KAAUQ,EAAGC,SAAS1B,KAAKC,EAAS,IAChDC,EACHyB,QAASzB,EAAQsB,UAAUI,OAAUX,GAAWM,EAAWN,EAAQf,EAAQsB,eAAYK,EACvFC,eAAe,IAEX5B,EAAQW,YAAcI,EAAOc,UAE7Bd,EAAOc,UAAYR,EAAWN,EAAQf,EAAQsB,kBAE5CP,EAGZ,CAWO,SAASe,EACd/B,EACAC,GAGA,GAAIC,QAAQC,SAASC,IAAK,CAGxB,MAEMC,EAAU,IAFJC,QAAQC,OAAO,QAEHC,MAAKR,GACvBgC,EAA8B,GACpC,IAAK,MAAMvB,KAAcJ,EAAQ4B,SAAS,CAAEtB,IAAKV,EAAQU,IAAKC,UAAWX,EAAQW,YAAc,CAC7F,MAAMC,EAAmBC,EAAKC,MAAMN,GAC9BO,EAAS,CACbC,KAAMJ,EAAiBK,KACvBC,WAAYL,EAAKM,QAAQnB,EAAQU,KAAO,IAAKE,EAAiBQ,MAE5DC,EAAWN,EAAQf,EAAQsB,WAE/BS,EAAQE,KAAKlB,EACf,CACA,OAAOgB,CACT,CACE,OACER,EACGO,SAAS/B,EAAS,IACdC,EACHyB,QAASzB,EAAQsB,SAAYP,GAAWM,EAAWN,EAAQf,EAAQsB,eAAYK,EAC/EC,eAAe,IAGhBM,QACEnB,KACGf,EAAQW,YAAcI,EAAOc,UAAed,EAAOc,UAAYR,EAAWN,EAAQf,EAAQsB,YAIxG,CAEA,SAASD,EAAWN,EAA0BO,GAC5C,IAAKA,EAAU,OAAO,EAEtB,MAAMa,EAAatB,EAAKuB,KAAKrB,EAAOG,WAAYH,EAAOC,MAAMqB,WAAW,KAAM,KAC9E,OAAOf,EAASgB,MAAMvC,GAAYA,EAAQwC,KAAKJ,IACjD"}
@@ -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\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"}
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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\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,GAEPlB,EAAOkB,EACT,IAEJ"}
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\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"}
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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\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,GAEPlB,EAAOkB,EACT,IAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/shared-lib-node",
3
- "version": "6.1.14",
3
+ "version": "6.1.16",
4
4
  "license": "Apache-2.0",
5
5
  "author": "WillBooster Inc.",
6
6
  "sideEffects": false,
@@ -26,9 +26,10 @@
26
26
  ],
27
27
  "scripts": {
28
28
  "build": "build-ts lib",
29
+ "check-all": "yarn cleanup && yarn typecheck && yarn test",
29
30
  "cleanup": "yarn format && yarn lint-fix",
30
31
  "format": "sort-package-json && yarn prettify",
31
- "lint": "eslint --color \"./{scripts,src,tests}/**/*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}\"",
32
+ "lint": "eslint --color",
32
33
  "lint-fix": "yarn lint --fix",
33
34
  "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
35
  "test": "vitest tests/",
@@ -40,27 +41,29 @@
40
41
  "tree-kill": "1.2.2"
41
42
  },
42
43
  "devDependencies": {
43
- "@types/bun": "1.2.9",
44
+ "@types/bun": "1.2.10",
44
45
  "@types/eslint": "8.56.10",
45
46
  "@types/micromatch": "4.0.9",
46
47
  "@types/node": "22.14.1",
47
- "@typescript-eslint/eslint-plugin": "8.29.1",
48
- "@typescript-eslint/parser": "8.29.1",
49
- "@willbooster/eslint-config-ts": "10.6.1",
50
- "@willbooster/prettier-config": "9.1.3",
51
- "build-ts": "13.1.37",
52
- "eslint": "8.57.0",
48
+ "@willbooster/eslint-config-ts": "11.2.0",
49
+ "@willbooster/prettier-config": "10.0.0",
50
+ "build-ts": "13.1.39",
51
+ "eslint": "9.25.0",
52
+ "eslint-config-flat-gitignore": "2.1.0",
53
53
  "eslint-config-prettier": "10.1.2",
54
- "eslint-import-resolver-typescript": "3.10.0",
55
- "eslint-plugin-import": "2.31.0",
54
+ "eslint-import-resolver-typescript": "4.3.2",
55
+ "eslint-plugin-import-x": "4.10.5",
56
56
  "eslint-plugin-sort-class-members": "1.21.0",
57
57
  "eslint-plugin-sort-destructure-keys": "2.0.0",
58
- "eslint-plugin-unicorn": "56.0.1",
58
+ "eslint-plugin-unicorn": "58.0.0",
59
+ "eslint-plugin-unused-imports": "4.1.4",
60
+ "globals": "16.0.0",
59
61
  "lint-staged": "15.5.1",
60
62
  "micromatch": "4.0.8",
61
63
  "prettier": "3.5.3",
62
- "sort-package-json": "2.15.1",
64
+ "sort-package-json": "3.0.0",
63
65
  "typescript": "5.8.3",
66
+ "typescript-eslint": "8.30.1",
64
67
  "vitest": "3.1.1"
65
68
  },
66
69
  "publishConfig": {