@socketsecurity/lib 4.3.0 → 5.0.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 (54) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/README.md +1 -1
  3. package/dist/constants/node.js +1 -1
  4. package/dist/{package-default-node-range.js → constants/package-default-node-range.js} +1 -1
  5. package/dist/constants/packages.js +3 -3
  6. package/dist/{dlx-binary.d.ts → dlx/binary.d.ts} +2 -2
  7. package/dist/{dlx-binary.js → dlx/binary.js} +17 -17
  8. package/dist/dlx/cache.d.ts +25 -0
  9. package/dist/dlx/cache.js +32 -0
  10. package/dist/dlx/dir.d.ts +24 -0
  11. package/dist/dlx/dir.js +79 -0
  12. package/dist/{dlx-manifest.js → dlx/manifest.js} +7 -7
  13. package/dist/{dlx-package.d.ts → dlx/package.d.ts} +2 -2
  14. package/dist/{dlx-package.js → dlx/package.js} +16 -16
  15. package/dist/dlx/packages.d.ts +24 -0
  16. package/dist/dlx/packages.js +125 -0
  17. package/dist/dlx/paths.d.ts +31 -0
  18. package/dist/dlx/paths.js +75 -0
  19. package/dist/fs.d.ts +103 -55
  20. package/dist/fs.js +149 -41
  21. package/dist/json/edit.d.ts +16 -0
  22. package/dist/json/edit.js +217 -0
  23. package/dist/json/format.d.ts +140 -0
  24. package/dist/json/format.js +121 -0
  25. package/dist/json/parse.d.ts +76 -0
  26. package/dist/{json.js → json/parse.js} +4 -4
  27. package/dist/json/types.d.ts +229 -0
  28. package/dist/json/types.js +17 -0
  29. package/dist/objects.d.ts +61 -61
  30. package/dist/objects.js +30 -30
  31. package/dist/packages/{editable.js → edit.js} +18 -32
  32. package/dist/packages/operations.js +3 -3
  33. package/dist/packages.d.ts +2 -2
  34. package/dist/packages.js +5 -5
  35. package/dist/promises.d.ts +19 -19
  36. package/dist/promises.js +14 -14
  37. package/dist/sorts.d.ts +10 -10
  38. package/dist/sorts.js +19 -19
  39. package/dist/strings.d.ts +63 -63
  40. package/dist/strings.js +18 -18
  41. package/dist/suppress-warnings.js +4 -0
  42. package/package.json +59 -35
  43. package/dist/dlx.d.ts +0 -104
  44. package/dist/dlx.js +0 -220
  45. package/dist/json.d.ts +0 -196
  46. /package/dist/{lifecycle-script-names.d.ts → constants/lifecycle-script-names.d.ts} +0 -0
  47. /package/dist/{lifecycle-script-names.js → constants/lifecycle-script-names.js} +0 -0
  48. /package/dist/{maintained-node-versions.d.ts → constants/maintained-node-versions.d.ts} +0 -0
  49. /package/dist/{maintained-node-versions.js → constants/maintained-node-versions.js} +0 -0
  50. /package/dist/{package-default-node-range.d.ts → constants/package-default-node-range.d.ts} +0 -0
  51. /package/dist/{package-default-socket-categories.d.ts → constants/package-default-socket-categories.d.ts} +0 -0
  52. /package/dist/{package-default-socket-categories.js → constants/package-default-socket-categories.js} +0 -0
  53. /package/dist/{dlx-manifest.d.ts → dlx/manifest.d.ts} +0 -0
  54. /package/dist/packages/{editable.d.ts → edit.d.ts} +0 -0
package/dist/promises.js CHANGED
@@ -101,20 +101,6 @@ function normalizeRetryOptions(options) {
101
101
  };
102
102
  }
103
103
  // @__NO_SIDE_EFFECTS__
104
- function resolveRetryOptions(options) {
105
- const defaults = {
106
- __proto__: null,
107
- retries: 0,
108
- baseDelayMs: 200,
109
- maxDelayMs: 1e4,
110
- backoffFactor: 2
111
- };
112
- if (typeof options === "number") {
113
- return { ...defaults, retries: options };
114
- }
115
- return options ? { ...defaults, ...options } : defaults;
116
- }
117
- // @__NO_SIDE_EFFECTS__
118
104
  async function pEach(array, callbackFn, options) {
119
105
  const iterOpts = /* @__PURE__ */ normalizeIterationOptions(options);
120
106
  const { concurrency, retries, signal } = iterOpts;
@@ -259,6 +245,20 @@ async function pRetry(callbackFn, options) {
259
245
  }
260
246
  return void 0;
261
247
  }
248
+ // @__NO_SIDE_EFFECTS__
249
+ function resolveRetryOptions(options) {
250
+ const defaults = {
251
+ __proto__: null,
252
+ retries: 0,
253
+ baseDelayMs: 200,
254
+ maxDelayMs: 1e4,
255
+ backoffFactor: 2
256
+ };
257
+ if (typeof options === "number") {
258
+ return { ...defaults, retries: options };
259
+ }
260
+ return options ? { ...defaults, ...options } : defaults;
261
+ }
262
262
  // Annotate the CommonJS export names for ESM import in node:
263
263
  0 && (module.exports = {
264
264
  normalizeIterationOptions,
package/dist/sorts.d.ts CHANGED
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Compare semantic versions.
3
+ */
4
+ /*@__NO_SIDE_EFFECTS__*/
5
+ export declare function compareSemver(a: string, b: string): number;
6
+ /**
7
+ * Simple string comparison.
8
+ */
9
+ /*@__NO_SIDE_EFFECTS__*/
10
+ export declare function compareStr(a: string, b: string): number;
1
11
  /**
2
12
  * Compare two strings using locale-aware comparison.
3
13
  */
@@ -15,14 +25,4 @@ type FastSortFunction = ReturnType<typeof import('fast-sort').createNewSortInsta
15
25
  */
16
26
  /*@__NO_SIDE_EFFECTS__*/
17
27
  export declare function naturalSorter<T>(arrayToSort: T[]): ReturnType<FastSortFunction>;
18
- /**
19
- * Simple string comparison.
20
- */
21
- /*@__NO_SIDE_EFFECTS__*/
22
- export declare function compareStr(a: string, b: string): number;
23
- /**
24
- * Compare semantic versions.
25
- */
26
- /*@__NO_SIDE_EFFECTS__*/
27
- export declare function compareSemver(a: string, b: string): number;
28
28
  export {};
package/dist/sorts.js CHANGED
@@ -38,6 +38,25 @@ __export(sorts_exports, {
38
38
  module.exports = __toCommonJS(sorts_exports);
39
39
  var fastSort = __toESM(require("./external/fast-sort.js"));
40
40
  var semver = __toESM(require("./external/semver.js"));
41
+ // @__NO_SIDE_EFFECTS__
42
+ function compareSemver(a, b) {
43
+ const validA = semver.valid(a);
44
+ const validB = semver.valid(b);
45
+ if (!validA && !validB) {
46
+ return 0;
47
+ }
48
+ if (!validA) {
49
+ return -1;
50
+ }
51
+ if (!validB) {
52
+ return 1;
53
+ }
54
+ return semver.compare(a, b);
55
+ }
56
+ // @__NO_SIDE_EFFECTS__
57
+ function compareStr(a, b) {
58
+ return a < b ? -1 : a > b ? 1 : 0;
59
+ }
41
60
  let _localeCompare;
42
61
  // @__NO_SIDE_EFFECTS__
43
62
  function localeCompare(x, y) {
@@ -77,25 +96,6 @@ function naturalSorter(arrayToSort) {
77
96
  }
78
97
  return _naturalSorter(arrayToSort);
79
98
  }
80
- // @__NO_SIDE_EFFECTS__
81
- function compareStr(a, b) {
82
- return a < b ? -1 : a > b ? 1 : 0;
83
- }
84
- // @__NO_SIDE_EFFECTS__
85
- function compareSemver(a, b) {
86
- const validA = semver.valid(a);
87
- const validB = semver.valid(b);
88
- if (!validA && !validB) {
89
- return 0;
90
- }
91
- if (!validA) {
92
- return -1;
93
- }
94
- if (!validB) {
95
- return 1;
96
- }
97
- return semver.compare(a, b);
98
- }
99
99
  // Annotate the CommonJS export names for ESM import in node:
100
100
  0 && (module.exports = {
101
101
  compareSemver,
package/dist/strings.d.ts CHANGED
@@ -85,6 +85,41 @@ export declare function applyLinePrefix(str: string, options?: ApplyLinePrefixOp
85
85
  */
86
86
  /*@__NO_SIDE_EFFECTS__*/
87
87
  export declare function camelToKebab(str: string): string;
88
+ /**
89
+ * Center text within a given width.
90
+ *
91
+ * Adds spaces before and after the text to center it within the specified width.
92
+ * Distributes padding evenly on both sides. When the padding is odd, the extra
93
+ * space is added to the right side. Strips ANSI codes before calculating text
94
+ * length to ensure accurate centering of colored text.
95
+ *
96
+ * If the text is already wider than or equal to the target width, returns the
97
+ * original text unchanged (no truncation occurs).
98
+ *
99
+ * @param text - The text to center (may include ANSI codes)
100
+ * @param width - The target width in columns
101
+ * @returns The centered text with padding
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * centerText('hello', 11)
106
+ * // Returns: ' hello ' (3 spaces on each side)
107
+ *
108
+ * centerText('hi', 10)
109
+ * // Returns: ' hi ' (4 spaces on each side)
110
+ *
111
+ * centerText('odd', 8)
112
+ * // Returns: ' odd ' (2 left, 3 right)
113
+ *
114
+ * centerText('\x1b[31mred\x1b[0m', 7)
115
+ * // Returns: ' \x1b[31mred\x1b[0m ' (ANSI codes preserved, 'red' centered)
116
+ *
117
+ * centerText('too long text', 5)
118
+ * // Returns: 'too long text' (no truncation, returned as-is)
119
+ * ```
120
+ */
121
+ /*@__NO_SIDE_EFFECTS__*/
122
+ export declare function centerText(text: string, width: number): string;
88
123
  export interface IndentStringOptions {
89
124
  /**
90
125
  * Number of spaces to indent each line.
@@ -181,6 +216,33 @@ export declare function isBlankString(value: unknown): value is BlankString;
181
216
  */
182
217
  /*@__NO_SIDE_EFFECTS__*/
183
218
  export declare function isNonEmptyString(value: unknown): value is Exclude<string, EmptyString>;
219
+ /**
220
+ * Repeat a string a specified number of times.
221
+ *
222
+ * Creates a new string by repeating the input string `count` times.
223
+ * Returns an empty string if count is 0 or negative.
224
+ *
225
+ * @param str - The string to repeat
226
+ * @param count - The number of times to repeat the string
227
+ * @returns The repeated string, or empty string if count <= 0
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * repeatString('hello', 3)
232
+ * // Returns: 'hellohellohello'
233
+ *
234
+ * repeatString('x', 5)
235
+ * // Returns: 'xxxxx'
236
+ *
237
+ * repeatString('hello', 0)
238
+ * // Returns: ''
239
+ *
240
+ * repeatString('hello', -1)
241
+ * // Returns: ''
242
+ * ```
243
+ */
244
+ /*@__NO_SIDE_EFFECTS__*/
245
+ export declare function repeatString(str: string, count: number): string;
184
246
  export interface SearchOptions {
185
247
  /**
186
248
  * The position in the string to begin searching from.
@@ -252,6 +314,7 @@ export declare function search(str: string, regexp: RegExp, options?: SearchOpti
252
314
  */
253
315
  /*@__NO_SIDE_EFFECTS__*/
254
316
  export declare function stripBom(str: string): string;
317
+ /* c8 ignore stop */
255
318
  /**
256
319
  * Get the visual width of a string in terminal columns.
257
320
  *
@@ -403,66 +466,3 @@ export declare function toKebabCase(str: string): string;
403
466
  */
404
467
  /*@__NO_SIDE_EFFECTS__*/
405
468
  export declare function trimNewlines(str: string): string;
406
- /**
407
- * Repeat a string n times.
408
- *
409
- * Creates a new string by repeating the input string the specified number of times.
410
- * Returns an empty string if count is zero or negative. This is a simple wrapper
411
- * around `String.prototype.repeat()` with guard for non-positive counts.
412
- *
413
- * @param str - The string to repeat
414
- * @param count - The number of times to repeat the string
415
- * @returns The repeated string, or empty string if count <= 0
416
- *
417
- * @example
418
- * ```ts
419
- * repeatString('hello', 3)
420
- * // Returns: 'hellohellohello'
421
- *
422
- * repeatString('x', 5)
423
- * // Returns: 'xxxxx'
424
- *
425
- * repeatString('hello', 0)
426
- * // Returns: ''
427
- *
428
- * repeatString('hello', -1)
429
- * // Returns: ''
430
- * ```
431
- */
432
- /*@__NO_SIDE_EFFECTS__*/
433
- export declare function repeatString(str: string, count: number): string;
434
- /**
435
- * Center text within a given width.
436
- *
437
- * Adds spaces before and after the text to center it within the specified width.
438
- * Distributes padding evenly on both sides. When the padding is odd, the extra
439
- * space is added to the right side. Strips ANSI codes before calculating text
440
- * length to ensure accurate centering of colored text.
441
- *
442
- * If the text is already wider than or equal to the target width, returns the
443
- * original text unchanged (no truncation occurs).
444
- *
445
- * @param text - The text to center (may include ANSI codes)
446
- * @param width - The target width in columns
447
- * @returns The centered text with padding
448
- *
449
- * @example
450
- * ```ts
451
- * centerText('hello', 11)
452
- * // Returns: ' hello ' (3 spaces on each side)
453
- *
454
- * centerText('hi', 10)
455
- * // Returns: ' hi ' (4 spaces on each side)
456
- *
457
- * centerText('odd', 8)
458
- * // Returns: ' odd ' (2 left, 3 right)
459
- *
460
- * centerText('\x1b[31mred\x1b[0m', 7)
461
- * // Returns: ' \x1b[31mred\x1b[0m ' (ANSI codes preserved, 'red' centered)
462
- *
463
- * centerText('too long text', 5)
464
- * // Returns: 'too long text' (no truncation, returned as-is)
465
- * ```
466
- */
467
- /*@__NO_SIDE_EFFECTS__*/
468
- export declare function centerText(text: string, width: number): string;
package/dist/strings.js CHANGED
@@ -92,6 +92,17 @@ function camelToKebab(str) {
92
92
  return result;
93
93
  }
94
94
  // @__NO_SIDE_EFFECTS__
95
+ function centerText(text, width) {
96
+ const textLength = (0, import_ansi.stripAnsi)(text).length;
97
+ if (textLength >= width) {
98
+ return text;
99
+ }
100
+ const padding = width - textLength;
101
+ const leftPad = Math.floor(padding / 2);
102
+ const rightPad = padding - leftPad;
103
+ return " ".repeat(leftPad) + text + " ".repeat(rightPad);
104
+ }
105
+ // @__NO_SIDE_EFFECTS__
95
106
  function indentString(str, options) {
96
107
  const { count = 1 } = { __proto__: null, ...options };
97
108
  return str.replace(/^(?!\s*$)/gm, " ".repeat(count));
@@ -105,6 +116,13 @@ function isNonEmptyString(value) {
105
116
  return typeof value === "string" && value.length > 0;
106
117
  }
107
118
  // @__NO_SIDE_EFFECTS__
119
+ function repeatString(str, count) {
120
+ if (count <= 0) {
121
+ return "";
122
+ }
123
+ return str.repeat(count);
124
+ }
125
+ // @__NO_SIDE_EFFECTS__
108
126
  function search(str, regexp, options) {
109
127
  const { fromIndex = 0 } = { __proto__: null, ...options };
110
128
  const { length } = str;
@@ -215,24 +233,6 @@ function trimNewlines(str) {
215
233
  }
216
234
  return start === 0 && end === length ? str : str.slice(start, end);
217
235
  }
218
- // @__NO_SIDE_EFFECTS__
219
- function repeatString(str, count) {
220
- if (count <= 0) {
221
- return "";
222
- }
223
- return str.repeat(count);
224
- }
225
- // @__NO_SIDE_EFFECTS__
226
- function centerText(text, width) {
227
- const textLength = (0, import_ansi.stripAnsi)(text).length;
228
- if (textLength >= width) {
229
- return text;
230
- }
231
- const padding = width - textLength;
232
- const leftPad = Math.floor(padding / 2);
233
- const rightPad = padding - leftPad;
234
- return " ".repeat(leftPad) + text + " ".repeat(rightPad);
235
- }
236
236
  // Annotate the CommonJS export names for ESM import in node:
237
237
  0 && (module.exports = {
238
238
  ansiRegex,
@@ -82,11 +82,15 @@ function restoreWarnings() {
82
82
  }
83
83
  }
84
84
  async function withSuppressedWarnings(warningType, callback) {
85
+ const wasAlreadySuppressed = suppressedWarnings.has(warningType);
85
86
  const original = process.emitWarning;
86
87
  suppressWarningType(warningType);
87
88
  try {
88
89
  return await callback();
89
90
  } finally {
91
+ if (!wasAlreadySuppressed) {
92
+ suppressedWarnings.delete(warningType);
93
+ }
90
94
  process.emitWarning = original;
91
95
  }
92
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socketsecurity/lib",
3
- "version": "4.3.0",
3
+ "version": "5.0.0",
4
4
  "packageManager": "pnpm@10.22.0",
5
5
  "license": "MIT",
6
6
  "description": "Core utilities and infrastructure for Socket.dev security tools",
@@ -151,10 +151,26 @@
151
151
  "types": "./dist/constants/licenses.d.ts",
152
152
  "default": "./dist/constants/licenses.js"
153
153
  },
154
+ "./constants/lifecycle-script-names": {
155
+ "types": "./dist/constants/lifecycle-script-names.d.ts",
156
+ "default": "./dist/constants/lifecycle-script-names.js"
157
+ },
158
+ "./constants/maintained-node-versions": {
159
+ "types": "./dist/constants/maintained-node-versions.d.ts",
160
+ "default": "./dist/constants/maintained-node-versions.js"
161
+ },
154
162
  "./constants/node": {
155
163
  "types": "./dist/constants/node.d.ts",
156
164
  "default": "./dist/constants/node.js"
157
165
  },
166
+ "./constants/package-default-node-range": {
167
+ "types": "./dist/constants/package-default-node-range.d.ts",
168
+ "default": "./dist/constants/package-default-node-range.js"
169
+ },
170
+ "./constants/package-default-socket-categories": {
171
+ "types": "./dist/constants/package-default-socket-categories.d.ts",
172
+ "default": "./dist/constants/package-default-socket-categories.js"
173
+ },
158
174
  "./constants/packages": {
159
175
  "types": "./dist/constants/packages.d.ts",
160
176
  "default": "./dist/constants/packages.js"
@@ -203,21 +219,33 @@
203
219
  "types": "./dist/debug.d.ts",
204
220
  "default": "./dist/debug.js"
205
221
  },
206
- "./dlx": {
207
- "types": "./dist/dlx.d.ts",
208
- "default": "./dist/dlx.js"
222
+ "./dlx/binary": {
223
+ "types": "./dist/dlx/binary.d.ts",
224
+ "default": "./dist/dlx/binary.js"
225
+ },
226
+ "./dlx/cache": {
227
+ "types": "./dist/dlx/cache.d.ts",
228
+ "default": "./dist/dlx/cache.js"
229
+ },
230
+ "./dlx/dir": {
231
+ "types": "./dist/dlx/dir.d.ts",
232
+ "default": "./dist/dlx/dir.js"
209
233
  },
210
- "./dlx-binary": {
211
- "types": "./dist/dlx-binary.d.ts",
212
- "default": "./dist/dlx-binary.js"
234
+ "./dlx/manifest": {
235
+ "types": "./dist/dlx/manifest.d.ts",
236
+ "default": "./dist/dlx/manifest.js"
213
237
  },
214
- "./dlx-manifest": {
215
- "types": "./dist/dlx-manifest.d.ts",
216
- "default": "./dist/dlx-manifest.js"
238
+ "./dlx/package": {
239
+ "types": "./dist/dlx/package.d.ts",
240
+ "default": "./dist/dlx/package.js"
217
241
  },
218
- "./dlx-package": {
219
- "types": "./dist/dlx-package.d.ts",
220
- "default": "./dist/dlx-package.js"
242
+ "./dlx/packages": {
243
+ "types": "./dist/dlx/packages.d.ts",
244
+ "default": "./dist/dlx/packages.js"
245
+ },
246
+ "./dlx/paths": {
247
+ "types": "./dist/dlx/paths.d.ts",
248
+ "default": "./dist/dlx/paths.js"
221
249
  },
222
250
  "./effects/pulse-frames": {
223
251
  "types": "./dist/effects/pulse-frames.d.ts",
@@ -355,13 +383,21 @@
355
383
  "types": "./dist/ipc.d.ts",
356
384
  "default": "./dist/ipc.js"
357
385
  },
358
- "./json": {
359
- "types": "./dist/json.d.ts",
360
- "default": "./dist/json.js"
386
+ "./json/edit": {
387
+ "types": "./dist/json/edit.d.ts",
388
+ "default": "./dist/json/edit.js"
389
+ },
390
+ "./json/format": {
391
+ "types": "./dist/json/format.d.ts",
392
+ "default": "./dist/json/format.js"
393
+ },
394
+ "./json/parse": {
395
+ "types": "./dist/json/parse.d.ts",
396
+ "default": "./dist/json/parse.js"
361
397
  },
362
- "./lifecycle-script-names": {
363
- "types": "./dist/lifecycle-script-names.d.ts",
364
- "default": "./dist/lifecycle-script-names.js"
398
+ "./json/types": {
399
+ "types": "./dist/json/types.d.ts",
400
+ "default": "./dist/json/types.js"
365
401
  },
366
402
  "./links": {
367
403
  "types": "./dist/links/index.d.ts",
@@ -375,10 +411,6 @@
375
411
  "types": "./dist/logger.d.ts",
376
412
  "default": "./dist/logger.js"
377
413
  },
378
- "./maintained-node-versions": {
379
- "types": "./dist/maintained-node-versions.d.ts",
380
- "default": "./dist/maintained-node-versions.js"
381
- },
382
414
  "./memoization": {
383
415
  "types": "./dist/memoization.d.ts",
384
416
  "default": "./dist/memoization.js"
@@ -387,14 +419,6 @@
387
419
  "types": "./dist/objects.d.ts",
388
420
  "default": "./dist/objects.js"
389
421
  },
390
- "./package-default-node-range": {
391
- "types": "./dist/package-default-node-range.d.ts",
392
- "default": "./dist/package-default-node-range.js"
393
- },
394
- "./package-default-socket-categories": {
395
- "types": "./dist/package-default-socket-categories.d.ts",
396
- "default": "./dist/package-default-socket-categories.js"
397
- },
398
422
  "./package-extensions": {
399
423
  "types": "./dist/package-extensions.d.ts",
400
424
  "default": "./dist/package-extensions.js"
@@ -403,9 +427,9 @@
403
427
  "types": "./dist/packages.d.ts",
404
428
  "default": "./dist/packages.js"
405
429
  },
406
- "./packages/editable": {
407
- "types": "./dist/packages/editable.d.ts",
408
- "default": "./dist/packages/editable.js"
430
+ "./packages/edit": {
431
+ "types": "./dist/packages/edit.d.ts",
432
+ "default": "./dist/packages/edit.js"
409
433
  },
410
434
  "./packages/exports": {
411
435
  "types": "./dist/packages/exports.d.ts",
@@ -690,7 +714,7 @@
690
714
  "@socketregistry/is-unicode-supported": "1.0.5",
691
715
  "@socketregistry/packageurl-js": "1.3.5",
692
716
  "@socketregistry/yocto-spinner": "1.0.25",
693
- "@socketsecurity/lib-stable": "npm:@socketsecurity/lib@4.1.0",
717
+ "@socketsecurity/lib-stable": "npm:@socketsecurity/lib@4.3.0",
694
718
  "@types/node": "24.9.2",
695
719
  "@typescript/native-preview": "7.0.0-dev.20250920.1",
696
720
  "@vitest/coverage-v8": "4.0.3",
package/dist/dlx.d.ts DELETED
@@ -1,104 +0,0 @@
1
- /**
2
- * Generate a cache directory name using npm/npx approach.
3
- * Uses first 16 characters of SHA-512 hash (like npm/npx).
4
- *
5
- * Rationale for SHA-512 truncated (vs full SHA-256):
6
- * - Matches npm/npx ecosystem behavior
7
- * - Shorter paths for Windows MAX_PATH compatibility (260 chars)
8
- * - 16 hex chars = 64 bits = acceptable collision risk for local cache
9
- * - Collision probability ~1 in 18 quintillion with 1000 entries
10
- *
11
- * Input strategy (aligned with npx):
12
- * - npx uses package spec strings (e.g., '@scope/pkg@1.0.0', 'prettier@3.0.0')
13
- * - Caller provides complete spec string with version for accurate cache keying
14
- * - For package installs: Use PURL-style spec with version
15
- * Examples: 'npm:prettier@3.0.0', 'pypi:requests@2.31.0', 'gem:rails@7.0.0'
16
- * Note: Socket uses shorthand format without 'pkg:' prefix
17
- * (handled by @socketregistry/packageurl-js)
18
- * - For binary downloads: Use URL:name for uniqueness
19
- *
20
- * Reference: npm/cli v11.6.2 libnpmexec/lib/index.js#L233-L244
21
- * https://github.com/npm/cli/blob/v11.6.2/workspaces/libnpmexec/lib/index.js#L233-L244
22
- * Implementation: packages.map().sort().join('\n') → SHA-512 → slice(0,16)
23
- * npx hashes the package spec (name@version), not just name
24
- */
25
- export declare function generateCacheKey(spec: string): string;
26
- /**
27
- * Clear all DLX package installations.
28
- */
29
- export declare function clearDlx(): Promise<void>;
30
- /**
31
- * Clear all DLX package installations synchronously.
32
- */
33
- export declare function clearDlxSync(): void;
34
- /**
35
- * Check if the DLX directory exists.
36
- */
37
- export declare function dlxDirExists(): boolean;
38
- /**
39
- * Check if the DLX directory exists asynchronously.
40
- */
41
- export declare function dlxDirExistsAsync(): Promise<boolean>;
42
- /**
43
- * Ensure the DLX directory exists, creating it if necessary.
44
- */
45
- export declare function ensureDlxDir(): Promise<void>;
46
- /**
47
- * Ensure the DLX directory exists synchronously, creating it if necessary.
48
- */
49
- export declare function ensureDlxDirSync(): void;
50
- /**
51
- * Get the installed package directory within DLX node_modules.
52
- */
53
- export declare function getDlxInstalledPackageDir(packageName: string): string;
54
- /**
55
- * Get the DLX installation directory for a specific package.
56
- */
57
- export declare function getDlxPackageDir(packageName: string): string;
58
- /**
59
- * Get the package.json path for a DLX installed package.
60
- */
61
- export declare function getDlxPackageJsonPath(packageName: string): string;
62
- /**
63
- * Get the node_modules directory for a DLX package installation.
64
- */
65
- export declare function getDlxPackageNodeModulesDir(packageName: string): string;
66
- /**
67
- * Check if a file path is within the Socket DLX directory.
68
- * This is useful for determining if a binary or file is managed by Socket's DLX system.
69
- *
70
- * @param filePath - Absolute or relative path to check
71
- * @returns true if the path is within ~/.socket/_dlx/, false otherwise
72
- *
73
- * @example
74
- * ```typescript
75
- * isInSocketDlx('/home/user/.socket/_dlx/abc123/bin/socket') // true
76
- * isInSocketDlx('/usr/local/bin/socket') // false
77
- * isInSocketDlx(process.argv[0]) // Check if current binary is in DLX
78
- * ```
79
- */
80
- export declare function isInSocketDlx(filePath: string): boolean;
81
- /**
82
- * Check if a package is installed in DLX.
83
- */
84
- export declare function isDlxPackageInstalled(packageName: string): boolean;
85
- /**
86
- * Check if a package is installed in DLX asynchronously.
87
- */
88
- export declare function isDlxPackageInstalledAsync(packageName: string): Promise<boolean>;
89
- /**
90
- * List all packages installed in DLX.
91
- */
92
- export declare function listDlxPackages(): string[];
93
- /**
94
- * List all packages installed in DLX asynchronously.
95
- */
96
- export declare function listDlxPackagesAsync(): Promise<string[]>;
97
- /**
98
- * Remove a DLX package installation.
99
- */
100
- export declare function removeDlxPackage(packageName: string): Promise<void>;
101
- /**
102
- * Remove a DLX package installation synchronously.
103
- */
104
- export declare function removeDlxPackageSync(packageName: string): void;