@socketsecurity/lib 5.18.1 → 5.19.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 (305) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +6 -5
  3. package/dist/abort.d.ts +3 -0
  4. package/dist/abort.js +1 -0
  5. package/dist/agent.d.ts +66 -49
  6. package/dist/agent.js +51 -50
  7. package/dist/ansi.d.ts +2 -5
  8. package/dist/ansi.js +3 -2
  9. package/dist/archives.d.ts +25 -21
  10. package/dist/archives.js +35 -34
  11. package/dist/argv/flags.d.ts +100 -91
  12. package/dist/argv/flags.js +88 -87
  13. package/dist/argv/parse.d.ts +30 -40
  14. package/dist/argv/parse.js +33 -32
  15. package/dist/arrays.d.ts +4 -8
  16. package/dist/arrays.js +1 -0
  17. package/dist/bin.d.ts +7 -5
  18. package/dist/bin.js +52 -29
  19. package/dist/cacache.d.ts +13 -12
  20. package/dist/cacache.js +9 -8
  21. package/dist/cache-with-ttl.d.ts +53 -35
  22. package/dist/cache-with-ttl.js +1 -0
  23. package/dist/colors.d.ts +5 -5
  24. package/dist/colors.js +1 -0
  25. package/dist/constants/agents.d.ts +5 -9
  26. package/dist/constants/agents.js +3 -2
  27. package/dist/constants/core.d.ts +5 -10
  28. package/dist/constants/core.js +2 -1
  29. package/dist/constants/encoding.d.ts +3 -3
  30. package/dist/constants/encoding.js +1 -0
  31. package/dist/constants/github.d.ts +3 -3
  32. package/dist/constants/github.js +1 -0
  33. package/dist/constants/licenses.d.ts +9 -2
  34. package/dist/constants/licenses.js +1 -0
  35. package/dist/constants/lifecycle-script-names.js +1 -0
  36. package/dist/constants/maintained-node-versions.d.ts +3 -0
  37. package/dist/constants/maintained-node-versions.js +1 -0
  38. package/dist/constants/node.d.ts +125 -16
  39. package/dist/constants/node.js +74 -73
  40. package/dist/constants/package-default-node-range.d.ts +3 -1
  41. package/dist/constants/package-default-node-range.js +2 -1
  42. package/dist/constants/package-default-socket-categories.d.ts +0 -1
  43. package/dist/constants/package-default-socket-categories.js +1 -0
  44. package/dist/constants/packages.d.ts +12 -17
  45. package/dist/constants/packages.js +31 -16
  46. package/dist/constants/platform.d.ts +1 -2
  47. package/dist/constants/platform.js +2 -1
  48. package/dist/constants/process.d.ts +18 -0
  49. package/dist/constants/process.js +1 -0
  50. package/dist/constants/socket.d.ts +4 -10
  51. package/dist/constants/socket.js +2 -1
  52. package/dist/constants/testing.d.ts +3 -3
  53. package/dist/constants/testing.js +1 -0
  54. package/dist/constants/time.d.ts +3 -4
  55. package/dist/constants/time.js +1 -0
  56. package/dist/constants/typescript.d.ts +10 -3
  57. package/dist/constants/typescript.js +5 -4
  58. package/dist/cover/code.d.ts +3 -0
  59. package/dist/cover/code.js +12 -12
  60. package/dist/cover/formatters.d.ts +12 -9
  61. package/dist/cover/formatters.js +19 -18
  62. package/dist/cover/type.d.ts +3 -0
  63. package/dist/cover/type.js +1 -0
  64. package/dist/cover/types.js +1 -0
  65. package/dist/debug.d.ts +32 -47
  66. package/dist/debug.js +97 -96
  67. package/dist/dlx/arborist.d.ts +134 -0
  68. package/dist/dlx/arborist.js +177 -0
  69. package/dist/dlx/binary.d.ts +25 -9
  70. package/dist/dlx/binary.js +34 -12
  71. package/dist/dlx/cache.d.ts +1 -0
  72. package/dist/dlx/cache.js +2 -1
  73. package/dist/dlx/detect.d.ts +15 -0
  74. package/dist/dlx/detect.js +28 -20
  75. package/dist/dlx/dir.d.ts +1 -11
  76. package/dist/dlx/dir.js +2 -12
  77. package/dist/dlx/integrity.d.ts +86 -0
  78. package/dist/dlx/integrity.js +112 -0
  79. package/dist/dlx/lockfile.d.ts +115 -0
  80. package/dist/dlx/lockfile.js +139 -0
  81. package/dist/dlx/manifest.d.ts +26 -1
  82. package/dist/dlx/manifest.js +9 -6
  83. package/dist/dlx/package.d.ts +58 -3
  84. package/dist/dlx/package.js +101 -74
  85. package/dist/dlx/packages.d.ts +1 -11
  86. package/dist/dlx/packages.js +3 -14
  87. package/dist/dlx/paths.d.ts +1 -0
  88. package/dist/dlx/paths.js +2 -1
  89. package/dist/effects/pulse-frames.js +1 -0
  90. package/dist/effects/text-shimmer.d.ts +13 -2
  91. package/dist/effects/text-shimmer.js +50 -46
  92. package/dist/effects/types.js +1 -0
  93. package/dist/effects/ultra.js +1 -0
  94. package/dist/env/ci.d.ts +6 -1
  95. package/dist/env/ci.js +1 -0
  96. package/dist/env/debug.d.ts +5 -1
  97. package/dist/env/debug.js +1 -0
  98. package/dist/env/github.d.ts +19 -23
  99. package/dist/env/github.js +5 -4
  100. package/dist/env/helpers.d.ts +21 -9
  101. package/dist/env/helpers.js +5 -11
  102. package/dist/env/home.d.ts +17 -4
  103. package/dist/env/home.js +2 -1
  104. package/dist/env/locale.d.ts +4 -3
  105. package/dist/env/locale.js +1 -0
  106. package/dist/env/node-auth-token.d.ts +5 -1
  107. package/dist/env/node-auth-token.js +1 -0
  108. package/dist/env/node-env.d.ts +5 -1
  109. package/dist/env/node-env.js +1 -0
  110. package/dist/env/npm.d.ts +4 -5
  111. package/dist/env/npm.js +1 -0
  112. package/dist/env/package-manager.d.ts +4 -3
  113. package/dist/env/package-manager.js +2 -1
  114. package/dist/env/path.d.ts +5 -1
  115. package/dist/env/path.js +1 -0
  116. package/dist/env/pre-commit.d.ts +5 -1
  117. package/dist/env/pre-commit.js +1 -0
  118. package/dist/env/rewire.d.ts +10 -0
  119. package/dist/env/rewire.js +7 -5
  120. package/dist/env/shell.d.ts +5 -1
  121. package/dist/env/shell.js +1 -0
  122. package/dist/env/socket-cli-shadow.d.ts +4 -5
  123. package/dist/env/socket-cli-shadow.js +1 -0
  124. package/dist/env/socket-cli.d.ts +4 -14
  125. package/dist/env/socket-cli.js +1 -0
  126. package/dist/env/socket.d.ts +6 -18
  127. package/dist/env/socket.js +4 -3
  128. package/dist/env/temp-dir.d.ts +4 -3
  129. package/dist/env/temp-dir.js +1 -0
  130. package/dist/env/term.d.ts +5 -1
  131. package/dist/env/term.js +1 -0
  132. package/dist/env/test.d.ts +4 -3
  133. package/dist/env/test.js +1 -0
  134. package/dist/env/windows.d.ts +4 -4
  135. package/dist/env/windows.js +1 -0
  136. package/dist/env/xdg.d.ts +4 -3
  137. package/dist/env/xdg.js +1 -0
  138. package/dist/env.d.ts +83 -23
  139. package/dist/env.js +112 -80
  140. package/dist/errors.js +1 -0
  141. package/dist/external/@npmcli/package-json.js +9 -3968
  142. package/dist/external/@socketregistry/packageurl-js.js +2 -2
  143. package/dist/external/debug.js +162 -328
  144. package/dist/external/external-pack.js +3 -2835
  145. package/dist/external/npm-pack.js +13939 -33342
  146. package/dist/external/zod.js +160 -7558
  147. package/dist/fs.d.ts +92 -113
  148. package/dist/fs.js +35 -35
  149. package/dist/git.d.ts +170 -164
  150. package/dist/git.js +113 -87
  151. package/dist/github.d.ts +249 -227
  152. package/dist/github.js +82 -81
  153. package/dist/globs.d.ts +31 -17
  154. package/dist/globs.js +51 -58
  155. package/dist/http-request.d.ts +99 -99
  156. package/dist/http-request.js +182 -156
  157. package/dist/ipc-cli.d.ts +28 -0
  158. package/dist/{utils/get-ipc.js → ipc-cli.js} +4 -3
  159. package/dist/ipc.d.ts +9 -299
  160. package/dist/ipc.js +18 -204
  161. package/dist/json/edit.d.ts +3 -1
  162. package/dist/json/edit.js +30 -30
  163. package/dist/json/format.d.ts +36 -36
  164. package/dist/json/format.js +22 -21
  165. package/dist/json/parse.d.ts +4 -2
  166. package/dist/json/parse.js +1 -0
  167. package/dist/json/types.js +1 -0
  168. package/dist/{links/index.d.ts → links.d.ts} +6 -2
  169. package/dist/{links/index.js → links.js} +5 -4
  170. package/dist/logger.d.ts +4 -6
  171. package/dist/logger.js +61 -53
  172. package/dist/memoization.d.ts +52 -49
  173. package/dist/memoization.js +55 -33
  174. package/dist/objects.d.ts +25 -44
  175. package/dist/objects.js +2 -1
  176. package/dist/package-extensions.d.ts +6 -0
  177. package/dist/package-extensions.js +2 -1
  178. package/dist/packages/edit.d.ts +3 -5
  179. package/dist/packages/edit.js +4 -3
  180. package/dist/packages/exports.d.ts +11 -14
  181. package/dist/packages/exports.js +11 -10
  182. package/dist/packages/isolation.d.ts +4 -0
  183. package/dist/packages/isolation.js +20 -19
  184. package/dist/packages/licenses.d.ts +3 -10
  185. package/dist/packages/licenses.js +2 -1
  186. package/dist/packages/manifest.d.ts +3 -3
  187. package/dist/packages/manifest.js +1 -0
  188. package/dist/packages/normalize.d.ts +3 -4
  189. package/dist/packages/normalize.js +1 -0
  190. package/dist/packages/operations.d.ts +3 -10
  191. package/dist/packages/operations.js +1 -0
  192. package/dist/packages/provenance.d.ts +10 -8
  193. package/dist/packages/provenance.js +55 -54
  194. package/dist/packages/specs.d.ts +3 -5
  195. package/dist/packages/specs.js +1 -0
  196. package/dist/packages/validation.d.ts +3 -3
  197. package/dist/packages/validation.js +1 -0
  198. package/dist/packages.d.ts +2 -17
  199. package/dist/packages.js +2 -1
  200. package/dist/paths/dirnames.d.ts +0 -2
  201. package/dist/paths/dirnames.js +1 -0
  202. package/dist/paths/exts.d.ts +0 -1
  203. package/dist/paths/exts.js +1 -0
  204. package/dist/paths/filenames.d.ts +0 -1
  205. package/dist/paths/filenames.js +1 -0
  206. package/dist/paths/globs.d.ts +0 -1
  207. package/dist/paths/globs.js +1 -0
  208. package/dist/paths/normalize.d.ts +115 -123
  209. package/dist/paths/normalize.js +128 -127
  210. package/dist/paths/packages.d.ts +3 -2
  211. package/dist/paths/packages.js +2 -1
  212. package/dist/paths/rewire.d.ts +9 -0
  213. package/dist/paths/rewire.js +5 -3
  214. package/dist/paths/socket.d.ts +37 -23
  215. package/dist/paths/socket.js +26 -25
  216. package/dist/performance.d.ts +87 -84
  217. package/dist/performance.js +97 -96
  218. package/dist/process-lock.d.ts +41 -1
  219. package/dist/process-lock.js +24 -17
  220. package/dist/promise-queue.d.ts +6 -0
  221. package/dist/promise-queue.js +1 -0
  222. package/dist/promises.d.ts +40 -55
  223. package/dist/promises.js +12 -11
  224. package/dist/regexps.d.ts +0 -5
  225. package/dist/regexps.js +1 -0
  226. package/dist/releases/github.d.ts +59 -63
  227. package/dist/releases/github.js +95 -100
  228. package/dist/releases/socket-btm.d.ts +9 -2
  229. package/dist/releases/socket-btm.js +32 -25
  230. package/dist/sea.d.ts +5 -0
  231. package/dist/sea.js +1 -0
  232. package/dist/shadow.d.ts +4 -0
  233. package/dist/shadow.js +1 -0
  234. package/dist/signal-exit.d.ts +7 -7
  235. package/dist/signal-exit.js +46 -45
  236. package/dist/sorts.d.ts +5 -7
  237. package/dist/sorts.js +11 -10
  238. package/dist/spawn.d.ts +96 -77
  239. package/dist/spawn.js +39 -38
  240. package/dist/spinner.d.ts +21 -22
  241. package/dist/spinner.js +15 -11
  242. package/dist/ssri.d.ts +31 -36
  243. package/dist/ssri.js +15 -14
  244. package/dist/stdio/_stream.d.ts +31 -0
  245. package/dist/stdio/_stream.js +57 -0
  246. package/dist/stdio/divider.d.ts +40 -36
  247. package/dist/stdio/divider.js +10 -9
  248. package/dist/stdio/footer.d.ts +20 -0
  249. package/dist/stdio/footer.js +12 -2
  250. package/dist/stdio/header.d.ts +4 -16
  251. package/dist/stdio/header.js +1 -9
  252. package/dist/stdio/stderr.d.ts +51 -39
  253. package/dist/stdio/stderr.js +19 -22
  254. package/dist/stdio/stdout.d.ts +54 -52
  255. package/dist/stdio/stdout.js +35 -33
  256. package/dist/streams.d.ts +4 -3
  257. package/dist/streams.js +1 -0
  258. package/dist/strings.d.ts +31 -85
  259. package/dist/strings.js +5 -49
  260. package/dist/suppress-warnings.d.ts +32 -15
  261. package/dist/suppress-warnings.js +14 -13
  262. package/dist/tables.d.ts +30 -26
  263. package/dist/tables.js +24 -23
  264. package/dist/temporary-executor.d.ts +4 -0
  265. package/dist/temporary-executor.js +1 -0
  266. package/dist/themes/context.d.ts +30 -26
  267. package/dist/themes/context.js +19 -18
  268. package/dist/themes/index.d.ts +0 -4
  269. package/dist/themes/index.js +1 -0
  270. package/dist/themes/themes.d.ts +1 -1
  271. package/dist/themes/themes.js +1 -0
  272. package/dist/themes/types.js +1 -0
  273. package/dist/themes/utils.d.ts +46 -43
  274. package/dist/themes/utils.js +45 -44
  275. package/dist/types.d.ts +48 -52
  276. package/dist/types.js +35 -35
  277. package/dist/url.d.ts +48 -53
  278. package/dist/url.js +38 -37
  279. package/dist/validation/json-parser.d.ts +19 -190
  280. package/dist/validation/json-parser.js +5 -69
  281. package/dist/validation/types.d.ts +9 -33
  282. package/dist/validation/types.js +1 -0
  283. package/dist/versions.d.ts +1 -0
  284. package/dist/versions.js +2 -1
  285. package/dist/words.d.ts +3 -6
  286. package/dist/words.js +1 -0
  287. package/dist/zod.js +1 -0
  288. package/package.json +34 -70
  289. package/dist/external/@inquirer/checkbox.js +0 -5
  290. package/dist/external/@inquirer/confirm.js +0 -5
  291. package/dist/external/@inquirer/input.js +0 -5
  292. package/dist/external/@inquirer/password.js +0 -5
  293. package/dist/external/@inquirer/search.js +0 -5
  294. package/dist/external/@inquirer/select.js +0 -5
  295. package/dist/functions.d.ts +0 -57
  296. package/dist/functions.js +0 -70
  297. package/dist/stdio/clear.d.ts +0 -140
  298. package/dist/stdio/clear.js +0 -95
  299. package/dist/stdio/mask.d.ts +0 -151
  300. package/dist/stdio/mask.js +0 -224
  301. package/dist/stdio/progress.d.ts +0 -148
  302. package/dist/stdio/progress.js +0 -212
  303. package/dist/stdio/prompts.d.ts +0 -195
  304. package/dist/stdio/prompts.js +0 -176
  305. package/dist/utils/get-ipc.d.ts +0 -15
package/CHANGELOG.md CHANGED
@@ -5,6 +5,55 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [5.19.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.19.0) - 2026-04-19
9
+
10
+ ### Added — dlx/integrity (new module)
11
+
12
+ - `HashSpec`, `NormalizedHash`, `ComputedHashes` types. `HashSpec` accepts a bare string (sha512 SRI or sha256 hex, sniffed) or an explicit `{ type, value }` object
13
+ - `normalizeHash()`, `computeHashes()`, `verifyHash()` — `verifyHash` uses `crypto.timingSafeEqual` for constant-time comparison
14
+ - `DlxHashMismatchError` — carries `expected` + `actual` for diagnostics
15
+
16
+ ### Added — dlx/arborist (new module)
17
+
18
+ - `safeIdealTree()`, `safeReify()` — hardened `@npmcli/arborist` wrappers mirroring socket-cli v1.1.79 `SafeArborist` overrides (`audit: false`, `fund: false`, `ignoreScripts: true`, `progress: false`, `saveBundle: false`, `silent: true`)
19
+ - `writeSafeNpmrc()` — defense-in-depth `.npmrc` writer matching the Arborist overrides
20
+ - Optional `before?: Date` on `safeIdealTree` for release-age enforcement during resolution
21
+
22
+ ### Added — dlx/lockfile (new module)
23
+
24
+ - `generatePackagePin({ package, minReleaseDays?, minReleaseMins? })` — returns `PinDetails { name, version, hash: ComputedHashes, packageJson, lockfile }`. Runs Arborist in `packageLockOnly: true` mode against a tmp directory and auto-cleans
25
+ - **Default `minReleaseDays: 7`** — resolution refuses to select versions published in the last week. Pass `0` to disable. `minReleaseMins` is a pnpm-style alias (mutually exclusive with `minReleaseDays`)
26
+ - `LockfileSpec` type — export for use as the new `lockfile` option on `downloadPackage`
27
+
28
+ ### Added — dlx existing modules
29
+
30
+ - `DlxPackageOptions.hash?: HashSpec` and `DlxPackageOptions.lockfile?: LockfileSpec` — passing a lockfile materializes it into the install dir (path → `fs.copyFileSync`, content → `fs.writeFileSync`) and drops a hardened `.npmrc` alongside before Arborist runs
31
+ - `DlxBinaryOptions.hash?: HashSpec` — ergonomic alternative to the lower-level `integrity` and `sha256` fields (both still accepted)
32
+
33
+ ### Fixed — external
34
+
35
+ - `pacote` shim now exposes `tarball`, `manifest`, `packument` alongside `extract`. **Fixes a latent runtime crash** in `src/packages/manifest.ts` callers (`fetchPackageManifest` / `fetchPackagePackument` called `.manifest(...)` / `.packument(...)` on a shim that previously only had `extract`, raising `TypeError: not a function`)
36
+
37
+ ### Changed — build (bundle size)
38
+
39
+ - `dist/external/npm-pack.js`: 2,526,598 → 1,755,460 bytes (−771 KB, −30.5%). New `STUB_MAP` entries for code paths our callers never reach:
40
+ - `@sigstore/{bundle,core,protobuf-specs,sign,tuf,verify}`, `sigstore`, `tuf-js`, `@tufjs/{canonical-json,models}` — Sigstore attestation, only reached via `arb.audit()`
41
+ - `@npmcli/metavuln-calculator` — audit-only
42
+ - `@npmcli/query`, `postcss-selector-parser` — `arb.query()` unused
43
+ - `@npmcli/run-script`, `@npmcli/node-gyp` — guarded out by `ignoreScripts: true`
44
+ - `@npmcli/git`, `pacote/lib/{git,file,dir,remote}.js` — registry specs only
45
+ - arborist `audit-report.js`, `yarn-lock.js`, `isolated-reifier.js`, `query-selector-all.js`, `printable.js` — each gated or unused
46
+ - `cacache/lib/verify.js` — `cacache.verify` (npm cache verify) unused
47
+ - `proggy` — progress tracker, gated by `progress: false`
48
+ - `debug/src/browser.js` — Node-only bundle
49
+ - `dist/external/zod.js`: 597,238 → 291,430 bytes (−306 KB, −51.2%). Stubbed `zod/v4/{core,classic,mini}`'s eager `locales/index.cjs` barrel (40+ translation modules). Opt-in via `z.config(z.locales.xx())` is never called by us
50
+
51
+ ## [5.18.2](https://github.com/SocketDev/socket-lib/releases/tag/v5.18.2) - 2026-04-14
52
+
53
+ ### Removed
54
+
55
+ - Remove unused `plugins/` directory and `./plugins/babel-plugin-inline-require-calls` export — no downstream consumers; socket-cli maintains its own local copies
56
+
8
57
  ## [5.18.1](https://github.com/SocketDev/socket-lib/releases/tag/v5.18.1) - 2026-04-14
9
58
 
10
59
  ### Changed — build
package/README.md CHANGED
@@ -45,6 +45,7 @@ logger.success(`Package: ${pkg.name}@${pkg.version}`)
45
45
 
46
46
  ## Documentation
47
47
 
48
+ - [API Index](./docs/api-index.md) - Every subpath export with a one-line description (start here)
48
49
  - [Getting Started](./docs/getting-started.md) - Prerequisites, installation, and first examples
49
50
  - [Visual Effects](./docs/visual-effects.md) - Spinners, loggers, themes, and progress indicators
50
51
  - [File System](./docs/file-system.md) - File operations, globs, paths, and safe deletion
@@ -96,8 +97,8 @@ Spawn child processes safely with cross-platform support.
96
97
  - `spawnSync()` - Synchronous version for blocking operations
97
98
  - Array-based arguments prevent command injection
98
99
  - Automatic Windows `.cmd`/`.bat` handling
99
- - `ProcessLock` - Ensure only one instance runs at a time
100
- - `setupIPC()` - Inter-process communication
100
+ - `processLock.withLock()` / `processLock.acquire()` / `processLock.release()` - Ensure only one instance runs at a time
101
+ - `writeIpcStub()` / `getIpcStubPath()` - Filesystem-based inter-process data handoff
101
102
 
102
103
  ### Environment Detection
103
104
 
@@ -106,14 +107,14 @@ Type-safe environment variable access and platform detection.
106
107
  - `getCI()` - Detect CI environment
107
108
  - `getNodeEnv()` - Get NODE_ENV value
108
109
  - `isTest()` - Check if running tests
109
- - `getHome()` - Home directory (Unix/Linux/macOS)
110
+ - `getHome()` - Home directory (cross-platform, with Windows `USERPROFILE` fallback)
110
111
  - Test rewiring with `setEnv()`, `resetEnv()`
111
112
 
112
113
  ### Package Management
113
114
 
114
115
  Detect and work with npm, pnpm, and yarn.
115
116
 
116
- - `detectPackageManager()` - Identify package manager from lock files
117
+ - `detectPackageManager()` - Identify running package manager from `npm_config_user_agent` / binary path
117
118
  - Package manifest operations
118
119
  - Lock file management
119
120
 
@@ -141,7 +142,7 @@ Helpers for arrays, objects, strings, promises, sorting, and more.
141
142
  - **Cross-platform** - Works on Windows, macOS, and Linux
142
143
  - **TypeScript-first** - Full type safety with .d.ts files
143
144
  - **Zero dependencies** (for core HTTP - uses Node.js native modules)
144
- - **Well-tested** - 6600+ tests across 145 test files
145
+ - **Well-tested** - 6000+ tests across 139+ test files
145
146
  - **Security-focused** - Safe defaults, command injection protection
146
147
  - **CommonJS output** - Compatible with Node.js tooling
147
148
 
package/dist/abort.d.ts CHANGED
@@ -15,6 +15,9 @@ export declare function createCompositeAbortSignal(...signals: Array<AbortSignal
15
15
  /**
16
16
  * Create an AbortSignal that triggers after a timeout.
17
17
  *
18
+ * @throws {TypeError} If `ms` is not a number, is NaN, is not finite, or is not
19
+ * positive.
20
+ *
18
21
  * @example
19
22
  * ```typescript
20
23
  * const signal = createTimeoutSignal(5000) // aborts after 5 seconds
package/dist/abort.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
+ "use strict";
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
package/dist/agent.d.ts CHANGED
@@ -1,4 +1,34 @@
1
+ /**
2
+ * @fileoverview Package manager agent for executing npm, pnpm, and yarn commands.
3
+ * Provides cross-platform utilities with optimized flags and security defaults.
4
+ *
5
+ * SECURITY: Array-Based Arguments Prevent Command Injection
6
+ *
7
+ * All functions in this module (execNpm, execPnpm, execYarn) use array-based
8
+ * arguments when calling spawn(). This is the PRIMARY DEFENSE against command
9
+ * injection attacks.
10
+ *
11
+ * When arguments are passed as an array:
12
+ * spawn(cmd, ['install', packageName, '--flag'], options)
13
+ *
14
+ * Node.js handles escaping automatically. Each argument is passed directly to
15
+ * the OS without shell interpretation. Shell metacharacters like ; | & $ ( )
16
+ * are treated as LITERAL STRINGS, not as commands.
17
+ *
18
+ * Example: If packageName = "lodash; rm -rf /", the package manager will try to
19
+ * install a package literally named "lodash; rm -rf /" (which doesn't exist),
20
+ * rather than executing the malicious command.
21
+ *
22
+ * This approach is secure even when shell: true is used on Windows for .cmd
23
+ * file resolution, because Node.js properly escapes each array element.
24
+ */
1
25
  import type { SpawnOptions } from './spawn';
26
+ export interface PnpmOptions extends SpawnOptions {
27
+ allowLockfileUpdate?: boolean;
28
+ }
29
+ export interface ExecScriptOptions extends SpawnOptions {
30
+ prepost?: boolean | undefined;
31
+ }
2
32
  /**
3
33
  * Execute npm commands with optimized flags and settings.
4
34
  *
@@ -12,9 +42,6 @@ import type { SpawnOptions } from './spawn';
12
42
  * ```
13
43
  */
14
44
  export declare function execNpm(args: string[], options?: SpawnOptions | undefined): import("./spawn").PromiseSpawnResult;
15
- export interface PnpmOptions extends SpawnOptions {
16
- allowLockfileUpdate?: boolean;
17
- }
18
45
  /**
19
46
  * Execute pnpm commands with optimized flags and settings.
20
47
  *
@@ -31,9 +58,28 @@ export declare function execPnpm(args: string[], options?: PnpmOptions | undefin
31
58
  cmd: string;
32
59
  args: string[] | readonly string[];
33
60
  code: number;
34
- signal: NodeJS.Signals;
35
- stdout: string | Buffer<ArrayBufferLike>;
36
- stderr: string | Buffer<ArrayBufferLike>;
61
+ signal: NodeJS.Signals | null;
62
+ stdout: string | Buffer;
63
+ stderr: string | Buffer;
64
+ }>;
65
+ /**
66
+ * Execute a package.json script using the detected package manager.
67
+ * Picks pnpm, npm, or yarn by walking up to the nearest lockfile; falls back
68
+ * to running `node --run` or `npm run` directly when no lockfile is found.
69
+ * Honors `shell: true` by passing through to `spawn()` unchanged.
70
+ *
71
+ * @param scriptName - The package.json script to run
72
+ * @param args - Either the script arguments or an options object
73
+ * @param options - Spawn options plus `prepost` to force npm-style pre/post scripts
74
+ * @returns The spawned `ChildProcess`-like promise from the underlying runner.
75
+ */
76
+ export declare function execScript(scriptName: string, args?: string[] | readonly string[] | ExecScriptOptions | undefined, options?: ExecScriptOptions | undefined): Promise<{
77
+ cmd: string;
78
+ args: string[] | readonly string[];
79
+ code: number;
80
+ signal: NodeJS.Signals | null;
81
+ stdout: string | Buffer;
82
+ stderr: string | Buffer;
37
83
  }>;
38
84
  /**
39
85
  * Execute yarn commands with optimized flags and settings.
@@ -51,9 +97,9 @@ export declare function execYarn(args: string[], options?: import('./spawn').Spa
51
97
  cmd: string;
52
98
  args: string[] | readonly string[];
53
99
  code: number;
54
- signal: NodeJS.Signals;
55
- stdout: string | Buffer<ArrayBufferLike>;
56
- stderr: string | Buffer<ArrayBufferLike>;
100
+ signal: NodeJS.Signals | null;
101
+ stdout: string | Buffer;
102
+ stderr: string | Buffer;
57
103
  }>;
58
104
  /**
59
105
  * Check if a command argument is an npm audit flag.
@@ -65,7 +111,6 @@ export declare function execYarn(args: string[], options?: import('./spawn').Spa
65
111
  * isNpmAuditFlag('--save') // false
66
112
  * ```
67
113
  */
68
- /*@__NO_SIDE_EFFECTS__*/
69
114
  export declare function isNpmAuditFlag(cmdArg: string): boolean;
70
115
  /**
71
116
  * Check if a command argument is an npm fund flag.
@@ -77,7 +122,6 @@ export declare function isNpmAuditFlag(cmdArg: string): boolean;
77
122
  * isNpmFundFlag('--save') // false
78
123
  * ```
79
124
  */
80
- /*@__NO_SIDE_EFFECTS__*/
81
125
  export declare function isNpmFundFlag(cmdArg: string): boolean;
82
126
  /**
83
127
  * Check if a command argument is an npm loglevel flag.
@@ -90,7 +134,6 @@ export declare function isNpmFundFlag(cmdArg: string): boolean;
90
134
  * isNpmLoglevelFlag('--save') // false
91
135
  * ```
92
136
  */
93
- /*@__NO_SIDE_EFFECTS__*/
94
137
  export declare function isNpmLoglevelFlag(cmdArg: string): boolean;
95
138
  /**
96
139
  * Check if a command argument is an npm node-options flag.
@@ -102,7 +145,6 @@ export declare function isNpmLoglevelFlag(cmdArg: string): boolean;
102
145
  * isNpmNodeOptionsFlag('--save') // false
103
146
  * ```
104
147
  */
105
- /*@__NO_SIDE_EFFECTS__*/
106
148
  export declare function isNpmNodeOptionsFlag(cmdArg: string): boolean;
107
149
  /**
108
150
  * Check if a command argument is an npm progress flag.
@@ -114,32 +156,29 @@ export declare function isNpmNodeOptionsFlag(cmdArg: string): boolean;
114
156
  * isNpmProgressFlag('--save') // false
115
157
  * ```
116
158
  */
117
- /*@__NO_SIDE_EFFECTS__*/
118
159
  export declare function isNpmProgressFlag(cmdArg: string): boolean;
119
160
  /**
120
- * Check if a command argument is a pnpm ignore-scripts flag.
161
+ * Check if a command argument is a pnpm frozen-lockfile flag.
121
162
  *
122
163
  * @example
123
164
  * ```typescript
124
- * isPnpmIgnoreScriptsFlag('--ignore-scripts') // true
125
- * isPnpmIgnoreScriptsFlag('--no-ignore-scripts') // true
126
- * isPnpmIgnoreScriptsFlag('--save') // false
165
+ * isPnpmFrozenLockfileFlag('--frozen-lockfile') // true
166
+ * isPnpmFrozenLockfileFlag('--no-frozen-lockfile') // true
167
+ * isPnpmFrozenLockfileFlag('--save') // false
127
168
  * ```
128
169
  */
129
- /*@__NO_SIDE_EFFECTS__*/
130
- export declare function isPnpmIgnoreScriptsFlag(cmdArg: string): boolean;
170
+ export declare function isPnpmFrozenLockfileFlag(cmdArg: string): boolean;
131
171
  /**
132
- * Check if a command argument is a pnpm frozen-lockfile flag.
172
+ * Check if a command argument is a pnpm ignore-scripts flag.
133
173
  *
134
174
  * @example
135
175
  * ```typescript
136
- * isPnpmFrozenLockfileFlag('--frozen-lockfile') // true
137
- * isPnpmFrozenLockfileFlag('--no-frozen-lockfile') // true
138
- * isPnpmFrozenLockfileFlag('--save') // false
176
+ * isPnpmIgnoreScriptsFlag('--ignore-scripts') // true
177
+ * isPnpmIgnoreScriptsFlag('--no-ignore-scripts') // true
178
+ * isPnpmIgnoreScriptsFlag('--save') // false
139
179
  * ```
140
180
  */
141
- /*@__NO_SIDE_EFFECTS__*/
142
- export declare function isPnpmFrozenLockfileFlag(cmdArg: string): boolean;
181
+ export declare function isPnpmIgnoreScriptsFlag(cmdArg: string): boolean;
143
182
  /**
144
183
  * Check if a command argument is a pnpm install command.
145
184
  *
@@ -150,30 +189,8 @@ export declare function isPnpmFrozenLockfileFlag(cmdArg: string): boolean;
150
189
  * isPnpmInstallCommand('run') // false
151
190
  * ```
152
191
  */
153
- /*@__NO_SIDE_EFFECTS__*/
154
192
  export declare function isPnpmInstallCommand(cmdArg: string): boolean;
155
193
  /**
156
- * Alias for isNpmLoglevelFlag for pnpm usage.
194
+ * Alias for isNpmLoglevelFlag pnpm uses the same `--loglevel` surface.
157
195
  */
158
196
  export declare const isPnpmLoglevelFlag: typeof isNpmLoglevelFlag;
159
- /**
160
- * Execute a package.json script using the appropriate package manager.
161
- * Automatically detects pnpm, yarn, or npm based on lockfiles.
162
- *
163
- * @example
164
- * ```typescript
165
- * await execScript('build')
166
- * await execScript('test', ['--coverage'], { cwd: '/tmp/project' })
167
- * ```
168
- */
169
- export interface ExecScriptOptions extends SpawnOptions {
170
- prepost?: boolean | undefined;
171
- }
172
- export declare function execScript(scriptName: string, args?: string[] | readonly string[] | ExecScriptOptions | undefined, options?: ExecScriptOptions | undefined): Promise<{
173
- cmd: string;
174
- args: string[] | readonly string[];
175
- code: number;
176
- signal: NodeJS.Signals;
177
- stdout: string | Buffer<ArrayBufferLike>;
178
- stderr: string | Buffer<ArrayBufferLike>;
179
- }>;
package/dist/agent.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
+ "use strict";
3
4
  var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
5
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -45,12 +46,12 @@ __export(agent_exports, {
45
46
  });
46
47
  module.exports = __toCommonJS(agent_exports);
47
48
  var import_node_process = __toESM(require("node:process"));
49
+ var import_bin = require("./bin");
48
50
  var import_agents = require("./constants/agents");
49
51
  var import_node = require("./constants/node");
50
52
  var import_platform = require("./constants/platform");
51
- var import_ci = require("./env/ci");
52
- var import_bin = require("./bin");
53
53
  var import_debug = require("./debug");
54
+ var import_ci = require("./env/ci");
54
55
  var import_fs = require("./fs");
55
56
  var import_objects = require("./objects");
56
57
  var import_spawn = require("./spawn");
@@ -158,6 +159,50 @@ function execPnpm(args, options) {
158
159
  extBinOpts
159
160
  );
160
161
  }
162
+ function execScript(scriptName, args, options) {
163
+ let resolvedOptions;
164
+ let resolvedArgs;
165
+ if (!Array.isArray(args) && args !== null && typeof args === "object") {
166
+ resolvedOptions = args;
167
+ resolvedArgs = [];
168
+ } else {
169
+ resolvedOptions = options;
170
+ resolvedArgs = args || [];
171
+ }
172
+ const { prepost, ...spawnOptions } = {
173
+ __proto__: null,
174
+ ...resolvedOptions
175
+ };
176
+ if (spawnOptions.shell === true) {
177
+ return (0, import_spawn.spawn)(scriptName, resolvedArgs, spawnOptions);
178
+ }
179
+ const useNodeRun = !prepost && (0, import_node.supportsNodeRun)();
180
+ const cwd = (0, import_objects.getOwn)(spawnOptions, "cwd") ?? import_node_process.default.cwd();
181
+ const pnpmLockPath = (0, import_fs.findUpSync)(import_agents.PNPM_LOCK_YAML, { cwd });
182
+ if (pnpmLockPath) {
183
+ return execPnpm(["run", scriptName, ...resolvedArgs], spawnOptions);
184
+ }
185
+ const packageLockPath = (0, import_fs.findUpSync)(import_agents.PACKAGE_LOCK_JSON, { cwd });
186
+ if (packageLockPath) {
187
+ return execNpm(["run", scriptName, ...resolvedArgs], spawnOptions);
188
+ }
189
+ const yarnLockPath = (0, import_fs.findUpSync)(import_agents.YARN_LOCK, { cwd });
190
+ if (yarnLockPath) {
191
+ return execYarn(["run", scriptName, ...resolvedArgs], spawnOptions);
192
+ }
193
+ return (0, import_spawn.spawn)(
194
+ (0, import_node.getExecPath)(),
195
+ [
196
+ ...(0, import_node.getNodeNoWarningsFlags)(),
197
+ ...useNodeRun ? ["--run"] : [import_agents.NPM_REAL_EXEC_PATH, "run"],
198
+ scriptName,
199
+ ...resolvedArgs
200
+ ],
201
+ {
202
+ ...spawnOptions
203
+ }
204
+ );
205
+ }
161
206
  function execYarn(args, options) {
162
207
  const useDebug = (0, import_debug.isDebug)();
163
208
  const terminatorPos = args.indexOf("--");
@@ -211,62 +256,18 @@ function isNpmProgressFlag(cmdArg) {
211
256
  return /^--(no-)?progress(=.*)?$/.test(cmdArg);
212
257
  }
213
258
  // @__NO_SIDE_EFFECTS__
214
- function isPnpmIgnoreScriptsFlag(cmdArg) {
215
- return pnpmIgnoreScriptsFlags.has(cmdArg);
216
- }
217
- // @__NO_SIDE_EFFECTS__
218
259
  function isPnpmFrozenLockfileFlag(cmdArg) {
219
260
  return pnpmFrozenLockfileFlags.has(cmdArg);
220
261
  }
221
262
  // @__NO_SIDE_EFFECTS__
263
+ function isPnpmIgnoreScriptsFlag(cmdArg) {
264
+ return pnpmIgnoreScriptsFlags.has(cmdArg);
265
+ }
266
+ // @__NO_SIDE_EFFECTS__
222
267
  function isPnpmInstallCommand(cmdArg) {
223
268
  return pnpmInstallCommands.has(cmdArg);
224
269
  }
225
270
  const isPnpmLoglevelFlag = isNpmLoglevelFlag;
226
- function execScript(scriptName, args, options) {
227
- let resolvedOptions;
228
- let resolvedArgs;
229
- if (!Array.isArray(args) && args !== null && typeof args === "object") {
230
- resolvedOptions = args;
231
- resolvedArgs = [];
232
- } else {
233
- resolvedOptions = options;
234
- resolvedArgs = args || [];
235
- }
236
- const { prepost, ...spawnOptions } = {
237
- __proto__: null,
238
- ...resolvedOptions
239
- };
240
- if (spawnOptions.shell === true) {
241
- return (0, import_spawn.spawn)(scriptName, resolvedArgs, spawnOptions);
242
- }
243
- const useNodeRun = !prepost && (0, import_node.supportsNodeRun)();
244
- const cwd = (0, import_objects.getOwn)(spawnOptions, "cwd") ?? import_node_process.default.cwd();
245
- const pnpmLockPath = (0, import_fs.findUpSync)(import_agents.PNPM_LOCK_YAML, { cwd });
246
- if (pnpmLockPath) {
247
- return execPnpm(["run", scriptName, ...resolvedArgs], spawnOptions);
248
- }
249
- const packageLockPath = (0, import_fs.findUpSync)(import_agents.PACKAGE_LOCK_JSON, { cwd });
250
- if (packageLockPath) {
251
- return execNpm(["run", scriptName, ...resolvedArgs], spawnOptions);
252
- }
253
- const yarnLockPath = (0, import_fs.findUpSync)(import_agents.YARN_LOCK, { cwd });
254
- if (yarnLockPath) {
255
- return execYarn(["run", scriptName, ...resolvedArgs], spawnOptions);
256
- }
257
- return (0, import_spawn.spawn)(
258
- (0, import_node.getExecPath)(),
259
- [
260
- ...(0, import_node.getNodeNoWarningsFlags)(),
261
- ...useNodeRun ? ["--run"] : [import_agents.NPM_REAL_EXEC_PATH, "run"],
262
- scriptName,
263
- ...resolvedArgs
264
- ],
265
- {
266
- ...spawnOptions
267
- }
268
- );
269
- }
270
271
  // Annotate the CommonJS export names for ESM import in node:
271
272
  0 && (module.exports = {
272
273
  execNpm,
package/dist/ansi.d.ts CHANGED
@@ -2,13 +2,12 @@
2
2
  * @fileoverview ANSI escape code utilities.
3
3
  * Provides constants and helpers for terminal formatting.
4
4
  */
5
- // ANSI escape codes - commonly used sequences.
6
- export declare const ANSI_RESET = "\u001B[0m";
7
5
  export declare const ANSI_BOLD = "\u001B[1m";
8
6
  export declare const ANSI_DIM = "\u001B[2m";
9
7
  export declare const ANSI_ITALIC = "\u001B[3m";
10
- export declare const ANSI_UNDERLINE = "\u001B[4m";
8
+ export declare const ANSI_RESET = "\u001B[0m";
11
9
  export declare const ANSI_STRIKETHROUGH = "\u001B[9m";
10
+ export declare const ANSI_UNDERLINE = "\u001B[4m";
12
11
  /**
13
12
  * Create a regular expression for matching ANSI escape codes.
14
13
  *
@@ -24,7 +23,6 @@ export declare const ANSI_STRIKETHROUGH = "\u001B[9m";
24
23
  * ansiRegex({ onlyFirst: true }) // matches only the first code
25
24
  * ```
26
25
  */
27
- /*@__NO_SIDE_EFFECTS__*/
28
26
  export declare function ansiRegex(options?: {
29
27
  onlyFirst?: boolean;
30
28
  }): RegExp;
@@ -38,5 +36,4 @@ export declare function ansiRegex(options?: {
38
36
  * stripAnsi('\u001b[1mBold\u001b[0m') // 'Bold'
39
37
  * ```
40
38
  */
41
- /*@__NO_SIDE_EFFECTS__*/
42
39
  export declare function stripAnsi(text: string): string;
package/dist/ansi.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
+ "use strict";
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -29,12 +30,12 @@ __export(ansi_exports, {
29
30
  stripAnsi: () => stripAnsi
30
31
  });
31
32
  module.exports = __toCommonJS(ansi_exports);
32
- const ANSI_RESET = "\x1B[0m";
33
33
  const ANSI_BOLD = "\x1B[1m";
34
34
  const ANSI_DIM = "\x1B[2m";
35
35
  const ANSI_ITALIC = "\x1B[3m";
36
- const ANSI_UNDERLINE = "\x1B[4m";
36
+ const ANSI_RESET = "\x1B[0m";
37
37
  const ANSI_STRIKETHROUGH = "\x1B[9m";
38
+ const ANSI_UNDERLINE = "\x1B[4m";
38
39
  const ANSI_REGEX = /\x1b\[[0-9;]*m/g;
39
40
  // @__NO_SIDE_EFFECTS__
40
41
  function ansiRegex(options) {
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @fileoverview Generic archive extraction utilities.
3
+ * Supports zip, tar, tar.gz, and tgz formats.
4
+ */
1
5
  /**
2
6
  * Archive format type.
3
7
  */
@@ -7,15 +11,15 @@ export type ArchiveFormat = 'tar' | 'tar.gz' | 'tgz' | 'zip';
7
11
  */
8
12
  export interface ExtractOptions {
9
13
  /** Suppress log messages */
10
- quiet?: boolean;
14
+ quiet?: boolean | undefined;
11
15
  /** Strip leading path components (like tar --strip-components) */
12
- strip?: number;
16
+ strip?: number | undefined;
13
17
  /** Maximum number of entries to extract (default: 100,000) */
14
- maxEntries?: number;
18
+ maxEntries?: number | undefined;
15
19
  /** Maximum size of a single extracted file in bytes (default: 100MB) */
16
- maxFileSize?: number;
20
+ maxFileSize?: number | undefined;
17
21
  /** Maximum total extracted size in bytes (default: 1GB) */
18
- maxTotalSize?: number;
22
+ maxTotalSize?: number | undefined;
19
23
  }
20
24
  /**
21
25
  * Detect archive format from file path.
@@ -31,6 +35,22 @@ export interface ExtractOptions {
31
35
  * ```
32
36
  */
33
37
  export declare function detectArchiveFormat(filePath: string): ArchiveFormat | null;
38
+ /**
39
+ * Extract an archive to a directory.
40
+ * Automatically detects format from file extension.
41
+ *
42
+ * @param archivePath - Path to archive file
43
+ * @param outputDir - Directory to extract to
44
+ * @param options - Extraction options
45
+ * @throws Error if archive format is not supported
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * await extractArchive('/tmp/package.tar.gz', '/tmp/output')
50
+ * await extractArchive('/tmp/release.zip', '/tmp/output', { strip: 1 })
51
+ * ```
52
+ */
53
+ export declare function extractArchive(archivePath: string, outputDir: string, options?: ExtractOptions): Promise<void>;
34
54
  /**
35
55
  * Extract a tar archive to a directory.
36
56
  *
@@ -73,19 +93,3 @@ export declare function extractTarGz(archivePath: string, outputDir: string, opt
73
93
  * ```
74
94
  */
75
95
  export declare function extractZip(archivePath: string, outputDir: string, options?: ExtractOptions): Promise<void>;
76
- /**
77
- * Extract an archive to a directory.
78
- * Automatically detects format from file extension.
79
- *
80
- * @param archivePath - Path to archive file
81
- * @param outputDir - Directory to extract to
82
- * @param options - Extraction options
83
- * @throws Error if archive format is not supported
84
- *
85
- * @example
86
- * ```typescript
87
- * await extractArchive('/tmp/package.tar.gz', '/tmp/output')
88
- * await extractArchive('/tmp/release.zip', '/tmp/output', { strip: 1 })
89
- * ```
90
- */
91
- export declare function extractArchive(archivePath: string, outputDir: string, options?: ExtractOptions): Promise<void>;