@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
@@ -1,7 +1,11 @@
1
+ /**
2
+ * @fileoverview Memoization utilities for caching function results.
3
+ * Provides function result caching to optimize repeated computations and expensive operations.
4
+ */
1
5
  /**
2
6
  * Options for memoization behavior.
3
7
  */
4
- type MemoizeOptions<Args extends unknown[], _Result = unknown> = {
8
+ export type MemoizeOptions<Args extends unknown[], _Result = unknown> = {
5
9
  /** Custom cache key generator (defaults to JSON.stringify) */
6
10
  keyGen?: (...args: Args) => string;
7
11
  /** Maximum cache size (LRU eviction when exceeded) */
@@ -15,6 +19,37 @@ type MemoizeOptions<Args extends unknown[], _Result = unknown> = {
15
19
  /** Custom equality check for cache hits */
16
20
  equals?: (a: Args, b: Args) => boolean;
17
21
  };
22
+ /**
23
+ * Clear all memoization caches.
24
+ * Useful for testing or when you need to force recomputation.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * clearAllMemoizationCaches()
29
+ * ```
30
+ */
31
+ export declare function clearAllMemoizationCaches(): void;
32
+ /**
33
+ * Create a memoized version of a method.
34
+ * Preserves 'this' context for class methods.
35
+ *
36
+ * @param target - Object containing the method
37
+ * @param propertyKey - Method name
38
+ * @param descriptor - Property descriptor
39
+ * @returns Modified descriptor with memoized method
40
+ *
41
+ * @example
42
+ * import { Memoize } from '@socketsecurity/lib/memoization'
43
+ *
44
+ * class Calculator {
45
+ * @Memoize()
46
+ * fibonacci(n: number): number {
47
+ * if (n <= 1) return n
48
+ * return this.fibonacci(n - 1) + this.fibonacci(n - 2)
49
+ * }
50
+ * }
51
+ */
52
+ export declare function Memoize(options?: MemoizeOptions<unknown[], unknown>): (_target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
18
53
  /**
19
54
  * Memoize a function with configurable caching behavior.
20
55
  * Caches function results to avoid repeated computation.
@@ -56,36 +91,24 @@ export declare function memoize<Args extends unknown[], Result>(fn: (...args: Ar
56
91
  */
57
92
  export declare function memoizeAsync<Args extends unknown[], Result>(fn: (...args: Args) => Promise<Result>, options?: MemoizeOptions<Args, Result>): (...args: Args) => Promise<Result>;
58
93
  /**
59
- * Create a memoized version of a method.
60
- * Preserves 'this' context for class methods.
94
+ * Create a debounced memoized function.
95
+ * Combines memoization with debouncing for expensive operations.
61
96
  *
62
- * @param target - Object containing the method
63
- * @param propertyKey - Method name
64
- * @param descriptor - Property descriptor
65
- * @returns Modified descriptor with memoized method
97
+ * @param fn - Function to memoize and debounce
98
+ * @param wait - Debounce wait time in milliseconds
99
+ * @param options - Memoization options
100
+ * @returns Debounced memoized function
66
101
  *
67
102
  * @example
68
- * import { Memoize } from '@socketsecurity/lib/memoization'
69
- *
70
- * class Calculator {
71
- * @Memoize()
72
- * fibonacci(n: number): number {
73
- * if (n <= 1) return n
74
- * return this.fibonacci(n - 1) + this.fibonacci(n - 2)
75
- * }
76
- * }
77
- */
78
- export declare function Memoize(options?: MemoizeOptions<unknown[], unknown>): (_target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
79
- /**
80
- * Clear all memoization caches.
81
- * Useful for testing or when you need to force recomputation.
103
+ * import { memoizeDebounced } from '@socketsecurity/lib/memoization'
82
104
  *
83
- * @example
84
- * ```typescript
85
- * clearAllMemoizationCaches()
86
- * ```
105
+ * const search = memoizeDebounced(
106
+ * (query: string) => performSearch(query),
107
+ * 300,
108
+ * { name: 'search' }
109
+ * )
87
110
  */
88
- export declare function clearAllMemoizationCaches(): void;
111
+ export declare function memoizeDebounced<Args extends unknown[], Result>(fn: (...args: Args) => Result, wait: number, options?: MemoizeOptions<Args, Result>): (...args: Args) => Result;
89
112
  /**
90
113
  * Memoize with WeakMap for object keys.
91
114
  * Allows garbage collection when objects are no longer referenced.
@@ -107,10 +130,10 @@ export declare function clearAllMemoizationCaches(): void;
107
130
  */
108
131
  export declare function memoizeWeak<K extends object, Result>(fn: (key: K) => Result): (key: K) => Result;
109
132
  /**
110
- * Simple once() implementation - caches single result forever.
111
- * Useful for initialization functions that should only run once.
133
+ * Simple once() for zero-argument initialization functions.
134
+ * Caches a single result forever and emits debug-log events on hit/miss.
112
135
  *
113
- * @param fn - Function to run once
136
+ * @param fn - Zero-argument function to run once
114
137
  * @returns Memoized version that only executes once
115
138
  *
116
139
  * @example
@@ -125,23 +148,3 @@ export declare function memoizeWeak<K extends object, Result>(fn: (key: K) => Re
125
148
  * initialize() // Returns cached config (no log)
126
149
  */
127
150
  export declare function once<Result>(fn: () => Result): () => Result;
128
- /**
129
- * Create a debounced memoized function.
130
- * Combines memoization with debouncing for expensive operations.
131
- *
132
- * @param fn - Function to memoize and debounce
133
- * @param wait - Debounce wait time in milliseconds
134
- * @param options - Memoization options
135
- * @returns Debounced memoized function
136
- *
137
- * @example
138
- * import { memoizeDebounced } from '@socketsecurity/lib/memoization'
139
- *
140
- * const search = memoizeDebounced(
141
- * (query: string) => performSearch(query),
142
- * 300,
143
- * { name: 'search' }
144
- * )
145
- */
146
- export declare function memoizeDebounced<Args extends unknown[], Result>(fn: (...args: Args) => Result, wait: number, options?: MemoizeOptions<Args, Result>): (...args: Args) => Result;
147
- export {};
@@ -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;
@@ -30,9 +31,45 @@ __export(memoization_exports, {
30
31
  module.exports = __toCommonJS(memoization_exports);
31
32
  var import_debug = require("./debug");
32
33
  const cacheRegistry = [];
34
+ function defaultKeyGen(args) {
35
+ return JSON.stringify(args, (_key, value) => {
36
+ if (value === void 0) {
37
+ return "\0undefined";
38
+ }
39
+ if (typeof value === "bigint") {
40
+ return `\0bigint:${value.toString()}`;
41
+ }
42
+ if (typeof value === "function") {
43
+ return `\0fn:${value.name || "anonymous"}`;
44
+ }
45
+ if (value instanceof Map) {
46
+ return { __tag: "Map", entries: Array.from(value.entries()) };
47
+ }
48
+ if (value instanceof Set) {
49
+ return { __tag: "Set", values: Array.from(value.values()) };
50
+ }
51
+ return value;
52
+ });
53
+ }
54
+ function clearAllMemoizationCaches() {
55
+ (0, import_debug.debugLog)("[memoize:all] clear", { action: "clear-all-caches" });
56
+ for (const clear of cacheRegistry) {
57
+ clear();
58
+ }
59
+ }
60
+ function Memoize(options = {}) {
61
+ return (_target, propertyKey, descriptor) => {
62
+ const originalMethod = descriptor.value;
63
+ descriptor.value = memoize(originalMethod, {
64
+ ...options,
65
+ name: options.name || propertyKey
66
+ });
67
+ return descriptor;
68
+ };
69
+ }
33
70
  function memoize(fn, options = {}) {
34
71
  const {
35
- keyGen = (...args) => JSON.stringify(args),
72
+ keyGen = (...args) => defaultKeyGen(args),
36
73
  maxSize = Number.POSITIVE_INFINITY,
37
74
  name = fn.name || "anonymous",
38
75
  ttl = Number.POSITIVE_INFINITY
@@ -99,7 +136,7 @@ function memoize(fn, options = {}) {
99
136
  }
100
137
  function memoizeAsync(fn, options = {}) {
101
138
  const {
102
- keyGen = (...args) => JSON.stringify(args),
139
+ keyGen = (...args) => defaultKeyGen(args),
103
140
  maxSize = Number.POSITIVE_INFINITY,
104
141
  name = fn.name || "anonymous",
105
142
  ttl = Number.POSITIVE_INFINITY
@@ -128,7 +165,7 @@ function memoizeAsync(fn, options = {}) {
128
165
  }
129
166
  return Date.now() - entry.timestamp > ttl;
130
167
  }
131
- const refreshing = /* @__PURE__ */ new Set();
168
+ const refreshing = /* @__PURE__ */ new Map();
132
169
  return async function memoized(...args) {
133
170
  const key = keyGen(...args);
134
171
  const cached = cache.get(key);
@@ -143,9 +180,10 @@ function memoizeAsync(fn, options = {}) {
143
180
  (0, import_debug.debugLog)(`[memoizeAsync:${name}] hit`, { key, hits: cached.hits });
144
181
  return await cached.value;
145
182
  }
146
- if (refreshing.has(key)) {
183
+ const inflight = refreshing.get(key);
184
+ if (inflight) {
147
185
  (0, import_debug.debugLog)(`[memoizeAsync:${name}] stale-dedup`, { key });
148
- return await cached.value;
186
+ return await inflight;
149
187
  }
150
188
  cache.delete(key);
151
189
  const index = accessOrder.indexOf(key);
@@ -154,7 +192,6 @@ function memoizeAsync(fn, options = {}) {
154
192
  }
155
193
  }
156
194
  (0, import_debug.debugLog)(`[memoizeAsync:${name}] miss`, { key });
157
- refreshing.add(key);
158
195
  const promise = fn(...args).then(
159
196
  (result) => {
160
197
  refreshing.delete(key);
@@ -175,6 +212,7 @@ function memoizeAsync(fn, options = {}) {
175
212
  throw error;
176
213
  }
177
214
  );
215
+ refreshing.set(key, promise);
178
216
  evictLRU();
179
217
  cache.set(key, {
180
218
  value: promise,
@@ -186,22 +224,19 @@ function memoizeAsync(fn, options = {}) {
186
224
  return await promise;
187
225
  };
188
226
  }
189
- function Memoize(options = {}) {
190
- return (_target, propertyKey, descriptor) => {
191
- const originalMethod = descriptor.value;
192
- descriptor.value = memoize(originalMethod, {
193
- ...options,
194
- name: options.name || propertyKey
195
- });
196
- return descriptor;
227
+ function memoizeDebounced(fn, wait, options = {}) {
228
+ const memoized = memoize(fn, options);
229
+ let timeoutId;
230
+ return function debounced(...args) {
231
+ if (timeoutId) {
232
+ clearTimeout(timeoutId);
233
+ }
234
+ timeoutId = setTimeout(() => {
235
+ memoized(...args);
236
+ }, wait);
237
+ return memoized(...args);
197
238
  };
198
239
  }
199
- function clearAllMemoizationCaches() {
200
- (0, import_debug.debugLog)("[memoize:all] clear", { action: "clear-all-caches" });
201
- for (const clear of cacheRegistry) {
202
- clear();
203
- }
204
- }
205
240
  function memoizeWeak(fn) {
206
241
  const cache = /* @__PURE__ */ new WeakMap();
207
242
  return function memoized(key) {
@@ -229,19 +264,6 @@ function once(fn) {
229
264
  return result;
230
265
  };
231
266
  }
232
- function memoizeDebounced(fn, wait, options = {}) {
233
- const memoized = memoize(fn, options);
234
- let timeoutId;
235
- return function debounced(...args) {
236
- if (timeoutId) {
237
- clearTimeout(timeoutId);
238
- }
239
- timeoutId = setTimeout(() => {
240
- memoized(...args);
241
- }, wait);
242
- return memoized(...args);
243
- };
244
- }
245
267
  // Annotate the CommonJS export names for ESM import in node:
246
268
  0 && (module.exports = {
247
269
  Memoize,
package/dist/objects.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- // Type definitions
1
+ /**
2
+ * @fileoverview Object manipulation and reflection utilities.
3
+ * Provides type-safe object operations, property access, and structural helpers.
4
+ */
2
5
  /**
3
6
  * Record of property keys mapped to getter functions.
4
7
  * Used for defining lazy getters on objects.
@@ -91,7 +94,6 @@ export type { GetterDefObj, LazyGetterStats, ConstantsObjectOptions, Remap };
91
94
  * console.log(config[kInternalsSymbol].version) // '1.0.0'
92
95
  * ```
93
96
  */
94
- /*@__NO_SIDE_EFFECTS__*/
95
97
  export declare function createConstantsObject(props: object, options_?: ConstantsObjectOptions | undefined): Readonly<object>;
96
98
  /**
97
99
  * Create a lazy getter function that memoizes its result.
@@ -118,7 +120,6 @@ export declare function createConstantsObject(props: object, options_?: Constant
118
120
  * console.log(stats.initialized.has('data')) // true
119
121
  * ```
120
122
  */
121
- /*@__NO_SIDE_EFFECTS__*/
122
123
  export declare function createLazyGetter<T>(name: PropertyKey, getter: () => T, stats?: LazyGetterStats | undefined): () => T;
123
124
  /**
124
125
  * Define a getter property on an object.
@@ -210,7 +211,6 @@ export declare function defineLazyGetters(object: object, getterDefObj: GetterDe
210
211
  * // [['apple', 2], ['banana', 3], ['zebra', 1]]
211
212
  * ```
212
213
  */
213
- /*@__NO_SIDE_EFFECTS__*/
214
214
  export declare function entryKeyComparator(a: [PropertyKey, unknown], b: [PropertyKey, unknown]): number;
215
215
  /**
216
216
  * Get the enumerable own property keys of an object.
@@ -230,7 +230,6 @@ export declare function entryKeyComparator(a: [PropertyKey, unknown], b: [Proper
230
230
  * getKeys('hello') // []
231
231
  * ```
232
232
  */
233
- /*@__NO_SIDE_EFFECTS__*/
234
233
  export declare function getKeys(obj: unknown): string[];
235
234
  /**
236
235
  * Get an own property value from an object safely.
@@ -253,7 +252,6 @@ export declare function getKeys(obj: unknown): string[];
253
252
  * getOwn(undefined, 'name') // undefined
254
253
  * ```
255
254
  */
256
- /*@__NO_SIDE_EFFECTS__*/
257
255
  export declare function getOwn(obj: unknown, propKey: PropertyKey): unknown;
258
256
  /**
259
257
  * Get all own property values from an object.
@@ -272,7 +270,6 @@ export declare function getOwn(obj: unknown, propKey: PropertyKey): unknown;
272
270
  * getOwnPropertyValues(undefined) // []
273
271
  * ```
274
272
  */
275
- /*@__NO_SIDE_EFFECTS__*/
276
273
  export declare function getOwnPropertyValues<T>(obj: {
277
274
  [key: PropertyKey]: T;
278
275
  } | null | undefined): T[];
@@ -296,7 +293,6 @@ export declare function getOwnPropertyValues<T>(obj: {
296
293
  * hasKeys(Object.create({ inherited: true })) // false (inherited, not own)
297
294
  * ```
298
295
  */
299
- /*@__NO_SIDE_EFFECTS__*/
300
296
  export declare function hasKeys(obj: unknown): obj is PropertyBag;
301
297
  /**
302
298
  * Check if an object has an own property.
@@ -319,7 +315,6 @@ export declare function hasKeys(obj: unknown): obj is PropertyBag;
319
315
  * hasOwn(undefined, 'name') // false
320
316
  * ```
321
317
  */
322
- /*@__NO_SIDE_EFFECTS__*/
323
318
  export declare function hasOwn(obj: unknown, propKey: PropertyKey): obj is object & PropertyBag;
324
319
  /**
325
320
  * Check if a value is an object (including arrays).
@@ -342,7 +337,6 @@ export declare function hasOwn(obj: unknown, propKey: PropertyKey): obj is objec
342
337
  * isObject('string') // false
343
338
  * ```
344
339
  */
345
- /*@__NO_SIDE_EFFECTS__*/
346
340
  export declare function isObject(value: unknown): value is {
347
341
  [key: PropertyKey]: unknown;
348
342
  };
@@ -366,33 +360,9 @@ export declare function isObject(value: unknown): value is {
366
360
  * isObjectObject(42) // false
367
361
  * ```
368
362
  */
369
- /*@__NO_SIDE_EFFECTS__*/
370
363
  export declare function isObjectObject(value: unknown): value is {
371
364
  [key: PropertyKey]: unknown;
372
365
  };
373
- // IMPORTANT: Do not use destructuring here - use direct assignment instead.
374
- // tsgo has a bug that incorrectly transpiles destructured exports, resulting in
375
- // `exports.SomeName = void 0;` which causes runtime errors.
376
- // See: https://github.com/SocketDev/socket-packageurl-js/issues/3
377
- /**
378
- * Alias for native `Object.assign`.
379
- *
380
- * Copies all enumerable own properties from one or more source objects
381
- * to a target object and returns the modified target object.
382
- *
383
- * @example
384
- * ```ts
385
- * const target = { a: 1 }
386
- * const source = { b: 2, c: 3 }
387
- * objectAssign(target, source) // { a: 1, b: 2, c: 3 }
388
- * ```
389
- */
390
- export declare const objectAssign: {
391
- <T extends {}, U>(target: T, source: U): T & U;
392
- <T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V;
393
- <T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
394
- (target: object, ...sources: any[]): any;
395
- };
396
366
  /**
397
367
  * Deep merge source object into target object.
398
368
  *
@@ -425,8 +395,26 @@ export declare const objectAssign: {
425
395
  * // { config: { api: 'v2', timeout: 1000, retries: 3 } }
426
396
  * ```
427
397
  */
428
- /*@__NO_SIDE_EFFECTS__*/
429
398
  export declare function merge<T extends object, U extends object>(target: T, source: U): T & U;
399
+ /**
400
+ * Alias for native `Object.assign`.
401
+ *
402
+ * Copies all enumerable own properties from one or more source objects
403
+ * to a target object and returns the modified target object.
404
+ *
405
+ * @example
406
+ * ```ts
407
+ * const target = { a: 1 }
408
+ * const source = { b: 2, c: 3 }
409
+ * objectAssign(target, source) // { a: 1, b: 2, c: 3 }
410
+ * ```
411
+ */
412
+ export declare const objectAssign: {
413
+ <T extends {}, U>(target: T, source: U): T & U;
414
+ <T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V;
415
+ <T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
416
+ (target: object, ...sources: any[]): any;
417
+ };
430
418
  /**
431
419
  * Get all own property entries (key-value pairs) from an object.
432
420
  *
@@ -445,12 +433,7 @@ export declare function merge<T extends object, U extends object>(target: T, sou
445
433
  * objectEntries(undefined) // []
446
434
  * ```
447
435
  */
448
- /*@__NO_SIDE_EFFECTS__*/
449
436
  export declare function objectEntries(obj: unknown): Array<[PropertyKey, unknown]>;
450
- // IMPORTANT: Do not use destructuring here - use direct assignment instead.
451
- // tsgo has a bug that incorrectly transpiles destructured exports, resulting in
452
- // `exports.SomeName = void 0;` which causes runtime errors.
453
- // See: https://github.com/SocketDev/socket-packageurl-js/issues/3
454
437
  /**
455
438
  * Alias for native `Object.freeze`.
456
439
  *
@@ -468,8 +451,8 @@ export declare function objectEntries(obj: unknown): Array<[PropertyKey, unknown
468
451
  export declare const objectFreeze: {
469
452
  <T extends Function>(f: T): T;
470
453
  <T extends {
471
- [idx: string]: object | U;
472
- }, U extends string | number | bigint | symbol | boolean>(o: T): Readonly<T>;
454
+ [idx: string]: U | null | undefined | object;
455
+ }, U extends string | bigint | number | boolean | symbol>(o: T): Readonly<T>;
473
456
  <T>(o: T): Readonly<T>;
474
457
  };
475
458
  /**
@@ -493,7 +476,6 @@ export declare const objectFreeze: {
493
476
  * // { [Symbol(first)]: 4, [Symbol(second)]: 2, a: 3, z: 1 }
494
477
  * ```
495
478
  */
496
- /*@__NO_SIDE_EFFECTS__*/
497
479
  export declare function toSortedObject<T extends object>(obj: T): T;
498
480
  /**
499
481
  * Create an object from entries with sorted keys.
@@ -515,5 +497,4 @@ export declare function toSortedObject<T extends object>(obj: T): T;
515
497
  * // { alpha: 1, beta: 2, gamma: 3 }
516
498
  * ```
517
499
  */
518
- /*@__NO_SIDE_EFFECTS__*/
519
500
  export declare function toSortedObjectFromEntries<T = unknown>(entries: Iterable<[PropertyKey, T]>): SortedObject<T>;
package/dist/objects.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;
@@ -207,7 +208,6 @@ function isObjectObject(value) {
207
208
  const proto = ObjectGetPrototypeOf(value);
208
209
  return proto === null || proto === ObjectPrototype;
209
210
  }
210
- const objectAssign = Object.assign;
211
211
  // @__NO_SIDE_EFFECTS__
212
212
  function merge(target, source) {
213
213
  if (!/* @__PURE__ */ isObject(target) || !/* @__PURE__ */ isObject(source)) {
@@ -249,6 +249,7 @@ function merge(target, source) {
249
249
  }
250
250
  return target;
251
251
  }
252
+ const objectAssign = Object.assign;
252
253
  // @__NO_SIDE_EFFECTS__
253
254
  function objectEntries(obj) {
254
255
  if (obj === null || obj === void 0) {
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @fileoverview Package extensions for compatibility adjustments.
3
+ *
4
+ * Package extensions allow modifying package.json fields of dependencies
5
+ * to fix compatibility issues, missing peer dependencies, etc.
6
+ */
1
7
  type PackageExtension = readonly [string, Record<string, unknown>];
2
8
  declare const packageExtensions: readonly PackageExtension[];
3
9
  export { packageExtensions };
@@ -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;
@@ -32,7 +33,7 @@ __export(package_extensions_exports, {
32
33
  packageExtensions: () => packageExtensions
33
34
  });
34
35
  module.exports = __toCommonJS(package_extensions_exports);
35
- var yarnPkgExtensions = __toESM(require("./external/@yarnpkg/extensions.js"));
36
+ var yarnPkgExtensions = __toESM(require("./external/@yarnpkg/extensions"));
36
37
  const { freeze: ObjectFreeze } = Object;
37
38
  const packageExtensions = ObjectFreeze(
38
39
  [
@@ -1,5 +1,7 @@
1
+ /**
2
+ * @fileoverview Editable package.json manipulation utilities.
3
+ */
1
4
  import type { EditablePackageJsonOptions, NormalizeOptions, PackageJson, SaveOptions } from '../packages';
2
- // Define the interface for the dynamic class
3
5
  interface EditablePackageJsonConstructor {
4
6
  new (): EditablePackageJsonInstance;
5
7
  fixSteps: unknown[];
@@ -91,7 +93,6 @@ export interface EditablePackageJsonInstance {
91
93
  * console.log(pkg.content.name)
92
94
  * ```
93
95
  */
94
- /*@__NO_SIDE_EFFECTS__*/
95
96
  export declare function getEditablePackageJsonClass(): EditablePackageJsonConstructor;
96
97
  /**
97
98
  * Convert a package.json object to an editable instance.
@@ -101,7 +102,6 @@ export declare function getEditablePackageJsonClass(): EditablePackageJsonConstr
101
102
  * const editable = pkgJsonToEditable({ name: 'my-pkg', version: '1.0.0' })
102
103
  * ```
103
104
  */
104
- /*@__NO_SIDE_EFFECTS__*/
105
105
  export declare function pkgJsonToEditable(pkgJson: PackageJson, options?: EditablePackageJsonOptions): unknown;
106
106
  /**
107
107
  * Convert package.json to editable instance with file persistence.
@@ -114,7 +114,6 @@ export declare function pkgJsonToEditable(pkgJson: PackageJson, options?: Editab
114
114
  * )
115
115
  * ```
116
116
  */
117
- /*@__NO_SIDE_EFFECTS__*/
118
117
  export declare function toEditablePackageJson(pkgJson: PackageJson, options?: EditablePackageJsonOptions): Promise<unknown>;
119
118
  /**
120
119
  * Convert package.json to editable instance with file persistence synchronously.
@@ -127,6 +126,5 @@ export declare function toEditablePackageJson(pkgJson: PackageJson, options?: Ed
127
126
  * )
128
127
  * ```
129
128
  */
130
- /*@__NO_SIDE_EFFECTS__*/
131
129
  export declare function toEditablePackageJsonSync(pkgJson: PackageJson, options?: EditablePackageJsonOptions): unknown;
132
130
  export {};
@@ -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;
@@ -47,7 +48,7 @@ let _fs;
47
48
  // @__NO_SIDE_EFFECTS__
48
49
  function getFs() {
49
50
  if (_fs === void 0) {
50
- _fs = require("fs");
51
+ _fs = require("node:fs");
51
52
  }
52
53
  return _fs;
53
54
  }
@@ -55,7 +56,7 @@ let _path;
55
56
  // @__NO_SIDE_EFFECTS__
56
57
  function getPath() {
57
58
  if (_path === void 0) {
58
- _path = require("path");
59
+ _path = require("node:path");
59
60
  }
60
61
  return _path;
61
62
  }
@@ -63,7 +64,7 @@ let _util;
63
64
  // @__NO_SIDE_EFFECTS__
64
65
  function getUtil() {
65
66
  if (_util === void 0) {
66
- _util = require("util");
67
+ _util = require("node:util");
67
68
  }
68
69
  return _util;
69
70
  }
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @fileoverview Package exports field utilities.
3
+ */
1
4
  /**
2
5
  * Find types definition for a specific subpath in package exports.
3
6
  *
@@ -8,30 +11,27 @@
8
11
  * // types === './dist/index.d.ts'
9
12
  * ```
10
13
  */
11
- /*@__NO_SIDE_EFFECTS__*/
12
14
  export declare function findTypesForSubpath(entryExports: unknown, subpath: string): string | undefined;
13
15
  /**
14
- * Get subpaths from package exports.
16
+ * Get file paths from package exports.
15
17
  *
16
18
  * @example
17
19
  * ```typescript
18
- * const exports = { '.': './index.js', './utils': './utils.js' }
19
- * getSubpaths(exports) // ['.', './utils']
20
+ * const exports = { '.': './dist/index.js', './utils': './dist/utils.js' }
21
+ * getExportFilePaths(exports) // ['./dist/index.js', './dist/utils.js']
20
22
  * ```
21
23
  */
22
- /*@__NO_SIDE_EFFECTS__*/
23
- export declare function getSubpaths(entryExports: unknown): string[];
24
+ export declare function getExportFilePaths(entryExports: unknown): string[];
24
25
  /**
25
- * Get file paths from package exports.
26
+ * Get subpaths from package exports.
26
27
  *
27
28
  * @example
28
29
  * ```typescript
29
- * const exports = { '.': './dist/index.js', './utils': './dist/utils.js' }
30
- * getExportFilePaths(exports) // ['./dist/index.js', './dist/utils.js']
30
+ * const exports = { '.': './index.js', './utils': './utils.js' }
31
+ * getSubpaths(exports) // ['.', './utils']
31
32
  * ```
32
33
  */
33
- /*@__NO_SIDE_EFFECTS__*/
34
- export declare function getExportFilePaths(entryExports: unknown): string[];
34
+ export declare function getSubpaths(entryExports: unknown): string[];
35
35
  /**
36
36
  * Check if package exports use conditional patterns (e.g., import/require).
37
37
  *
@@ -41,7 +41,6 @@ export declare function getExportFilePaths(entryExports: unknown): string[];
41
41
  * isConditionalExports({ '.': './index.js' }) // false
42
42
  * ```
43
43
  */
44
- /*@__NO_SIDE_EFFECTS__*/
45
44
  export declare function isConditionalExports(entryExports: unknown): boolean;
46
45
  /**
47
46
  * Check if package exports use subpath patterns (keys starting with '.').
@@ -52,7 +51,6 @@ export declare function isConditionalExports(entryExports: unknown): boolean;
52
51
  * isSubpathExports({ import: './index.mjs' }) // false
53
52
  * ```
54
53
  */
55
- /*@__NO_SIDE_EFFECTS__*/
56
54
  export declare function isSubpathExports(entryExports: unknown): boolean;
57
55
  /**
58
56
  * Normalize package.json exports field to canonical format.
@@ -66,5 +64,4 @@ export declare function isSubpathExports(entryExports: unknown): boolean;
66
64
  * // { '.': './index.js' }
67
65
  * ```
68
66
  */
69
- /*@__NO_SIDE_EFFECTS__*/
70
67
  export declare function resolvePackageJsonEntryExports(entryExports: unknown): unknown;