@socketsecurity/lib 1.0.4 → 1.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/abort.js.map +2 -2
  3. package/dist/argv/parse.js.map +2 -2
  4. package/dist/arrays.d.ts +143 -0
  5. package/dist/arrays.js.map +2 -2
  6. package/dist/bin.js +1 -4
  7. package/dist/bin.js.map +2 -2
  8. package/dist/cacache.d.ts +0 -2
  9. package/dist/cacache.js +0 -1
  10. package/dist/cacache.js.map +2 -2
  11. package/dist/cache-with-ttl.js.map +2 -2
  12. package/dist/dlx.js.map +2 -2
  13. package/dist/external/@yarnpkg/extensions.d.ts +0 -1
  14. package/dist/external/cacache.d.ts +0 -7
  15. package/dist/external/debug.d.ts +0 -3
  16. package/dist/external/fast-sort.d.ts +0 -1
  17. package/dist/external/libnpmpack.d.ts +0 -1
  18. package/dist/external/make-fetch-happen.d.ts +0 -1
  19. package/dist/external/pacote.d.ts +0 -5
  20. package/dist/external/semver.d.ts +0 -1
  21. package/dist/external/validate-npm-package-name.js +1 -1
  22. package/dist/external/yargs-parser.d.ts +0 -1
  23. package/dist/external/yoctocolors-cjs.js +1 -1
  24. package/dist/external/zod.js +9 -9
  25. package/dist/fs.d.ts +595 -23
  26. package/dist/fs.js.map +2 -2
  27. package/dist/git.d.ts +488 -41
  28. package/dist/git.js.map +2 -2
  29. package/dist/github.d.ts +361 -12
  30. package/dist/github.js.map +2 -2
  31. package/dist/http-request.d.ts +463 -4
  32. package/dist/http-request.js.map +2 -2
  33. package/dist/json.d.ts +177 -4
  34. package/dist/json.js.map +2 -2
  35. package/dist/logger.d.ts +823 -70
  36. package/dist/logger.js +654 -51
  37. package/dist/logger.js.map +2 -2
  38. package/dist/objects.d.ts +386 -10
  39. package/dist/objects.js.map +2 -2
  40. package/dist/path.d.ts +270 -6
  41. package/dist/path.js.map +2 -2
  42. package/dist/promises.d.ts +432 -27
  43. package/dist/promises.js +3 -0
  44. package/dist/promises.js.map +2 -2
  45. package/dist/signal-exit.js.map +2 -2
  46. package/dist/sorts.js.map +2 -2
  47. package/dist/spawn.d.ts +242 -33
  48. package/dist/spawn.js.map +2 -2
  49. package/dist/spinner.d.ts +260 -20
  50. package/dist/spinner.js +201 -63
  51. package/dist/spinner.js.map +2 -2
  52. package/dist/stdio/clear.d.ts +130 -9
  53. package/dist/stdio/clear.js.map +2 -2
  54. package/dist/stdio/divider.d.ts +106 -10
  55. package/dist/stdio/divider.js +10 -0
  56. package/dist/stdio/divider.js.map +2 -2
  57. package/dist/stdio/footer.d.ts +70 -3
  58. package/dist/stdio/footer.js.map +2 -2
  59. package/dist/stdio/header.d.ts +93 -12
  60. package/dist/stdio/header.js.map +2 -2
  61. package/dist/stdio/mask.d.ts +82 -14
  62. package/dist/stdio/mask.js +25 -4
  63. package/dist/stdio/mask.js.map +2 -2
  64. package/dist/stdio/progress.d.ts +112 -15
  65. package/dist/stdio/progress.js +43 -3
  66. package/dist/stdio/progress.js.map +2 -2
  67. package/dist/stdio/prompts.d.ts +95 -5
  68. package/dist/stdio/prompts.js.map +2 -2
  69. package/dist/stdio/stderr.d.ts +114 -11
  70. package/dist/stdio/stderr.js.map +2 -2
  71. package/dist/stdio/stdout.d.ts +107 -11
  72. package/dist/stdio/stdout.js.map +2 -2
  73. package/dist/strings.d.ts +357 -28
  74. package/dist/strings.js.map +2 -2
  75. package/dist/suppress-warnings.js.map +2 -2
  76. package/dist/validation/json-parser.d.ts +226 -7
  77. package/dist/validation/json-parser.js.map +2 -2
  78. package/dist/validation/types.d.ts +114 -12
  79. package/dist/validation/types.js.map +1 -1
  80. package/package.json +5 -3
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/signal-exit.ts"],
4
- "sourcesContent": ["/**\n * @fileoverview Process signal handling utilities.\n * Provides cross-platform signal exit detection and cleanup handlers.\n */\n\n// Inlined signal-exit:\n// https://socket.dev/npm/package/signal-exit/overview/4.1.0\n// ISC License\n// Copyright (c) 2015-2023 Benjamin Coe, Isaac Z. Schlueter, and Contributors\n\n// This is not the set of all possible signals.\n//\n// It IS, however, the set of all signals that trigger\n// an exit on either Linux or BSD systems. Linux is a\n// superset of the signal names supported on BSD, and\n// the unknown signals just fail to register, so we can\n// catch that easily enough.\n//\n// Don't bother with SIGKILL. It's uncatchable, which\n// means that we can't fire any callbacks anyway.\n//\n// If a user does happen to register a handler on a non-\n// fatal signal like SIGWINCH or something, and then\n// exit, it'll end up firing `process.emit('exit')`, so\n// the handler will be fired anyway.\n//\n// SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised\n// artificially, inherently leave the process in a\n// state from which it is not safe to try and enter JS\n// listeners.\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst ReflectApply = Reflect.apply\nconst globalProcess = globalThis.process as\n | (NodeJS.Process & {\n // biome-ignore lint/suspicious/noExplicitAny: Signal exit emitter can be any event emitter.\n __signal_exit_emitter__?: any\n reallyExit?: (code?: number | undefined) => never\n })\n | undefined\nconst originalProcessEmit = globalProcess?.emit\nconst platform = globalProcess?.platform ?? ''\nconst originalProcessReallyExit = globalProcess?.reallyExit as\n | ((code?: number | undefined) => never)\n | undefined\nconst WIN32 = platform === 'win32'\n\nlet _events: typeof import('node:events') | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getEvents() {\n if (_events === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _events = /*@__PURE__*/ require('node:events')\n }\n return _events as typeof import('node:events')\n}\n\n// Type for tracking emitted signals.\ntype EmittedSignals = {\n // Using string as signals can include custom events like 'exit' and 'afterexit'.\n [signal: string]: boolean\n}\n\ntype SignalExitEmitter = import('node:events').EventEmitter & {\n count?: number\n emitted?: EmittedSignals\n infinite?: boolean\n}\nlet _emitter: SignalExitEmitter | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getEmitter() {\n if (_emitter === undefined) {\n if (globalProcess?.__signal_exit_emitter__) {\n _emitter = globalProcess.__signal_exit_emitter__\n } else if (globalProcess) {\n const EventEmitter = getEvents().EventEmitter\n _emitter = globalProcess.__signal_exit_emitter__ =\n new EventEmitter() as SignalExitEmitter\n _emitter.count = 0\n _emitter.emitted = { __proto__: null } as unknown as EmittedSignals\n }\n // Because this emitter is a global, we have to check to see if a\n // previous version of this library failed to enable infinite listeners.\n // I know what you're about to say. But literally everything about\n // signal-exit is a compromise with evil. Get used to it.\n if (_emitter && !_emitter.infinite) {\n _emitter.setMaxListeners(Number.POSITIVE_INFINITY)\n _emitter.infinite = true\n }\n }\n return _emitter as SignalExitEmitter\n}\n\ntype SignalListener = () => void\n// Type for signal listeners indexed by signal name.\ntype SignalListenerMap = {\n [signal: string]: SignalListener\n}\nlet _sigListeners: SignalListenerMap | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getSignalListeners() {\n if (_sigListeners === undefined) {\n _sigListeners = { __proto__: null } as unknown as SignalListenerMap\n const emitter = getEmitter()\n const sigs = getSignals()\n for (const sig of sigs) {\n _sigListeners[sig] = function listener() {\n // If there are no other listeners, an exit is coming!\n // Simplest way: remove us and then re-send the signal.\n // We know that this will kill the process, so we can\n // safely emit now.\n const listeners = globalProcess?.listeners(sig as NodeJS.Signals) || []\n if (listeners.length === emitter.count) {\n unload()\n emit('exit', null, sig)\n emit('afterexit', null, sig)\n // \"SIGHUP\" throws an `ENOSYS` error on Windows,\n // so use a supported signal instead.\n const killSig = WIN32 && sig === 'SIGHUP' ? 'SIGINT' : sig\n globalProcess?.kill(globalProcess?.pid, killSig)\n }\n }\n }\n }\n return _sigListeners as SignalListenerMap\n}\n\nlet _signals: string[] | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getSignals() {\n if (_signals === undefined) {\n _signals = ['SIGABRT', 'SIGALRM', 'SIGHUP', 'SIGINT', 'SIGTERM']\n if (!WIN32) {\n _signals.push(\n 'SIGVTALRM',\n 'SIGXCPU',\n 'SIGXFSZ',\n 'SIGUSR2',\n 'SIGTRAP',\n 'SIGSYS',\n 'SIGQUIT',\n 'SIGIOT',\n // should detect profiler and enable/disable accordingly.\n // see #21\n // 'SIGPROF'\n )\n }\n if (platform === 'linux') {\n _signals.push('SIGIO', 'SIGPOLL', 'SIGPWR', 'SIGSTKFLT', 'SIGUNUSED')\n }\n }\n return _signals as string[]\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nfunction emit(event: string, code: number | null, signal: string | null): void {\n const emitter = getEmitter()\n if (emitter.emitted?.[event]) {\n return\n }\n if (emitter.emitted) {\n emitter.emitted[event] = true\n }\n emitter.emit(event, code, signal)\n}\n\nlet loaded = false\n\n/**\n * Load signal handlers and hook into process exit events.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function load(): void {\n if (loaded || !globalProcess) {\n return\n }\n loaded = true\n\n // This is the number of onSignalExit's that are in play.\n // It's important so that we can count the correct number of\n // listeners on signals, and don't wait for the other one to\n // handle it instead of us.\n const emitter = getEmitter()\n if (emitter.count !== undefined) {\n emitter.count += 1\n }\n\n const sigs = getSignals()\n const sigListeners = getSignalListeners()\n _signals = sigs.filter(sig => {\n try {\n globalProcess.on(\n sig as NodeJS.Signals,\n sigListeners[sig] as SignalListener,\n )\n return true\n } catch {}\n return false\n })\n\n globalProcess.emit = processEmit as typeof globalProcess.emit\n globalProcess.reallyExit = processReallyExit\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nfunction processEmit(\n this: NodeJS.Process,\n eventName: string,\n exitCode?: number | undefined,\n // biome-ignore lint/suspicious/noExplicitAny: Process emit args can be any type.\n ...args: any[]\n): boolean {\n if (eventName === 'exit') {\n let actualExitCode = exitCode\n if (actualExitCode === undefined) {\n const processExitCode = globalProcess?.exitCode\n actualExitCode =\n typeof processExitCode === 'number' ? processExitCode : undefined\n } else if (globalProcess) {\n globalProcess.exitCode = actualExitCode\n }\n const result = ReflectApply(\n originalProcessEmit as (...args: unknown[]) => boolean,\n this,\n [eventName, actualExitCode, ...args],\n ) as boolean\n const numExitCode =\n typeof actualExitCode === 'number' ? actualExitCode : null\n emit('exit', numExitCode, null)\n emit('afterexit', numExitCode, null)\n return result\n }\n return ReflectApply(\n originalProcessEmit as (...args: unknown[]) => boolean,\n this,\n [eventName, exitCode, ...args],\n ) as boolean\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nfunction processReallyExit(code?: number | undefined): never {\n const exitCode = code || 0\n if (globalProcess) {\n globalProcess.exitCode = exitCode\n }\n emit('exit', exitCode, null)\n emit('afterexit', exitCode, null)\n ReflectApply(\n originalProcessReallyExit as (code?: number) => never,\n globalProcess,\n [exitCode],\n )\n throw new Error('processReallyExit should never return')\n}\n\nexport interface OnExitOptions {\n alwaysLast?: boolean\n}\n\n/**\n * Register a callback to run on process exit or signal.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function onExit(\n cb: (code: number | null, signal: string | null) => void,\n options?: OnExitOptions | undefined,\n): () => void {\n if (!globalProcess) {\n return function remove() {}\n }\n if (typeof cb !== 'function') {\n throw new TypeError('a callback must be provided for exit handler')\n }\n if (loaded === false) {\n load()\n }\n const { alwaysLast } = { __proto__: null, ...options } as OnExitOptions\n\n let eventName = 'exit'\n if (alwaysLast) {\n eventName = 'afterexit'\n }\n\n const emitter = getEmitter()\n emitter.on(eventName, cb)\n\n return function remove() {\n emitter.removeListener(eventName, cb)\n if (\n !emitter.listeners('exit').length &&\n !emitter.listeners('afterexit').length\n ) {\n unload()\n }\n }\n}\n\n/**\n * Get the list of signals that are currently being monitored.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function signals(): string[] | undefined {\n return _signals\n}\n\n/**\n * Unload signal handlers and restore original process behavior.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function unload(): void {\n if (!loaded || !globalProcess) {\n return\n }\n loaded = false\n\n const sigs = getSignals()\n const sigListeners = getSignalListeners()\n for (const sig of sigs) {\n try {\n globalProcess.removeListener(\n sig as NodeJS.Signals,\n sigListeners[sig] as SignalListener,\n )\n } catch {}\n }\n globalProcess.emit = originalProcessEmit as typeof globalProcess.emit\n if (originalProcessReallyExit !== undefined) {\n globalProcess.reallyExit = originalProcessReallyExit\n }\n const emitter = getEmitter()\n if (emitter.count !== undefined) {\n emitter.count -= 1\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCA,MAAM,eAAe,QAAQ;AAC7B,MAAM,gBAAgB,WAAW;AAOjC,MAAM,sBAAsB,eAAe;AAC3C,MAAM,WAAW,eAAe,YAAY;AAC5C,MAAM,4BAA4B,eAAe;AAGjD,MAAM,QAAQ,aAAa;AAE3B,IAAI;AAAA;AAEJ,SAAS,YAAY;AACnB,MAAI,YAAY,QAAW;AAGzB,cAAwB,QAAQ,aAAa;AAAA,EAC/C;AACA,SAAO;AACT;AAaA,IAAI;AAAA;AAEJ,SAAS,aAAa;AACpB,MAAI,aAAa,QAAW;AAC1B,QAAI,eAAe,yBAAyB;AAC1C,iBAAW,cAAc;AAAA,IAC3B,WAAW,eAAe;AACxB,YAAM,gBAAe,0BAAU,GAAE;AACjC,iBAAW,cAAc,0BACvB,IAAI,aAAa;AACnB,eAAS,QAAQ;AACjB,eAAS,UAAU,EAAE,WAAW,KAAK;AAAA,IACvC;AAKA,QAAI,YAAY,CAAC,SAAS,UAAU;AAClC,eAAS,gBAAgB,OAAO,iBAAiB;AACjD,eAAS,WAAW;AAAA,IACtB;AAAA,EACF;AACA,SAAO;AACT;AAOA,IAAI;AAAA;AAEJ,SAAS,qBAAqB;AAC5B,MAAI,kBAAkB,QAAW;AAC/B,oBAAgB,EAAE,WAAW,KAAK;AAClC,UAAM,UAAU,2BAAW;AAC3B,UAAM,OAAO,2BAAW;AACxB,eAAW,OAAO,MAAM;AACtB,oBAAc,GA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ACP;AACA,QAAM,EAAE,WAAW,IAAI,EAAE,WAAW,MAAM,GAAG,QAAQ;AAErD,MAAI,YAAY;AAChB,MAAI,YAAY;AACd,gBAAY;AAAA,EACd;AAEA,QAAM,UAAU,2BAAW;AAC3B,UAAQ,GAAG,WAAW,EAAE;AAExB,SAAO,SAAS,SAAS;AACvB,YAAQ,eAAe,WAAW,EAAE;AACpC,QACE,CAAC,QAAQ,UAAU,MAAM,EAAE,UAC3B,CAAC,QAAQ,UAAU,WAAW,EAAE,QAChC;AACA,6BAAO;AAAA,IACT;AAAA,EACF;AACF;AAAA;AAMO,SAAS,UAAgC;AAC9C,SAAO;AACT;AAAA;AAMO,SAAS,SAAe;AAC7B,MAAI,CAAC,UAAU,CAAC,eAAe;AAC7B;AAAA,EACF;AACA,WAAS;AAET,QAAM,OAAO,2BAAW;AACxB,QAAM,eAAe,mCAAmB;AACxC,aAAW,OAAO,MAAM;AACtB,QAAI;AACF,oBAAc;AAAA,QACZ;AAAA,QACA,aAAa,GAAG;AAAA,MAClB;AAAA,IACF,QAAQ;AAAA,IAAC;AAAA,EACX;AACA,gBAAc,OAAO;AACrB,MAAI,8BAA8B,QAAW;AAC3C,kBAAc,aAAa;AAAA,EAC7B;AACA,QAAM,UAAU,2BAAW;AAC3B,MAAI,QAAQ,UAAU,QAAW;AAC/B,YAAQ,SAAS;AAAA,EACnB;AACF;",
4
+ "sourcesContent": ["/**\n * @fileoverview Process signal handling utilities.\n * Provides cross-platform signal exit detection and cleanup handlers.\n */\n\n// Inlined signal-exit:\n// https://socket.dev/npm/package/signal-exit/overview/4.1.0\n// ISC License\n// Copyright (c) 2015-2023 Benjamin Coe, Isaac Z. Schlueter, and Contributors\n\n// This is not the set of all possible signals.\n//\n// It IS, however, the set of all signals that trigger\n// an exit on either Linux or BSD systems. Linux is a\n// superset of the signal names supported on BSD, and\n// the unknown signals just fail to register, so we can\n// catch that easily enough.\n//\n// Don't bother with SIGKILL. It's uncatchable, which\n// means that we can't fire any callbacks anyway.\n//\n// If a user does happen to register a handler on a non-\n// fatal signal like SIGWINCH or something, and then\n// exit, it'll end up firing `process.emit('exit')`, so\n// the handler will be fired anyway.\n//\n// SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised\n// artificially, inherently leave the process in a\n// state from which it is not safe to try and enter JS\n// listeners.\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst ReflectApply = Reflect.apply\nconst globalProcess = globalThis.process as\n | (NodeJS.Process & {\n __signal_exit_emitter__?: any\n reallyExit?: (code?: number | undefined) => never\n })\n | undefined\nconst originalProcessEmit = globalProcess?.emit\nconst platform = globalProcess?.platform ?? ''\nconst originalProcessReallyExit = globalProcess?.reallyExit as\n | ((code?: number | undefined) => never)\n | undefined\nconst WIN32 = platform === 'win32'\n\nlet _events: typeof import('node:events') | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getEvents() {\n if (_events === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _events = /*@__PURE__*/ require('node:events')\n }\n return _events as typeof import('node:events')\n}\n\n// Type for tracking emitted signals.\ntype EmittedSignals = {\n // Using string as signals can include custom events like 'exit' and 'afterexit'.\n [signal: string]: boolean\n}\n\ntype SignalExitEmitter = import('node:events').EventEmitter & {\n count?: number\n emitted?: EmittedSignals\n infinite?: boolean\n}\nlet _emitter: SignalExitEmitter | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getEmitter() {\n if (_emitter === undefined) {\n if (globalProcess?.__signal_exit_emitter__) {\n _emitter = globalProcess.__signal_exit_emitter__\n } else if (globalProcess) {\n const EventEmitter = getEvents().EventEmitter\n _emitter = globalProcess.__signal_exit_emitter__ =\n new EventEmitter() as SignalExitEmitter\n _emitter.count = 0\n _emitter.emitted = { __proto__: null } as unknown as EmittedSignals\n }\n // Because this emitter is a global, we have to check to see if a\n // previous version of this library failed to enable infinite listeners.\n // I know what you're about to say. But literally everything about\n // signal-exit is a compromise with evil. Get used to it.\n if (_emitter && !_emitter.infinite) {\n _emitter.setMaxListeners(Number.POSITIVE_INFINITY)\n _emitter.infinite = true\n }\n }\n return _emitter as SignalExitEmitter\n}\n\ntype SignalListener = () => void\n// Type for signal listeners indexed by signal name.\ntype SignalListenerMap = {\n [signal: string]: SignalListener\n}\nlet _sigListeners: SignalListenerMap | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getSignalListeners() {\n if (_sigListeners === undefined) {\n _sigListeners = { __proto__: null } as unknown as SignalListenerMap\n const emitter = getEmitter()\n const sigs = getSignals()\n for (const sig of sigs) {\n _sigListeners[sig] = function listener() {\n // If there are no other listeners, an exit is coming!\n // Simplest way: remove us and then re-send the signal.\n // We know that this will kill the process, so we can\n // safely emit now.\n const listeners = globalProcess?.listeners(sig as NodeJS.Signals) || []\n if (listeners.length === emitter.count) {\n unload()\n emit('exit', null, sig)\n emit('afterexit', null, sig)\n // \"SIGHUP\" throws an `ENOSYS` error on Windows,\n // so use a supported signal instead.\n const killSig = WIN32 && sig === 'SIGHUP' ? 'SIGINT' : sig\n globalProcess?.kill(globalProcess?.pid, killSig)\n }\n }\n }\n }\n return _sigListeners as SignalListenerMap\n}\n\nlet _signals: string[] | undefined\n/*@__NO_SIDE_EFFECTS__*/\nfunction getSignals() {\n if (_signals === undefined) {\n _signals = ['SIGABRT', 'SIGALRM', 'SIGHUP', 'SIGINT', 'SIGTERM']\n if (!WIN32) {\n _signals.push(\n 'SIGVTALRM',\n 'SIGXCPU',\n 'SIGXFSZ',\n 'SIGUSR2',\n 'SIGTRAP',\n 'SIGSYS',\n 'SIGQUIT',\n 'SIGIOT',\n // should detect profiler and enable/disable accordingly.\n // see #21\n // 'SIGPROF'\n )\n }\n if (platform === 'linux') {\n _signals.push('SIGIO', 'SIGPOLL', 'SIGPWR', 'SIGSTKFLT', 'SIGUNUSED')\n }\n }\n return _signals as string[]\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nfunction emit(event: string, code: number | null, signal: string | null): void {\n const emitter = getEmitter()\n if (emitter.emitted?.[event]) {\n return\n }\n if (emitter.emitted) {\n emitter.emitted[event] = true\n }\n emitter.emit(event, code, signal)\n}\n\nlet loaded = false\n\n/**\n * Load signal handlers and hook into process exit events.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function load(): void {\n if (loaded || !globalProcess) {\n return\n }\n loaded = true\n\n // This is the number of onSignalExit's that are in play.\n // It's important so that we can count the correct number of\n // listeners on signals, and don't wait for the other one to\n // handle it instead of us.\n const emitter = getEmitter()\n if (emitter.count !== undefined) {\n emitter.count += 1\n }\n\n const sigs = getSignals()\n const sigListeners = getSignalListeners()\n _signals = sigs.filter(sig => {\n try {\n globalProcess.on(\n sig as NodeJS.Signals,\n sigListeners[sig] as SignalListener,\n )\n return true\n } catch {}\n return false\n })\n\n globalProcess.emit = processEmit as typeof globalProcess.emit\n globalProcess.reallyExit = processReallyExit\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nfunction processEmit(\n this: NodeJS.Process,\n eventName: string,\n exitCode?: number | undefined,\n ...args: any[]\n): boolean {\n if (eventName === 'exit') {\n let actualExitCode = exitCode\n if (actualExitCode === undefined) {\n const processExitCode = globalProcess?.exitCode\n actualExitCode =\n typeof processExitCode === 'number' ? processExitCode : undefined\n } else if (globalProcess) {\n globalProcess.exitCode = actualExitCode\n }\n const result = ReflectApply(\n originalProcessEmit as (...args: unknown[]) => boolean,\n this,\n [eventName, actualExitCode, ...args],\n ) as boolean\n const numExitCode =\n typeof actualExitCode === 'number' ? actualExitCode : null\n emit('exit', numExitCode, null)\n emit('afterexit', numExitCode, null)\n return result\n }\n return ReflectApply(\n originalProcessEmit as (...args: unknown[]) => boolean,\n this,\n [eventName, exitCode, ...args],\n ) as boolean\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nfunction processReallyExit(code?: number | undefined): never {\n const exitCode = code || 0\n if (globalProcess) {\n globalProcess.exitCode = exitCode\n }\n emit('exit', exitCode, null)\n emit('afterexit', exitCode, null)\n ReflectApply(\n originalProcessReallyExit as (code?: number) => never,\n globalProcess,\n [exitCode],\n )\n throw new Error('processReallyExit should never return')\n}\n\nexport interface OnExitOptions {\n alwaysLast?: boolean\n}\n\n/**\n * Register a callback to run on process exit or signal.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function onExit(\n cb: (code: number | null, signal: string | null) => void,\n options?: OnExitOptions | undefined,\n): () => void {\n if (!globalProcess) {\n return function remove() {}\n }\n if (typeof cb !== 'function') {\n throw new TypeError('a callback must be provided for exit handler')\n }\n if (loaded === false) {\n load()\n }\n const { alwaysLast } = { __proto__: null, ...options } as OnExitOptions\n\n let eventName = 'exit'\n if (alwaysLast) {\n eventName = 'afterexit'\n }\n\n const emitter = getEmitter()\n emitter.on(eventName, cb)\n\n return function remove() {\n emitter.removeListener(eventName, cb)\n if (\n !emitter.listeners('exit').length &&\n !emitter.listeners('afterexit').length\n ) {\n unload()\n }\n }\n}\n\n/**\n * Get the list of signals that are currently being monitored.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function signals(): string[] | undefined {\n return _signals\n}\n\n/**\n * Unload signal handlers and restore original process behavior.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function unload(): void {\n if (!loaded || !globalProcess) {\n return\n }\n loaded = false\n\n const sigs = getSignals()\n const sigListeners = getSignalListeners()\n for (const sig of sigs) {\n try {\n globalProcess.removeListener(\n sig as NodeJS.Signals,\n sigListeners[sig] as SignalListener,\n )\n } catch {}\n }\n globalProcess.emit = originalProcessEmit as typeof globalProcess.emit\n if (originalProcessReallyExit !== undefined) {\n globalProcess.reallyExit = originalProcessReallyExit\n }\n const emitter = getEmitter()\n if (emitter.count !== undefined) {\n emitter.count -= 1\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCA,MAA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A;AAMO,SAAS,UAAgC;AAC9C,SAAO;AACT;AAAA;AAMO,SAAS,SAAe;AAC7B,MAAI,CAAC,UAAU,CAAC,eAAe;AAC7B;AAAA,EACF;AACA,WAAS;AAET,QAAM,OAAO,2BAAW;AACxB,QAAM,eAAe,mCAAmB;AACxC,aAAW,OAAO,MAAM;AACtB,QAAI;AACF,oBAAc;AAAA,QACZ;AAAA,QACA,aAAa,GAAG;AAAA,MAClB;AAAA,IACF,QAAQ;AAAA,IAAC;AAAA,EACX;AACA,gBAAc,OAAO;AACrB,MAAI,8BAA8B,QAAW;AAC3C,kBAAc,aAAa;AAAA,EAC7B;AACA,QAAM,UAAU,2BAAW;AAC3B,MAAI,QAAQ,UAAU,QAAW;AAC/B,YAAQ,SAAS;AAAA,EACnB;AACF;",
6
6
  "names": []
7
7
  }
package/dist/sorts.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/sorts.ts"],
4
- "sourcesContent": ["/**\n * @fileoverview Sorting comparison functions including locale-aware and natural sorting.\n * Provides various comparison utilities for arrays and collections.\n */\n\nlet _localeCompare: ((x: string, y: string) => number) | undefined\n/**\n * Compare two strings using locale-aware comparison.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function localeCompare(x: string, y: string): number {\n if (_localeCompare === undefined) {\n // Lazily call new Intl.Collator() because in Node it can take 10-14ms.\n _localeCompare = new Intl.Collator().compare\n }\n return _localeCompare(x, y)\n}\n\nlet _naturalCompare: ((x: string, y: string) => number) | undefined\n/**\n * Compare two strings using natural sorting (numeric-aware, case-insensitive).\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function naturalCompare(x: string, y: string): number {\n if (_naturalCompare === undefined) {\n // Lazily call new Intl.Collator() because in Node it can take 10-14ms.\n _naturalCompare = new Intl.Collator(\n // The `undefined` locale means it uses the default locale of the user's\n // environment.\n undefined,\n {\n // Enables numeric sorting: numbers in strings are compared by value,\n // e.g. 'file2' comes before 'file10' as numbers and not 'file10' before\n // 'file2' as plain text.\n numeric: true,\n // Makes the comparison case-insensitive and ignores diacritics, e.g.\n // 'a', 'A', and '\u00E1' are treated as equivalent.\n sensitivity: 'base',\n },\n ).compare\n }\n return _naturalCompare(x, y)\n}\n\n// Type for fast-sort sorter function.\ntype FastSortFunction = ReturnType<\n typeof import('fast-sort').createNewSortInstance\n>\n\nlet _naturalSorter: FastSortFunction | undefined\n/**\n * Sort an array using natural comparison.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function naturalSorter<T>(\n arrayToSort: T[],\n): ReturnType<FastSortFunction> {\n if (_naturalSorter === undefined) {\n const fastSort = /*@__PURE__*/ require('./external/fast-sort')\n // biome-ignore lint/suspicious/noExplicitAny: Fast-sort API requires dynamic method access.\n _naturalSorter = (fastSort as any).createNewSortInstance({\n comparer: naturalCompare,\n })\n }\n return _naturalSorter?.(arrayToSort)\n}\n\n/**\n * Simple string comparison.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function compareStr(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0\n}\n\n/**\n * Compare semantic versions.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function compareSemver(a: string, b: string): number {\n const semver = /*@__PURE__*/ require('./external/semver')\n const validA = semver.valid(a)\n const validB = semver.valid(b)\n\n if (!validA && !validB) {\n return 0\n }\n if (!validA) {\n return -1\n }\n if (!validB) {\n return 1\n }\n // biome-ignore lint/suspicious/noExplicitAny: Semver API requires dynamic method access.\n return (semver as any).compare(a, b)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,IAAI;AAAA;AAKG,SAAS,cAAc,GAAW,GAAmB;AAC1D,MAAI,mBAAmB,QAAW;AAEhC,qBAAiB,IAAI,KAAK,SAAS,EAAE;AAAA,EACvC;AACA,SAAO,eAAe,GAAG,CAAC;AAC5B;AAEA,IAAI;AAAA;AAKG,SAAS,eAAe,GAAW,GAAmB;AAC3D,MAAI,oBAAoB,QAAW;AAEjC,sBAAkB,IAAI,KAAK;AAAA;AAAA;AAAA,MAGzB;AAAA,MACA;AAAA;AAAA;AAAA;AAAA,QAIE,SAAS;AAAA;AAAA;AAAA,QAGT,aAAa;AAAA,MACf;AAAA,IACF,EAAE;AAAA,EACJ;AACA,SAAO,gBAAgB,GAAG,CAAC;AAC7B;AAOA,IAAI;AAAA;AAKG,SAAS,cACd,aAC8B;AAC9B,MAAI,mBAAmB,QAAW;AAChC,UAAM,WAAyB,QAAQ,sBAAsB;AAE7D,qBAAkB,SAAiB,sBAAsB;AAAA,MACvD,UAAU;AAAA,IACZ,CAAC;AAAA,EACH;AACA,SAAO,iBAAiB,WAAW;AACrC;AAAA;AAMO,SAAS,WAAW,GAAW,GAAmB;AACvD,SAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAClC;AAAA;AAMO,SAAS,cAAc,GAAW,GAAmB;AAC1D,QAAM,SAAuB,QAAQ,mBAAmB;AACxD,QAAM,SAAS,OAAO,MAAM,CAAC;AAC7B,QAAM,SAAS,OAAO,MAAM,CAAC;AAE7B,MAAI,CAAC,UAAU,CAAC,QAAQ;AACtB,WAAO;AAAA,EACT;AACA,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AACA,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,SAAQ,OAAe,QAAQ,GAAG,CAAC;AACrC;",
4
+ "sourcesContent": ["/**\n * @fileoverview Sorting comparison functions including locale-aware and natural sorting.\n * Provides various comparison utilities for arrays and collections.\n */\n\nlet _localeCompare: ((x: string, y: string) => number) | undefined\n/**\n * Compare two strings using locale-aware comparison.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function localeCompare(x: string, y: string): number {\n if (_localeCompare === undefined) {\n // Lazily call new Intl.Collator() because in Node it can take 10-14ms.\n _localeCompare = new Intl.Collator().compare\n }\n return _localeCompare(x, y)\n}\n\nlet _naturalCompare: ((x: string, y: string) => number) | undefined\n/**\n * Compare two strings using natural sorting (numeric-aware, case-insensitive).\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function naturalCompare(x: string, y: string): number {\n if (_naturalCompare === undefined) {\n // Lazily call new Intl.Collator() because in Node it can take 10-14ms.\n _naturalCompare = new Intl.Collator(\n // The `undefined` locale means it uses the default locale of the user's\n // environment.\n undefined,\n {\n // Enables numeric sorting: numbers in strings are compared by value,\n // e.g. 'file2' comes before 'file10' as numbers and not 'file10' before\n // 'file2' as plain text.\n numeric: true,\n // Makes the comparison case-insensitive and ignores diacritics, e.g.\n // 'a', 'A', and '\u00E1' are treated as equivalent.\n sensitivity: 'base',\n },\n ).compare\n }\n return _naturalCompare(x, y)\n}\n\n// Type for fast-sort sorter function.\ntype FastSortFunction = ReturnType<\n typeof import('fast-sort').createNewSortInstance\n>\n\nlet _naturalSorter: FastSortFunction | undefined\n/**\n * Sort an array using natural comparison.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function naturalSorter<T>(\n arrayToSort: T[],\n): ReturnType<FastSortFunction> {\n if (_naturalSorter === undefined) {\n const fastSort = /*@__PURE__*/ require('./external/fast-sort')\n _naturalSorter = (fastSort as any).createNewSortInstance({\n comparer: naturalCompare,\n })\n }\n return _naturalSorter?.(arrayToSort)\n}\n\n/**\n * Simple string comparison.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function compareStr(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0\n}\n\n/**\n * Compare semantic versions.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function compareSemver(a: string, b: string): number {\n const semver = /*@__PURE__*/ require('./external/semver')\n const validA = semver.valid(a)\n const validB = semver.valid(b)\n\n if (!validA && !validB) {\n return 0\n }\n if (!validA) {\n return -1\n }\n if (!validB) {\n return 1\n }\n return (semver as any).compare(a, b)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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ferEncoding;
3
- // Type for promise-spawn options.
3
+ /**
4
+ * Options for spawning a child process with promise-based completion.
5
+ *
6
+ * @property {string | undefined} cwd - Current working directory for the process
7
+ * @property {boolean | undefined} stdioString - Convert stdio output to strings (default: `true`)
8
+ * @property {StdioType | undefined} stdio - Stdio configuration (`'pipe'`, `'ignore'`, `'inherit'`, or array)
9
+ * @property {NodeJS.ProcessEnv | undefined} env - Environment variables for the process
10
+ * @property {boolean | string | undefined} shell - Whether to run command in shell, or path to shell
11
+ * @property {AbortSignal | undefined} signal - Signal to abort the process
12
+ * @property {number | undefined} timeout - Maximum time in milliseconds before killing the process
13
+ * @property {number | undefined} uid - User identity of the process (POSIX only)
14
+ * @property {number | undefined} gid - Group identity of the process (POSIX only)
15
+ */
4
16
  export type PromiseSpawnOptions = {
5
17
  cwd?: string | undefined;
6
18
  stdioString?: boolean | undefined;
@@ -12,7 +24,20 @@ export type PromiseSpawnOptions = {
12
24
  uid?: number | undefined;
13
25
  gid?: number | undefined;
14
26
  };
15
- // Type for promise-spawn result.
27
+ /**
28
+ * Result returned by {@link spawn} when the child process completes.
29
+ * This is a Promise that resolves with process exit information and output,
30
+ * with additional properties for accessing the running process and stdin stream.
31
+ *
32
+ * @property {ChildProcessType} process - The running child process instance
33
+ * @property {WritableStreamType | null} stdin - Writable stream for process stdin, or `null` if not piped
34
+ *
35
+ * @example
36
+ * const result = spawn('echo', ['hello'])
37
+ * result.stdin?.write('additional input\n')
38
+ * const { code, stdout } = await result
39
+ * console.log(stdout) // 'hello'
40
+ */
16
41
  export type PromiseSpawnResult = Promise<{
17
42
  cmd: string;
18
43
  args: string[] | readonly string[];
@@ -25,7 +50,29 @@ export type PromiseSpawnResult = Promise<{
25
50
  stdin: WritableStreamType | null;
26
51
  };
27
52
  /**
28
- * Check if a value is a spawn error.
53
+ * Error object thrown when a spawned process fails.
54
+ * Extends the standard Error with process-specific information including exit code,
55
+ * signal, command details, and captured output.
56
+ *
57
+ * @property {string[]} args - Arguments passed to the command
58
+ * @property {string} cmd - Command that was executed
59
+ * @property {number} code - Process exit code
60
+ * @property {string} name - Error name (typically `'Error'`)
61
+ * @property {string} message - Error message describing the failure
62
+ * @property {NodeJS.Signals | null} signal - Signal that terminated the process, if any
63
+ * @property {string} stack - Stack trace of the error
64
+ * @property {string | Buffer} stderr - Standard error output from the process
65
+ * @property {string | Buffer} stdout - Standard output from the process
66
+ *
67
+ * @example
68
+ * try {
69
+ * await spawn('exit', ['1'])
70
+ * } catch (error) {
71
+ * if (isSpawnError(error)) {
72
+ * console.error(`Command failed with code ${error.code}`)
73
+ * console.error(`stderr: ${error.stderr}`)
74
+ * }
75
+ * }
29
76
  */
30
77
  export type SpawnError = {
31
78
  args: string[];
@@ -38,17 +85,67 @@ export type SpawnError = {
38
85
  stderr: string | Buffer;
39
86
  stdout: string | Buffer;
40
87
  };
88
+ /**
89
+ * Spawn error variant where stdout and stderr are guaranteed to be strings.
90
+ * This type is used when `stdioString: true` is set in spawn options.
91
+ *
92
+ * @property {string} stdout - Standard output as a string
93
+ * @property {string} stderr - Standard error as a string
94
+ */
41
95
  export type SpawnErrorWithOutputString = SpawnError & {
42
96
  stdout: string;
43
97
  stderr: string;
44
98
  };
99
+ /**
100
+ * Spawn error variant where stdout and stderr are guaranteed to be Buffers.
101
+ * This type is used when `stdioString: false` is set in spawn options.
102
+ *
103
+ * @property {Buffer} stdout - Standard output as a Buffer
104
+ * @property {Buffer} stderr - Standard error as a Buffer
105
+ */
45
106
  export type SpawnErrorWithOutputBuffer = SpawnError & {
46
107
  stdout: Buffer;
47
108
  stderr: Buffer;
48
109
  };
110
+ /**
111
+ * Extra options passed to the underlying promise-spawn implementation.
112
+ * This is an open-ended object for passing additional metadata or configuration.
113
+ */
49
114
  export type SpawnExtra = Record<string, unknown>;
115
+ /**
116
+ * Valid values for individual stdio streams.
117
+ * - `'pipe'` - Creates a pipe between child and parent (default)
118
+ * - `'ignore'` - Ignores the stream
119
+ * - `'inherit'` - Uses parent's stream
120
+ * - `'overlapped'` - Windows-specific overlapped I/O
121
+ */
50
122
  export type IOType = 'pipe' | 'ignore' | 'inherit' | 'overlapped';
123
+ /**
124
+ * Configuration for process stdio (stdin, stdout, stderr) streams.
125
+ * Can be a single value applied to all streams, or an array specifying each stream individually.
126
+ * - `'ipc'` - Creates an IPC channel for communication with the parent
127
+ *
128
+ * @example
129
+ * // All streams piped
130
+ * stdio: 'pipe'
131
+ *
132
+ * @example
133
+ * // Custom configuration per stream: [stdin, stdout, stderr]
134
+ * stdio: ['ignore', 'pipe', 'pipe']
135
+ */
51
136
  export type StdioType = IOType | 'ipc' | Array<IOType | 'ipc'>;
137
+ /**
138
+ * Result object returned by {@link spawnSync} when the child process completes synchronously.
139
+ *
140
+ * @template T - Type of stdout/stderr (string or Buffer)
141
+ * @property {number} pid - Process ID of the spawned child
142
+ * @property {Array<T | null>} output - Array containing stdout/stderr values
143
+ * @property {T} stdout - Standard output from the process
144
+ * @property {T} stderr - Standard error from the process
145
+ * @property {number | null} status - Exit code, or `null` if killed by signal
146
+ * @property {NodeJS.Signals | null} signal - Signal that terminated the process, or `null`
147
+ * @property {Error | undefined} error - Error object if the spawn failed
148
+ */
52
149
  export interface SpawnSyncReturns<T> {
53
150
  pid: number;
54
151
  output: Array<T | null>;
@@ -59,12 +156,42 @@ export interface SpawnSyncReturns<T> {
59
156
  error?: Error | undefined;
60
157
  }
61
158
  /**
62
- * Check if a value is a spawn error with expected properties.
159
+ * Check if a value is a spawn error with expected error properties.
160
+ * Tests for common error properties from child process failures.
161
+ *
162
+ * @param {unknown} value - Value to check
163
+ * @returns {boolean} `true` if the value has spawn error properties
164
+ *
165
+ * @example
166
+ * try {
167
+ * await spawn('nonexistent-command')
168
+ * } catch (error) {
169
+ * if (isSpawnError(error)) {
170
+ * console.error(`Spawn failed: ${error.code}`)
171
+ * }
172
+ * }
63
173
  */
64
174
  /*@__NO_SIDE_EFFECTS__*/
65
175
  export declare function isSpawnError(value: unknown): value is SpawnError;
66
176
  /**
67
177
  * Check if stdio configuration matches a specific type.
178
+ * When called with one argument, validates if it's a valid stdio type.
179
+ * When called with two arguments, checks if the stdio config matches the specified type.
180
+ *
181
+ * @param {string | string[]} stdio - Stdio configuration to check
182
+ * @param {StdioType | undefined} type - Expected stdio type (optional)
183
+ * @returns {boolean} `true` if stdio matches the type or is valid
184
+ *
185
+ * @example
186
+ * // Check if valid stdio type
187
+ * isStdioType('pipe') // true
188
+ * isStdioType('invalid') // false
189
+ *
190
+ * @example
191
+ * // Check if stdio matches specific type
192
+ * isStdioType('pipe', 'pipe') // true
193
+ * isStdioType(['pipe', 'pipe', 'pipe'], 'pipe') // true
194
+ * isStdioType('ignore', 'pipe') // false
68
195
  */
69
196
  /*@__NO_SIDE_EFFECTS__*/
70
197
  export declare function isStdioType(stdio: string | string[], type?: StdioType | undefined): boolean;
@@ -75,7 +202,6 @@ interface NodeSpawnOptions {
75
202
  cwd?: string | URL | undefined;
76
203
  env?: NodeJS.ProcessEnv | undefined;
77
204
  argv0?: string | undefined;
78
- // biome-ignore lint/suspicious/noExplicitAny: Stdio can be complex union of types from Node.js.
79
205
  stdio?: any;
80
206
  detached?: boolean | undefined;
81
207
  uid?: number | undefined;
@@ -94,7 +220,6 @@ interface ChildProcessType {
94
220
  stdin: NodeJS.WritableStream | null;
95
221
  stdout: NodeJS.ReadableStream | null;
96
222
  stderr: NodeJS.ReadableStream | null;
97
- // biome-ignore lint/suspicious/noExplicitAny: IPC channel type from Node.js.
98
223
  readonly channel?: any;
99
224
  readonly stdio: [
100
225
  NodeJS.WritableStream | null,
@@ -111,20 +236,9 @@ interface ChildProcessType {
111
236
  readonly spawnargs: string[];
112
237
  readonly spawnfile: string;
113
238
  kill(signal?: NodeJS.Signals | number): boolean;
114
- // biome-ignore lint/suspicious/noExplicitAny: IPC message type from Node.js.
115
239
  send(message: any, callback?: (error: Error | null) => void): boolean;
116
- send(
117
- // biome-ignore lint/suspicious/noExplicitAny: IPC message and handle types from Node.js.
118
- message: any,
119
- // biome-ignore lint/suspicious/noExplicitAny: IPC message and handle types from Node.js.
120
- sendHandle?: any | undefined, callback?: (error: Error | null) => void): boolean;
121
- send(
122
- // biome-ignore lint/suspicious/noExplicitAny: IPC message, handle, and options types from Node.js.
123
- message: any,
124
- // biome-ignore lint/suspicious/noExplicitAny: IPC message, handle, and options types from Node.js.
125
- sendHandle?: any | undefined,
126
- // biome-ignore lint/suspicious/noExplicitAny: IPC message, handle, and options types from Node.js.
127
- options?: any | undefined, callback?: (error: Error | null) => void): boolean;
240
+ send(message: any, sendHandle?: any | undefined, callback?: (error: Error | null) => void): boolean;
241
+ send(message: any, sendHandle?: any | undefined, options?: any | undefined, callback?: (error: Error | null) => void): boolean;
128
242
  disconnect(): void;
129
243
  unref(): void;
130
244
  ref(): void;
@@ -139,22 +253,30 @@ interface WritableStreamType {
139
253
  writableObjectMode: boolean;
140
254
  writableCorked: number;
141
255
  destroyed: boolean;
142
- write(
143
- // biome-ignore lint/suspicious/noExplicitAny: Stream chunk can be any type.
144
- chunk: any, encoding?: BufferEncoding | undefined, callback?: (error?: Error | null) => void): boolean;
145
- // biome-ignore lint/suspicious/noExplicitAny: Stream chunk can be any type.
256
+ write(chunk: any, encoding?: BufferEncoding | undefined, callback?: (error?: Error | null) => void): boolean;
146
257
  write(chunk: any, callback?: (error?: Error | null) => void): boolean;
147
258
  end(cb?: () => void): this;
148
- // biome-ignore lint/suspicious/noExplicitAny: Stream chunk can be any type.
149
259
  end(chunk: any, cb?: () => void): this;
150
- // biome-ignore lint/suspicious/noExplicitAny: Stream chunk can be any type.
151
260
  end(chunk: any, encoding?: BufferEncoding | undefined, cb?: () => void): this;
152
261
  cork(): void;
153
262
  uncork(): void;
154
263
  destroy(error?: Error | undefined): this;
155
264
  }
156
265
  /**
157
- * Spawn a child process with enhanced error handling and output capture.
266
+ * Options for spawning a child process with {@link spawn}.
267
+ * Extends Node.js spawn options with additional Socket-specific functionality.
268
+ *
269
+ * @property {import('./spinner').Spinner | undefined} spinner - Spinner instance to pause during execution
270
+ * @property {boolean | undefined} stdioString - Convert output to strings (default: `true`)
271
+ * @property {boolean | undefined} stripAnsi - Remove ANSI codes from output (default: `true`)
272
+ * @property {string | URL | undefined} cwd - Current working directory
273
+ * @property {NodeJS.ProcessEnv | undefined} env - Environment variables
274
+ * @property {StdioType | undefined} stdio - Stdio configuration
275
+ * @property {boolean | string | undefined} shell - Run command in shell
276
+ * @property {number | undefined} timeout - Timeout in milliseconds
277
+ * @property {AbortSignal | undefined} signal - Abort signal
278
+ * @property {number | undefined} uid - User identity (POSIX)
279
+ * @property {number | undefined} gid - Group identity (POSIX)
158
280
  */
159
281
  export type SpawnOptions = import('./objects').Remap<NodeSpawnOptions & {
160
282
  spinner?: import('./spinner').Spinner | undefined;
@@ -162,6 +284,16 @@ export type SpawnOptions = import('./objects').Remap<NodeSpawnOptions & {
162
284
  stripAnsi?: boolean;
163
285
  }>;
164
286
  export type SpawnResult = PromiseSpawnResult;
287
+ /**
288
+ * Result object returned when a spawned process completes.
289
+ *
290
+ * @property {string} cmd - Command that was executed
291
+ * @property {string[] | readonly string[]} args - Arguments passed to the command
292
+ * @property {number} code - Process exit code
293
+ * @property {NodeJS.Signals | null} signal - Signal that terminated the process, if any
294
+ * @property {string | Buffer} stdout - Standard output (string if `stdioString: true`, Buffer otherwise)
295
+ * @property {string | Buffer} stderr - Standard error (string if `stdioString: true`, Buffer otherwise)
296
+ */
165
297
  export type SpawnStdioResult = {
166
298
  cmd: string;
167
299
  args: string[] | readonly string[];
@@ -172,6 +304,7 @@ export type SpawnStdioResult = {
172
304
  };
173
305
  /**
174
306
  * Spawn a child process and return a promise that resolves when it completes.
307
+ * Provides enhanced error handling, output capture, and cross-platform support.
175
308
  *
176
309
  * SECURITY: This function uses array-based arguments which prevent command injection.
177
310
  * Arguments in the `args` array are passed directly to the OS without shell
@@ -182,26 +315,102 @@ export type SpawnStdioResult = {
182
315
  * approach remains secure because Node.js properly escapes each argument before passing
183
316
  * to the shell.
184
317
  *
185
- * @param cmd - Command to execute (not user-controlled)
186
- * @param args - Array of arguments (safe even with user input due to array-based passing)
187
- * @param options - Spawn options
188
- * @param extra - Extra options for promise-spawn
318
+ * @param {string} cmd - Command to execute (not user-controlled)
319
+ * @param {string[] | readonly string[] | undefined} args - Array of arguments (safe even with user input)
320
+ * @param {SpawnOptions | undefined} options - Spawn options for process configuration
321
+ * @param {SpawnExtra | undefined} extra - Extra options for promise-spawn
322
+ * @returns {SpawnResult} Promise that resolves with process exit information
323
+ *
324
+ * @throws {SpawnError} When the process exits with non-zero code or is terminated by signal
325
+ *
326
+ * @example
327
+ * // Basic usage - spawn and wait for completion
328
+ * const result = await spawn('git', ['status'])
329
+ * console.log(result.stdout)
330
+ *
331
+ * @example
332
+ * // With options - set working directory and environment
333
+ * const result = await spawn('npm', ['install'], {
334
+ * cwd: '/path/to/project',
335
+ * env: { NODE_ENV: 'production' }
336
+ * })
189
337
  *
190
338
  * @example
191
- * // ✔ DO THIS - Array-based arguments
339
+ * // ✔ DO THIS - Array-based arguments (safe)
192
340
  * spawn('git', ['commit', '-m', userMessage])
193
341
  * // Each argument is properly escaped, even if userMessage = "foo; rm -rf /"
194
342
  *
195
343
  * @example
196
- * // ✖ NEVER DO THIS - String concatenation
344
+ * // ✖ NEVER DO THIS - String concatenation (vulnerable)
197
345
  * spawn(`git commit -m "${userMessage}"`, { shell: true })
198
346
  * // Vulnerable to injection if userMessage = '"; rm -rf / #'
347
+ *
348
+ * @example
349
+ * // Access stdin for interactive processes
350
+ * const result = spawn('cat', [])
351
+ * result.stdin?.write('Hello\n')
352
+ * result.stdin?.end()
353
+ * const { stdout } = await result
354
+ * console.log(stdout) // 'Hello'
355
+ *
356
+ * @example
357
+ * // Handle errors with exit codes
358
+ * try {
359
+ * await spawn('exit', ['1'])
360
+ * } catch (error) {
361
+ * if (isSpawnError(error)) {
362
+ * console.error(`Failed with code ${error.code}`)
363
+ * console.error(error.stderr)
364
+ * }
365
+ * }
199
366
  */
200
367
  export declare function spawn(cmd: string, args?: string[] | readonly string[], options?: SpawnOptions | undefined, extra?: SpawnExtra | undefined): SpawnResult;
201
368
  /*@__NO_SIDE_EFFECTS__*/
202
369
  /**
203
- * Synchronously spawn a child process.
370
+ * Options for synchronously spawning a child process with {@link spawnSync}.
371
+ * Same as {@link SpawnOptions} but excludes the `spinner` property (not applicable for synchronous execution).
204
372
  */
205
373
  export type SpawnSyncOptions = Omit<SpawnOptions, 'spinner'>;
374
+ /**
375
+ * Synchronously spawn a child process and wait for it to complete.
376
+ * Blocks execution until the process exits, returning all output and exit information.
377
+ *
378
+ * WARNING: This function blocks the event loop. Use {@link spawn} for async operations.
379
+ *
380
+ * @param {string} cmd - Command to execute
381
+ * @param {string[] | readonly string[] | undefined} args - Array of arguments
382
+ * @param {SpawnSyncOptions | undefined} options - Spawn options for process configuration
383
+ * @returns {SpawnSyncReturns<string | Buffer>} Process result with exit code and captured output
384
+ *
385
+ * @example
386
+ * // Basic synchronous spawn
387
+ * const result = spawnSync('git', ['status'])
388
+ * console.log(result.stdout)
389
+ * console.log(result.status) // exit code
390
+ *
391
+ * @example
392
+ * // With options
393
+ * const result = spawnSync('npm', ['install'], {
394
+ * cwd: '/path/to/project',
395
+ * stdioString: true
396
+ * })
397
+ * if (result.status !== 0) {
398
+ * console.error(result.stderr)
399
+ * }
400
+ *
401
+ * @example
402
+ * // Get raw buffer output
403
+ * const result = spawnSync('cat', ['binary-file'], {
404
+ * stdioString: false
405
+ * })
406
+ * console.log(result.stdout) // Buffer
407
+ *
408
+ * @example
409
+ * // Handle process errors
410
+ * const result = spawnSync('nonexistent-command')
411
+ * if (result.error) {
412
+ * console.error('Failed to spawn:', result.error)
413
+ * }
414
+ */
206
415
  export declare function spawnSync(cmd: string, args?: string[] | readonly string[], options?: SpawnSyncOptions | undefined): SpawnSyncReturns<string | Buffer>;
207
416
  export {};
package/dist/spawn.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/spawn.ts"],
4
- "sourcesContent": ["/**\n * @fileoverview Child process spawning utilities with cross-platform support.\n * Provides enhanced spawn functionality with stdio handling and error management.\n *\n * SECURITY: Array-Based Arguments Prevent Command Injection\n *\n * This module uses array-based arguments for all command execution, which is the\n * PRIMARY DEFENSE against command injection attacks. When you pass arguments as\n * an array to spawn():\n *\n * spawn('npx', ['sfw', tool, ...args], { shell: true })\n *\n * Node.js handles escaping automatically. Each argument is passed directly to the\n * OS without shell interpretation. Shell metacharacters like ; | & $ ( ) ` are\n * treated as LITERAL STRINGS, not as commands. This approach is secure even when\n * shell: true is used on Windows for .cmd/.bat file resolution.\n *\n * UNSAFE ALTERNATIVE (not used in this codebase):\n * spawn(`npx sfw ${tool} ${args.join(' ')}`, { shell: true }) // \u2716 VULNERABLE\n *\n * String concatenation allows injection. For example, if tool = \"foo; rm -rf /\",\n * the shell would execute both commands. Array-based arguments prevent this.\n *\n * References:\n * - https://nodejs.org/api/child_process.html#child_processspawncommand-args-options\n * - https://cheatsheetseries.owasp.org/cheatsheets/Nodejs_Security_Cheat_Sheet.html\n */\n\nimport { getAbortSignal, getSpinner } from '#constants/process'\n\nimport { isArray } from './arrays'\n\nconst abortSignal = getAbortSignal()\nconst spinner = getSpinner()\n\nimport { getOwn, hasOwn } from './objects'\nimport { stripAnsi } from './strings'\n\n// Define BufferEncoding type for TypeScript compatibility.\ntype BufferEncoding = globalThis.BufferEncoding\n\nconst windowsScriptExtRegExp = /\\.(?:cmd|bat|ps1)$/i\n\nlet _child_process: typeof import('node:child_process') | undefined\n/**\n * Lazily load the child_process module.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getChildProcess() {\n if (_child_process === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _child_process = /*@__PURE__*/ require('node:child_process')\n }\n return _child_process as typeof import('node:child_process')\n}\n\n// Type for promise-spawn options.\nexport type PromiseSpawnOptions = {\n cwd?: string | undefined\n stdioString?: boolean | undefined\n stdio?: StdioType | undefined\n env?: NodeJS.ProcessEnv | undefined\n shell?: boolean | string | undefined\n signal?: AbortSignal | undefined\n timeout?: number | undefined\n uid?: number | undefined\n gid?: number | undefined\n}\n\n// Type for promise-spawn result.\nexport type PromiseSpawnResult = Promise<{\n cmd: string\n args: string[] | readonly string[]\n code: number\n signal: NodeJS.Signals | null\n stdout: string | Buffer\n stderr: string | Buffer\n}> & {\n process: ChildProcessType\n stdin: WritableStreamType | null\n}\n\nlet _npmCliPromiseSpawn:\n | ((\n cmd: string,\n args: string[],\n options?: PromiseSpawnOptions | undefined,\n extra?: SpawnExtra | undefined,\n ) => PromiseSpawnResult)\n | undefined\n/**\n * Lazily load the promise-spawn module for async process spawning.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getNpmcliPromiseSpawn() {\n if (_npmCliPromiseSpawn === undefined) {\n _npmCliPromiseSpawn = /*@__PURE__*/ require('./external/@npmcli/promise-spawn')\n }\n return _npmCliPromiseSpawn as unknown as typeof import('@npmcli/promise-spawn')\n}\n\nlet _path: typeof import('node:path') | undefined\n/**\n * Lazily load the path module to avoid Webpack errors.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getPath() {\n if (_path === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _path = /*@__PURE__*/ require('node:path')\n }\n return _path as typeof import('node:path')\n}\n\n/**\n * Check if a value is a spawn error.\n */\nexport type SpawnError = {\n args: string[]\n cmd: string\n code: number\n name: string\n message: string\n signal: NodeJS.Signals | null\n stack: string\n stderr: string | Buffer\n stdout: string | Buffer\n}\n\nexport type SpawnErrorWithOutputString = SpawnError & {\n stdout: string\n stderr: string\n}\n\nexport type SpawnErrorWithOutputBuffer = SpawnError & {\n stdout: Buffer\n stderr: Buffer\n}\n\nexport type SpawnExtra = Record<string, unknown>\n\nexport type IOType = 'pipe' | 'ignore' | 'inherit' | 'overlapped'\nexport type StdioType = IOType | 'ipc' | Array<IOType | 'ipc'>\n\nexport interface SpawnSyncReturns<T> {\n pid: number\n output: Array<T | null>\n stdout: T\n stderr: T\n status: number | null\n signal: NodeJS.Signals | null\n error?: Error | undefined\n}\n\n/**\n * Check if a value is a spawn error with expected properties.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isSpawnError(value: unknown): value is SpawnError {\n if (value === null || typeof value !== 'object') {\n return false\n }\n // Check for spawn-specific error properties.\n const err = value as Record<string, unknown>\n return (\n (hasOwn(err, 'code') && typeof err['code'] !== 'undefined') ||\n (hasOwn(err, 'errno') && typeof err['errno'] !== 'undefined') ||\n (hasOwn(err, 'syscall') && typeof err['syscall'] === 'string')\n )\n}\n\n/**\n * Check if stdio configuration matches a specific type.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isStdioType(\n stdio: string | string[],\n type?: StdioType | undefined,\n): boolean {\n // If called with one argument, check if it's a valid stdio type.\n // biome-ignore lint/complexity/noArguments: Function overload detection for single vs two-arg calls.\n if (arguments.length === 1) {\n const validTypes = ['pipe', 'ignore', 'inherit', 'overlapped']\n return typeof stdio === 'string' && validTypes.includes(stdio)\n }\n // Original two-argument behavior.\n return (\n stdio === type ||\n ((stdio === null || stdio === undefined) && type === 'pipe') ||\n (isArray(stdio) &&\n stdio.length > 2 &&\n stdio[0] === type &&\n stdio[1] === type &&\n stdio[2] === type)\n )\n}\n\n/**\n * Strip ANSI escape codes from spawn result stdout and stderr.\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction stripAnsiFromSpawnResult(result: unknown): unknown {\n const res = result as {\n stdout?: string | Buffer\n stderr?: string | Buffer\n }\n const { stderr, stdout } = res\n if (typeof stdout === 'string') {\n res.stdout = stripAnsi(stdout)\n }\n if (typeof stderr === 'string') {\n res.stderr = stripAnsi(stderr)\n }\n return res\n}\n\n/*@__NO_SIDE_EFFECTS__*/\n// Duplicated from Node.js child_process.SpawnOptions\n// These are the options passed to child_process.spawn()\ninterface NodeSpawnOptions {\n cwd?: string | URL | undefined\n env?: NodeJS.ProcessEnv | undefined\n argv0?: string | undefined\n // biome-ignore lint/suspicious/noExplicitAny: Stdio can be complex union of types from Node.js.\n stdio?: any\n detached?: boolean | undefined\n uid?: number | undefined\n gid?: number | undefined\n serialization?: 'json' | 'advanced' | undefined\n shell?: boolean | string | undefined\n windowsVerbatimArguments?: boolean | undefined\n windowsHide?: boolean | undefined\n signal?: AbortSignal | undefined\n timeout?: number | undefined\n killSignal?: NodeJS.Signals | number | undefined\n}\n\n// Duplicated from Node.js child_process.ChildProcess\n// This represents a spawned child process\ninterface ChildProcessType {\n stdin: NodeJS.WritableStream | null\n stdout: NodeJS.ReadableStream | null\n stderr: NodeJS.ReadableStream | null\n // biome-ignore lint/suspicious/noExplicitAny: IPC channel type from Node.js.\n readonly channel?: any\n readonly stdio: [\n NodeJS.WritableStream | null,\n NodeJS.ReadableStream | null,\n NodeJS.ReadableStream | null,\n NodeJS.ReadableStream | NodeJS.WritableStream | null | undefined,\n NodeJS.ReadableStream | NodeJS.WritableStream | null | undefined,\n ]\n readonly killed: boolean\n readonly pid?: number | undefined\n readonly connected: boolean\n readonly exitCode: number | null\n readonly signalCode: NodeJS.Signals | null\n readonly spawnargs: string[]\n readonly spawnfile: string\n kill(signal?: NodeJS.Signals | number): boolean\n // biome-ignore lint/suspicious/noExplicitAny: IPC message type from Node.js.\n send(message: any, callback?: (error: Error | null) => void): boolean\n send(\n // biome-ignore lint/suspicious/noExplicitAny: IPC message and handle types from Node.js.\n message: any,\n // biome-ignore lint/suspicious/noExplicitAny: IPC message and handle types from Node.js.\n sendHandle?: any | undefined,\n callback?: (error: Error | null) => void,\n ): boolean\n send(\n // biome-ignore lint/suspicious/noExplicitAny: IPC message, handle, and options types from Node.js.\n message: any,\n // biome-ignore lint/suspicious/noExplicitAny: IPC message, handle, and options types from Node.js.\n sendHandle?: any | undefined,\n // biome-ignore lint/suspicious/noExplicitAny: IPC message, handle, and options types from Node.js.\n options?: any | undefined,\n callback?: (error: Error | null) => void,\n ): boolean\n disconnect(): void\n unref(): void\n ref(): void\n}\n\n// Duplicated from Node.js stream.Writable\ninterface WritableStreamType {\n writable: boolean\n writableEnded: boolean\n writableFinished: boolean\n writableHighWaterMark: number\n writableLength: number\n writableObjectMode: boolean\n writableCorked: number\n destroyed: boolean\n write(\n // biome-ignore lint/suspicious/noExplicitAny: Stream chunk can be any type.\n chunk: any,\n encoding?: BufferEncoding | undefined,\n callback?: (error?: Error | null) => void,\n ): boolean\n // biome-ignore lint/suspicious/noExplicitAny: Stream chunk can be any type.\n write(chunk: any, callback?: (error?: Error | null) => void): boolean\n end(cb?: () => void): this\n // biome-ignore lint/suspicious/noExplicitAny: Stream chunk can be any type.\n end(chunk: any, cb?: () => void): this\n // biome-ignore lint/suspicious/noExplicitAny: Stream chunk can be any type.\n end(chunk: any, encoding?: BufferEncoding | undefined, cb?: () => void): this\n cork(): void\n uncork(): void\n destroy(error?: Error | undefined): this\n}\n\n/**\n * Spawn a child process with enhanced error handling and output capture.\n */\nexport type SpawnOptions = import('./objects').Remap<\n NodeSpawnOptions & {\n spinner?: import('./spinner').Spinner | undefined\n stdioString?: boolean\n stripAnsi?: boolean\n }\n>\nexport type SpawnResult = PromiseSpawnResult\nexport type SpawnStdioResult = {\n cmd: string\n args: string[] | readonly string[]\n code: number\n signal: NodeJS.Signals | null\n stdout: string | Buffer\n stderr: string | Buffer\n}\n\n/**\n * Spawn a child process and return a promise that resolves when it completes.\n *\n * SECURITY: This function uses array-based arguments which prevent command injection.\n * Arguments in the `args` array are passed directly to the OS without shell\n * interpretation. Shell metacharacters (;|&$()`) are treated as literal strings,\n * not as commands or operators. This is the PRIMARY SECURITY DEFENSE.\n *\n * Even when shell: true is used (on Windows for .cmd/.bat execution), the array-based\n * approach remains secure because Node.js properly escapes each argument before passing\n * to the shell.\n *\n * @param cmd - Command to execute (not user-controlled)\n * @param args - Array of arguments (safe even with user input due to array-based passing)\n * @param options - Spawn options\n * @param extra - Extra options for promise-spawn\n *\n * @example\n * // \u2714 DO THIS - Array-based arguments\n * spawn('git', ['commit', '-m', userMessage])\n * // Each argument is properly escaped, even if userMessage = \"foo; rm -rf /\"\n *\n * @example\n * // \u2716 NEVER DO THIS - String concatenation\n * spawn(`git commit -m \"${userMessage}\"`, { shell: true })\n * // Vulnerable to injection if userMessage = '\"; rm -rf / #'\n */\nexport function spawn(\n cmd: string,\n args?: string[] | readonly string[],\n options?: SpawnOptions | undefined,\n extra?: SpawnExtra | undefined,\n): SpawnResult {\n // Windows cmd.exe command resolution for .cmd/.bat/.ps1 files:\n //\n // When shell: true is used on Windows with script files (.cmd, .bat, .ps1),\n // cmd.exe can have issues executing full paths. The solution is to use just\n // the command basename without extension and let cmd.exe find it via PATH.\n //\n // How cmd.exe resolves commands:\n // 1. Searches current directory first\n // 2. Then searches each directory in PATH environment variable\n // 3. For each directory, tries extensions from PATHEXT (.COM, .EXE, .BAT, .CMD, etc.)\n // 4. Executes the first match found\n //\n // Example: Given 'C:\\pnpm\\pnpm.cmd' with shell: true\n // 1. Extract basename without extension: 'pnpm'\n // 2. cmd.exe searches PATH directories for 'pnpm'\n // 3. PATHEXT causes it to try 'pnpm.com', 'pnpm.exe', 'pnpm.bat', 'pnpm.cmd', etc.\n // 4. Finds and executes 'C:\\pnpm\\pnpm.cmd'\n //\n // This approach is consistent with how other tools handle Windows execution:\n // - npm's promise-spawn: uses which.sync() to find commands in PATH\n // - cross-spawn: spawns cmd.exe with escaped arguments\n // - execa: uses cross-spawn under the hood for Windows support\n //\n // See: https://github.com/nodejs/node/issues/3675\n const shell = getOwn(options, 'shell')\n // Inline WIN32 constant for coverage mode compatibility\n const WIN32 = process.platform === 'win32'\n let actualCmd = cmd\n if (WIN32 && shell && windowsScriptExtRegExp.test(actualCmd)) {\n const path = getPath()\n // Extract just the command name without path and extension.\n actualCmd = path.basename(actualCmd, path.extname(actualCmd))\n }\n const {\n spinner: optionsSpinner = spinner,\n stripAnsi: shouldStripAnsi = true,\n ...spawnOptions\n } = { __proto__: null, ...options } as SpawnOptions\n const spinnerInstance = optionsSpinner\n const { env, stdio, stdioString = true } = spawnOptions\n // The stdio option can be a string or an array.\n // https://nodejs.org/api/child_process.html#optionsstdio\n const wasSpinning = !!spinnerInstance?.isSpinning\n const shouldStopSpinner =\n wasSpinning && !isStdioType(stdio, 'ignore') && !isStdioType(stdio, 'pipe')\n const shouldRestartSpinner = shouldStopSpinner\n if (shouldStopSpinner) {\n spinnerInstance.stop()\n }\n const npmCliPromiseSpawn = getNpmcliPromiseSpawn()\n // Use __proto__: null to prevent prototype pollution when passing to\n // third-party code, Node.js built-ins, or JavaScript built-in methods.\n // https://github.com/npm/promise-spawn\n // https://github.com/nodejs/node/blob/v24.0.1/lib/child_process.js#L674-L678\n const promiseSpawnOpts = {\n __proto__: null,\n cwd: typeof spawnOptions.cwd === 'string' ? spawnOptions.cwd : undefined,\n env: {\n __proto__: null,\n ...process.env,\n ...env,\n } as unknown as NodeJS.ProcessEnv,\n signal: abortSignal,\n stdio: spawnOptions.stdio,\n stdioString,\n shell: spawnOptions.shell,\n timeout: spawnOptions.timeout,\n uid: spawnOptions.uid,\n gid: spawnOptions.gid,\n } as unknown as PromiseSpawnOptions\n const spawnPromise = npmCliPromiseSpawn(\n actualCmd,\n args ? [...args] : [],\n promiseSpawnOpts as Parameters<typeof npmCliPromiseSpawn>[2],\n extra,\n )\n const oldSpawnPromise = spawnPromise\n let newSpawnPromise: PromiseSpawnResult\n if (shouldStripAnsi && stdioString) {\n newSpawnPromise = spawnPromise\n .then(result => {\n const strippedResult = stripAnsiFromSpawnResult(result)\n // Add exitCode as an alias for code.\n if ('code' in (strippedResult as { code?: number })) {\n ;(strippedResult as { code: number; exitCode: number }).exitCode = (\n strippedResult as { code: number }\n ).code\n }\n return strippedResult\n })\n .catch(error => {\n throw stripAnsiFromSpawnResult(error)\n }) as PromiseSpawnResult\n } else {\n newSpawnPromise = spawnPromise.then(result => {\n // Add exitCode as an alias for code.\n if ('code' in result) {\n const res = result as typeof result & { exitCode: number }\n res.exitCode = result.code\n return res\n }\n return result\n }) as PromiseSpawnResult\n }\n if (shouldRestartSpinner) {\n newSpawnPromise = newSpawnPromise.finally(() => {\n spinnerInstance.start()\n }) as PromiseSpawnResult\n }\n // Copy process and stdin properties from original promise\n ;(newSpawnPromise as unknown as PromiseSpawnResult).process =\n oldSpawnPromise.process\n ;(newSpawnPromise as unknown as PromiseSpawnResult).stdin = (\n oldSpawnPromise as unknown as PromiseSpawnResult\n ).stdin\n return newSpawnPromise as SpawnResult\n}\n\n/*@__NO_SIDE_EFFECTS__*/\n/**\n * Synchronously spawn a child process.\n */\nexport type SpawnSyncOptions = Omit<SpawnOptions, 'spinner'>\nexport function spawnSync(\n cmd: string,\n args?: string[] | readonly string[],\n options?: SpawnSyncOptions | undefined,\n): SpawnSyncReturns<string | Buffer> {\n // Windows cmd.exe command resolution for .cmd/.bat/.ps1 files:\n // See spawn() function above for detailed explanation of this approach.\n const shell = getOwn(options, 'shell')\n // Inline WIN32 constant for coverage mode compatibility\n const WIN32 = process.platform === 'win32'\n let actualCmd = cmd\n if (WIN32 && shell && windowsScriptExtRegExp.test(actualCmd)) {\n const path = getPath()\n // Extract just the command name without path and extension.\n actualCmd = path.basename(actualCmd, path.extname(actualCmd))\n }\n const { stripAnsi: shouldStripAnsi = true, ...rawSpawnOptions } = {\n __proto__: null,\n ...options,\n } as SpawnSyncOptions\n const { stdioString: rawStdioString = true } = rawSpawnOptions\n const rawEncoding = rawStdioString ? 'utf8' : 'buffer'\n const spawnOptions = {\n encoding: rawEncoding,\n ...rawSpawnOptions,\n } as NodeSpawnOptions & { encoding: BufferEncoding | 'buffer' }\n const stdioString = spawnOptions.encoding !== 'buffer'\n const result = getChildProcess().spawnSync(actualCmd, args, spawnOptions)\n if (stdioString) {\n const { stderr, stdout } = result\n if (stdout) {\n result.stdout = stdout.toString().trim()\n }\n if (stderr) {\n result.stderr = stderr.toString().trim()\n }\n }\n return (\n shouldStripAnsi && stdioString ? stripAnsiFromSpawnResult(result) : result\n ) as SpawnSyncReturns<string | Buffer>\n}\n"],
5
- "mappings": ";;;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,KAAK,IAAI;AAC/C,QAAM,cAAc,iBAAiB,SAAS;AAC9C,QAAM,eAAe;AAAA,IACnB,UAAU;AAAA,IACV,GAAG;AAAA,EACL;AACA,QAAM,cAAc,aAAa,aAAa;AAC9C,QAAM,UAAS,gCAAgB,GAAE,UAAU,WAAW,MAAM,YAAY;AACxE,MAAI,aAAa;AACf,UAAM,EAAE,QAAQ,OAAO,IAAI;AAC3B,QAAI,QAAQ;AACV,aAAO,SAAS,OAAO,SAAS,EAAE,KAAK;AAAA,IACzC;AACA,QAAI,QAAQ;AACV,aAAO,SAAS,OAAO,SAAS,EAAE,KAAK;AAAA,IACzC;AAAA,EACF;AACA,SACE,mBAAmB,cAAc,yCAAyB,MAAM,IAAI;AAExE;",
4
+ "sourcesContent": ["/**\n * @fileoverview Child process spawning utilities with cross-platform support.\n * Provides enhanced spawn functionality with stdio handling and error management.\n *\n * SECURITY: Array-Based Arguments Prevent Command Injection\n *\n * This module uses array-based arguments for all command execution, which is the\n * PRIMARY DEFENSE against command injection attacks. When you pass arguments as\n * an array to spawn():\n *\n * spawn('npx', ['sfw', tool, ...args], { shell: true })\n *\n * Node.js handles escaping automatically. Each argument is passed directly to the\n * OS without shell interpretation. Shell metacharacters like ; | & $ ( ) ` are\n * treated as LITERAL STRINGS, not as commands. This approach is secure even when\n * shell: true is used on Windows for .cmd/.bat file resolution.\n *\n * UNSAFE ALTERNATIVE (not used in this codebase):\n * spawn(`npx sfw ${tool} ${args.join(' ')}`, { shell: true }) // \u2716 VULNERABLE\n *\n * String concatenation allows injection. For example, if tool = \"foo; rm -rf /\",\n * the shell would execute both commands. Array-based arguments prevent this.\n *\n * References:\n * - https://nodejs.org/api/child_process.html#child_processspawncommand-args-options\n * - https://cheatsheetseries.owasp.org/cheatsheets/Nodejs_Security_Cheat_Sheet.html\n */\n\nimport { getAbortSignal, getSpinner } from '#constants/process'\n\nimport { isArray } from './arrays'\n\nconst abortSignal = getAbortSignal()\nconst spinner = getSpinner()\n\nimport { getOwn, hasOwn } from './objects'\nimport { stripAnsi } from './strings'\n\n// Define BufferEncoding type for TypeScript compatibility.\ntype BufferEncoding = globalThis.BufferEncoding\n\nconst windowsScriptExtRegExp = /\\.(?:cmd|bat|ps1)$/i\n\nlet _child_process: typeof import('node:child_process') | undefined\n/**\n * Lazily load the `child_process` module to avoid Webpack bundling issues.\n *\n * @returns The Node.js `child_process` module\n *\n * @example\n * const childProcess = getChildProcess()\n * childProcess.spawnSync('ls', ['-la'])\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getChildProcess() {\n if (_child_process === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _child_process = /*@__PURE__*/ require('node:child_process')\n }\n return _child_process as typeof import('node:child_process')\n}\n\n/**\n * Options for spawning a child process with promise-based completion.\n *\n * @property {string | undefined} cwd - Current working directory for the process\n * @property {boolean | undefined} stdioString - Convert stdio output to strings (default: `true`)\n * @property {StdioType | undefined} stdio - Stdio configuration (`'pipe'`, `'ignore'`, `'inherit'`, or array)\n * @property {NodeJS.ProcessEnv | undefined} env - Environment variables for the process\n * @property {boolean | string | undefined} shell - Whether to run command in shell, or path to shell\n * @property {AbortSignal | undefined} signal - Signal to abort the process\n * @property {number | undefined} timeout - Maximum time in milliseconds before killing the process\n * @property {number | undefined} uid - User identity of the process (POSIX only)\n * @property {number | undefined} gid - Group identity of the process (POSIX only)\n */\nexport type PromiseSpawnOptions = {\n cwd?: string | undefined\n stdioString?: boolean | undefined\n stdio?: StdioType | undefined\n env?: NodeJS.ProcessEnv | undefined\n shell?: boolean | string | undefined\n signal?: AbortSignal | undefined\n timeout?: number | undefined\n uid?: number | undefined\n gid?: number | undefined\n}\n\n/**\n * Result returned by {@link spawn} when the child process completes.\n * This is a Promise that resolves with process exit information and output,\n * with additional properties for accessing the running process and stdin stream.\n *\n * @property {ChildProcessType} process - The running child process instance\n * @property {WritableStreamType | null} stdin - Writable stream for process stdin, or `null` if not piped\n *\n * @example\n * const result = spawn('echo', ['hello'])\n * result.stdin?.write('additional input\\n')\n * const { code, stdout } = await result\n * console.log(stdout) // 'hello'\n */\nexport type PromiseSpawnResult = Promise<{\n cmd: string\n args: string[] | readonly string[]\n code: number\n signal: NodeJS.Signals | null\n stdout: string | Buffer\n stderr: string | Buffer\n}> & {\n process: ChildProcessType\n stdin: WritableStreamType | null\n}\n\nlet _npmCliPromiseSpawn:\n | ((\n cmd: string,\n args: string[],\n options?: PromiseSpawnOptions | undefined,\n extra?: SpawnExtra | undefined,\n ) => PromiseSpawnResult)\n | undefined\n/**\n * Lazily load the `@npmcli/promise-spawn` module for async process spawning.\n *\n * @returns The promise-spawn module that provides Promise-based spawn functionality\n *\n * @example\n * const promiseSpawn = getNpmcliPromiseSpawn()\n * await promiseSpawn('git', ['status'])\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getNpmcliPromiseSpawn() {\n if (_npmCliPromiseSpawn === undefined) {\n _npmCliPromiseSpawn = /*@__PURE__*/ require('./external/@npmcli/promise-spawn')\n }\n return _npmCliPromiseSpawn as unknown as typeof import('@npmcli/promise-spawn')\n}\n\nlet _path: typeof import('node:path') | undefined\n/**\n * Lazily load the `path` module to avoid Webpack bundling issues.\n *\n * @returns The Node.js `path` module\n *\n * @example\n * const path = getPath()\n * const basename = path.basename('/foo/bar.txt')\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction getPath() {\n if (_path === undefined) {\n // Use non-'node:' prefixed require to avoid Webpack errors.\n\n _path = /*@__PURE__*/ require('node:path')\n }\n return _path as typeof import('node:path')\n}\n\n/**\n * Error object thrown when a spawned process fails.\n * Extends the standard Error with process-specific information including exit code,\n * signal, command details, and captured output.\n *\n * @property {string[]} args - Arguments passed to the command\n * @property {string} cmd - Command that was executed\n * @property {number} code - Process exit code\n * @property {string} name - Error name (typically `'Error'`)\n * @property {string} message - Error message describing the failure\n * @property {NodeJS.Signals | null} signal - Signal that terminated the process, if any\n * @property {string} stack - Stack trace of the error\n * @property {string | Buffer} stderr - Standard error output from the process\n * @property {string | Buffer} stdout - Standard output from the process\n *\n * @example\n * try {\n * await spawn('exit', ['1'])\n * } catch (error) {\n * if (isSpawnError(error)) {\n * console.error(`Command failed with code ${error.code}`)\n * console.error(`stderr: ${error.stderr}`)\n * }\n * }\n */\nexport type SpawnError = {\n args: string[]\n cmd: string\n code: number\n name: string\n message: string\n signal: NodeJS.Signals | null\n stack: string\n stderr: string | Buffer\n stdout: string | Buffer\n}\n\n/**\n * Spawn error variant where stdout and stderr are guaranteed to be strings.\n * This type is used when `stdioString: true` is set in spawn options.\n *\n * @property {string} stdout - Standard output as a string\n * @property {string} stderr - Standard error as a string\n */\nexport type SpawnErrorWithOutputString = SpawnError & {\n stdout: string\n stderr: string\n}\n\n/**\n * Spawn error variant where stdout and stderr are guaranteed to be Buffers.\n * This type is used when `stdioString: false` is set in spawn options.\n *\n * @property {Buffer} stdout - Standard output as a Buffer\n * @property {Buffer} stderr - Standard error as a Buffer\n */\nexport type SpawnErrorWithOutputBuffer = SpawnError & {\n stdout: Buffer\n stderr: Buffer\n}\n\n/**\n * Extra options passed to the underlying promise-spawn implementation.\n * This is an open-ended object for passing additional metadata or configuration.\n */\nexport type SpawnExtra = Record<string, unknown>\n\n/**\n * Valid values for individual stdio streams.\n * - `'pipe'` - Creates a pipe between child and parent (default)\n * - `'ignore'` - Ignores the stream\n * - `'inherit'` - Uses parent's stream\n * - `'overlapped'` - Windows-specific overlapped I/O\n */\nexport type IOType = 'pipe' | 'ignore' | 'inherit' | 'overlapped'\n\n/**\n * Configuration for process stdio (stdin, stdout, stderr) streams.\n * Can be a single value applied to all streams, or an array specifying each stream individually.\n * - `'ipc'` - Creates an IPC channel for communication with the parent\n *\n * @example\n * // All streams piped\n * stdio: 'pipe'\n *\n * @example\n * // Custom configuration per stream: [stdin, stdout, stderr]\n * stdio: ['ignore', 'pipe', 'pipe']\n */\nexport type StdioType = IOType | 'ipc' | Array<IOType | 'ipc'>\n\n/**\n * Result object returned by {@link spawnSync} when the child process completes synchronously.\n *\n * @template T - Type of stdout/stderr (string or Buffer)\n * @property {number} pid - Process ID of the spawned child\n * @property {Array<T | null>} output - Array containing stdout/stderr values\n * @property {T} stdout - Standard output from the process\n * @property {T} stderr - Standard error from the process\n * @property {number | null} status - Exit code, or `null` if killed by signal\n * @property {NodeJS.Signals | null} signal - Signal that terminated the process, or `null`\n * @property {Error | undefined} error - Error object if the spawn failed\n */\nexport interface SpawnSyncReturns<T> {\n pid: number\n output: Array<T | null>\n stdout: T\n stderr: T\n status: number | null\n signal: NodeJS.Signals | null\n error?: Error | undefined\n}\n\n/**\n * Check if a value is a spawn error with expected error properties.\n * Tests for common error properties from child process failures.\n *\n * @param {unknown} value - Value to check\n * @returns {boolean} `true` if the value has spawn error properties\n *\n * @example\n * try {\n * await spawn('nonexistent-command')\n * } catch (error) {\n * if (isSpawnError(error)) {\n * console.error(`Spawn failed: ${error.code}`)\n * }\n * }\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isSpawnError(value: unknown): value is SpawnError {\n if (value === null || typeof value !== 'object') {\n return false\n }\n // Check for spawn-specific error properties.\n const err = value as Record<string, unknown>\n return (\n (hasOwn(err, 'code') && typeof err['code'] !== 'undefined') ||\n (hasOwn(err, 'errno') && typeof err['errno'] !== 'undefined') ||\n (hasOwn(err, 'syscall') && typeof err['syscall'] === 'string')\n )\n}\n\n/**\n * Check if stdio configuration matches a specific type.\n * When called with one argument, validates if it's a valid stdio type.\n * When called with two arguments, checks if the stdio config matches the specified type.\n *\n * @param {string | string[]} stdio - Stdio configuration to check\n * @param {StdioType | undefined} type - Expected stdio type (optional)\n * @returns {boolean} `true` if stdio matches the type or is valid\n *\n * @example\n * // Check if valid stdio type\n * isStdioType('pipe') // true\n * isStdioType('invalid') // false\n *\n * @example\n * // Check if stdio matches specific type\n * isStdioType('pipe', 'pipe') // true\n * isStdioType(['pipe', 'pipe', 'pipe'], 'pipe') // true\n * isStdioType('ignore', 'pipe') // false\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isStdioType(\n stdio: string | string[],\n type?: StdioType | undefined,\n): boolean {\n // If called with one argument, check if it's a valid stdio type.\n // biome-ignore lint/complexity/noArguments: Function overload detection for single vs two-arg calls.\n if (arguments.length === 1) {\n const validTypes = ['pipe', 'ignore', 'inherit', 'overlapped']\n return typeof stdio === 'string' && validTypes.includes(stdio)\n }\n // Original two-argument behavior.\n return (\n stdio === type ||\n ((stdio === null || stdio === undefined) && type === 'pipe') ||\n (isArray(stdio) &&\n stdio.length > 2 &&\n stdio[0] === type &&\n stdio[1] === type &&\n stdio[2] === type)\n )\n}\n\n/**\n * Strip ANSI escape codes from spawn result stdout and stderr.\n * Modifies the result object in place to remove color codes and formatting.\n *\n * @param {unknown} result - Spawn result object with stdout/stderr properties\n * @returns {unknown} The modified result object\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction stripAnsiFromSpawnResult(result: unknown): unknown {\n const res = result as {\n stdout?: string | Buffer\n stderr?: string | Buffer\n }\n const { stderr, stdout } = res\n if (typeof stdout === 'string') {\n res.stdout = stripAnsi(stdout)\n }\n if (typeof stderr === 'string') {\n res.stderr = stripAnsi(stderr)\n }\n return res\n}\n\n/*@__NO_SIDE_EFFECTS__*/\n// Duplicated from Node.js child_process.SpawnOptions\n// These are the options passed to child_process.spawn()\ninterface NodeSpawnOptions {\n cwd?: string | URL | undefined\n env?: NodeJS.ProcessEnv | undefined\n argv0?: string | undefined\n stdio?: any\n detached?: boolean | undefined\n uid?: number | undefined\n gid?: number | undefined\n serialization?: 'json' | 'advanced' | undefined\n shell?: boolean | string | undefined\n windowsVerbatimArguments?: boolean | undefined\n windowsHide?: boolean | undefined\n signal?: AbortSignal | undefined\n timeout?: number | undefined\n killSignal?: NodeJS.Signals | number | undefined\n}\n\n// Duplicated from Node.js child_process.ChildProcess\n// This represents a spawned child process\ninterface ChildProcessType {\n stdin: NodeJS.WritableStream | null\n stdout: NodeJS.ReadableStream | null\n stderr: NodeJS.ReadableStream | null\n readonly channel?: any\n readonly stdio: [\n NodeJS.WritableStream | null,\n NodeJS.ReadableStream | null,\n NodeJS.ReadableStream | null,\n NodeJS.ReadableStream | NodeJS.WritableStream | null | undefined,\n NodeJS.ReadableStream | NodeJS.WritableStream | null | undefined,\n ]\n readonly killed: boolean\n readonly pid?: number | undefined\n readonly connected: boolean\n readonly exitCode: number | null\n readonly signalCode: NodeJS.Signals | null\n readonly spawnargs: string[]\n readonly spawnfile: string\n kill(signal?: NodeJS.Signals | number): boolean\n send(message: any, callback?: (error: Error | null) => void): boolean\n send(\n message: any,\n sendHandle?: any | undefined,\n callback?: (error: Error | null) => void,\n ): boolean\n send(\n message: any,\n sendHandle?: any | undefined,\n options?: any | undefined,\n callback?: (error: Error | null) => void,\n ): boolean\n disconnect(): void\n unref(): void\n ref(): void\n}\n\n// Duplicated from Node.js stream.Writable\ninterface WritableStreamType {\n writable: boolean\n writableEnded: boolean\n writableFinished: boolean\n writableHighWaterMark: number\n writableLength: number\n writableObjectMode: boolean\n writableCorked: number\n destroyed: boolean\n write(\n chunk: any,\n encoding?: BufferEncoding | undefined,\n callback?: (error?: Error | null) => void,\n ): boolean\n write(chunk: any, callback?: (error?: Error | null) => void): boolean\n end(cb?: () => void): this\n end(chunk: any, cb?: () => void): this\n end(chunk: any, encoding?: BufferEncoding | undefined, cb?: () => void): this\n cork(): void\n uncork(): void\n destroy(error?: Error | undefined): this\n}\n\n/**\n * Options for spawning a child process with {@link spawn}.\n * Extends Node.js spawn options with additional Socket-specific functionality.\n *\n * @property {import('./spinner').Spinner | undefined} spinner - Spinner instance to pause during execution\n * @property {boolean | undefined} stdioString - Convert output to strings (default: `true`)\n * @property {boolean | undefined} stripAnsi - Remove ANSI codes from output (default: `true`)\n * @property {string | URL | undefined} cwd - Current working directory\n * @property {NodeJS.ProcessEnv | undefined} env - Environment variables\n * @property {StdioType | undefined} stdio - Stdio configuration\n * @property {boolean | string | undefined} shell - Run command in shell\n * @property {number | undefined} timeout - Timeout in milliseconds\n * @property {AbortSignal | undefined} signal - Abort signal\n * @property {number | undefined} uid - User identity (POSIX)\n * @property {number | undefined} gid - Group identity (POSIX)\n */\nexport type SpawnOptions = import('./objects').Remap<\n NodeSpawnOptions & {\n spinner?: import('./spinner').Spinner | undefined\n stdioString?: boolean\n stripAnsi?: boolean\n }\n>\nexport type SpawnResult = PromiseSpawnResult\n/**\n * Result object returned when a spawned process completes.\n *\n * @property {string} cmd - Command that was executed\n * @property {string[] | readonly string[]} args - Arguments passed to the command\n * @property {number} code - Process exit code\n * @property {NodeJS.Signals | null} signal - Signal that terminated the process, if any\n * @property {string | Buffer} stdout - Standard output (string if `stdioString: true`, Buffer otherwise)\n * @property {string | Buffer} stderr - Standard error (string if `stdioString: true`, Buffer otherwise)\n */\nexport type SpawnStdioResult = {\n cmd: string\n args: string[] | readonly string[]\n code: number\n signal: NodeJS.Signals | null\n stdout: string | Buffer\n stderr: string | Buffer\n}\n\n/**\n * Spawn a child process and return a promise that resolves when it completes.\n * Provides enhanced error handling, output capture, and cross-platform support.\n *\n * SECURITY: This function uses array-based arguments which prevent command injection.\n * Arguments in the `args` array are passed directly to the OS without shell\n * interpretation. Shell metacharacters (;|&$()`) are treated as literal strings,\n * not as commands or operators. This is the PRIMARY SECURITY DEFENSE.\n *\n * Even when shell: true is used (on Windows for .cmd/.bat execution), the array-based\n * approach remains secure because Node.js properly escapes each argument before passing\n * to the shell.\n *\n * @param {string} cmd - Command to execute (not user-controlled)\n * @param {string[] | readonly string[] | undefined} args - Array of arguments (safe even with user input)\n * @param {SpawnOptions | undefined} options - Spawn options for process configuration\n * @param {SpawnExtra | undefined} extra - Extra options for promise-spawn\n * @returns {SpawnResult} Promise that resolves with process exit information\n *\n * @throws {SpawnError} When the process exits with non-zero code or is terminated by signal\n *\n * @example\n * // Basic usage - spawn and wait for completion\n * const result = await spawn('git', ['status'])\n * console.log(result.stdout)\n *\n * @example\n * // With options - set working directory and environment\n * const result = await spawn('npm', ['install'], {\n * cwd: '/path/to/project',\n * env: { NODE_ENV: 'production' }\n * })\n *\n * @example\n * // \u2714 DO THIS - Array-based arguments (safe)\n * spawn('git', ['commit', '-m', userMessage])\n * // Each argument is properly escaped, even if userMessage = \"foo; rm -rf /\"\n *\n * @example\n * // \u2716 NEVER DO THIS - String concatenation (vulnerable)\n * spawn(`git commit -m \"${userMessage}\"`, { shell: true })\n * // Vulnerable to injection if userMessage = '\"; rm -rf / #'\n *\n * @example\n * // Access stdin for interactive processes\n * const result = spawn('cat', [])\n * result.stdin?.write('Hello\\n')\n * result.stdin?.end()\n * const { stdout } = await result\n * console.log(stdout) // 'Hello'\n *\n * @example\n * // Handle errors with exit codes\n * try {\n * await spawn('exit', ['1'])\n * } catch (error) {\n * if (isSpawnError(error)) {\n * console.error(`Failed with code ${error.code}`)\n * console.error(error.stderr)\n * }\n * }\n */\nexport function spawn(\n cmd: string,\n args?: string[] | readonly string[],\n options?: SpawnOptions | undefined,\n extra?: SpawnExtra | undefined,\n): SpawnResult {\n // Windows cmd.exe command resolution for .cmd/.bat/.ps1 files:\n //\n // When shell: true is used on Windows with script files (.cmd, .bat, .ps1),\n // cmd.exe can have issues executing full paths. The solution is to use just\n // the command basename without extension and let cmd.exe find it via PATH.\n //\n // How cmd.exe resolves commands:\n // 1. Searches current directory first\n // 2. Then searches each directory in PATH environment variable\n // 3. For each directory, tries extensions from PATHEXT (.COM, .EXE, .BAT, .CMD, etc.)\n // 4. Executes the first match found\n //\n // Example: Given 'C:\\pnpm\\pnpm.cmd' with shell: true\n // 1. Extract basename without extension: 'pnpm'\n // 2. cmd.exe searches PATH directories for 'pnpm'\n // 3. PATHEXT causes it to try 'pnpm.com', 'pnpm.exe', 'pnpm.bat', 'pnpm.cmd', etc.\n // 4. Finds and executes 'C:\\pnpm\\pnpm.cmd'\n //\n // This approach is consistent with how other tools handle Windows execution:\n // - npm's promise-spawn: uses which.sync() to find commands in PATH\n // - cross-spawn: spawns cmd.exe with escaped arguments\n // - execa: uses cross-spawn under the hood for Windows support\n //\n // See: https://github.com/nodejs/node/issues/3675\n const shell = getOwn(options, 'shell')\n // Inline WIN32 constant for coverage mode compatibility\n const WIN32 = process.platform === 'win32'\n let actualCmd = cmd\n if (WIN32 && shell && windowsScriptExtRegExp.test(actualCmd)) {\n const path = getPath()\n // Extract just the command name without path and extension.\n actualCmd = path.basename(actualCmd, path.extname(actualCmd))\n }\n const {\n spinner: optionsSpinner = spinner,\n stripAnsi: shouldStripAnsi = true,\n ...spawnOptions\n } = { __proto__: null, ...options } as SpawnOptions\n const spinnerInstance = optionsSpinner\n const { env, stdio, stdioString = true } = spawnOptions\n // The stdio option can be a string or an array.\n // https://nodejs.org/api/child_process.html#optionsstdio\n const wasSpinning = !!spinnerInstance?.isSpinning\n const shouldStopSpinner =\n wasSpinning && !isStdioType(stdio, 'ignore') && !isStdioType(stdio, 'pipe')\n const shouldRestartSpinner = shouldStopSpinner\n if (shouldStopSpinner) {\n spinnerInstance.stop()\n }\n const npmCliPromiseSpawn = getNpmcliPromiseSpawn()\n // Use __proto__: null to prevent prototype pollution when passing to\n // third-party code, Node.js built-ins, or JavaScript built-in methods.\n // https://github.com/npm/promise-spawn\n // https://github.com/nodejs/node/blob/v24.0.1/lib/child_process.js#L674-L678\n const promiseSpawnOpts = {\n __proto__: null,\n cwd: typeof spawnOptions.cwd === 'string' ? spawnOptions.cwd : undefined,\n env: {\n __proto__: null,\n ...process.env,\n ...env,\n } as unknown as NodeJS.ProcessEnv,\n signal: abortSignal,\n stdio: spawnOptions.stdio,\n stdioString,\n shell: spawnOptions.shell,\n timeout: spawnOptions.timeout,\n uid: spawnOptions.uid,\n gid: spawnOptions.gid,\n } as unknown as PromiseSpawnOptions\n const spawnPromise = npmCliPromiseSpawn(\n actualCmd,\n args ? [...args] : [],\n promiseSpawnOpts as Parameters<typeof npmCliPromiseSpawn>[2],\n extra,\n )\n const oldSpawnPromise = spawnPromise\n let newSpawnPromise: PromiseSpawnResult\n if (shouldStripAnsi && stdioString) {\n newSpawnPromise = spawnPromise\n .then(result => {\n const strippedResult = stripAnsiFromSpawnResult(result)\n // Add exitCode as an alias for code.\n if ('code' in (strippedResult as { code?: number })) {\n ;(strippedResult as { code: number; exitCode: number }).exitCode = (\n strippedResult as { code: number }\n ).code\n }\n return strippedResult\n })\n .catch(error => {\n throw stripAnsiFromSpawnResult(error)\n }) as PromiseSpawnResult\n } else {\n newSpawnPromise = spawnPromise.then(result => {\n // Add exitCode as an alias for code.\n if ('code' in result) {\n const res = result as typeof result & { exitCode: number }\n res.exitCode = result.code\n return res\n }\n return result\n }) as PromiseSpawnResult\n }\n if (shouldRestartSpinner) {\n newSpawnPromise = newSpawnPromise.finally(() => {\n spinnerInstance.start()\n }) as PromiseSpawnResult\n }\n // Copy process and stdin properties from original promise\n ;(newSpawnPromise as unknown as PromiseSpawnResult).process =\n oldSpawnPromise.process\n ;(newSpawnPromise as unknown as PromiseSpawnResult).stdin = (\n oldSpawnPromise as unknown as PromiseSpawnResult\n ).stdin\n return newSpawnPromise as SpawnResult\n}\n\n/*@__NO_SIDE_EFFECTS__*/\n/**\n * Options for synchronously spawning a child process with {@link spawnSync}.\n * Same as {@link SpawnOptions} but excludes the `spinner` property (not applicable for synchronous execution).\n */\nexport type SpawnSyncOptions = Omit<SpawnOptions, 'spinner'>\n\n/**\n * Synchronously spawn a child process and wait for it to complete.\n * Blocks execution until the process exits, returning all output and exit information.\n *\n * WARNING: This function blocks the event loop. Use {@link spawn} for async operations.\n *\n * @param {string} cmd - Command to execute\n * @param {string[] | readonly string[] | undefined} args - Array of arguments\n * @param {SpawnSyncOptions | undefined} options - Spawn options for process configuration\n * @returns {SpawnSyncReturns<string | Buffer>} Process result with exit code and captured output\n *\n * @example\n * // Basic synchronous spawn\n * const result = spawnSync('git', ['status'])\n * console.log(result.stdout)\n * console.log(result.status) // exit code\n *\n * @example\n * // With options\n * const result = spawnSync('npm', ['install'], {\n * cwd: '/path/to/project',\n * stdioString: true\n * })\n * if (result.status !== 0) {\n * console.error(result.stderr)\n * }\n *\n * @example\n * // Get raw buffer output\n * const result = spawnSync('cat', ['binary-file'], {\n * stdioString: false\n * })\n * console.log(result.stdout) // Buffer\n *\n * @example\n * // Handle process errors\n * const result = spawnSync('nonexistent-command')\n * if (result.error) {\n * console.error('Failed to spawn:', result.error)\n * }\n */\nexport function spawnSync(\n cmd: string,\n args?: string[] | readonly string[],\n options?: SpawnSyncOptions | undefined,\n): SpawnSyncReturns<string | Buffer> {\n // Windows cmd.exe command resolution for .cmd/.bat/.ps1 files:\n // See spawn() function above for detailed explanation of this approach.\n const shell = getOwn(options, 'shell')\n // Inline WIN32 constant for coverage mode compatibility\n const WIN32 = process.platform === 'win32'\n let actualCmd = cmd\n if (WIN32 && shell && windowsScriptExtRegExp.test(actualCmd)) {\n const path = getPath()\n // Extract just the command name without path and extension.\n actualCmd = path.basename(actualCmd, path.extname(actualCmd))\n }\n const { stripAnsi: shouldStripAnsi = true, ...rawSpawnOptions } = {\n __proto__: null,\n ...options,\n } as SpawnSyncOptions\n const { stdioString: rawStdioString = true } = rawSpawnOptions\n const rawEncoding = rawStdioString ? 'utf8' : 'buffer'\n const spawnOptions = {\n encoding: rawEncoding,\n ...rawSpawnOptions,\n } as NodeSpawnOptions & { encoding: BufferEncoding | 'buffer' }\n const stdioString = spawnOptions.encoding !== 'buffer'\n const result = getChildProcess().spawnSync(actualCmd, args, spawnOptions)\n if (stdioString) {\n const { stderr, stdout } = result\n if (stdout) {\n result.stdout = stdout.toString().trim()\n }\n if (stderr) {\n result.stderr = stderr.toString().trim()\n }\n }\n return (\n shouldStripAnsi && stdioString ? stripAnsiFromSpawnResult(result) : result\n ) as SpawnSyncReturns<string | Buffer>\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BA,qBAA2C;AAE3C,oBAAwB;AAKxB,qBAA+B;AAC/B,qBAA0B;AAJ1B,MAAM,kBAAc,+BAAe;AACnC,MAAM,cAAU,2BAAW;AAQ3B,MAAM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