@socketsecurity/lib 5.25.1 → 5.26.1

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 (147) hide show
  1. package/CHANGELOG.md +344 -1184
  2. package/README.md +1 -1
  3. package/dist/abort.js +7 -6
  4. package/dist/agent.js +16 -15
  5. package/dist/ansi.js +3 -2
  6. package/dist/archives.js +18 -17
  7. package/dist/argv/flags.js +29 -28
  8. package/dist/argv/parse.js +4 -3
  9. package/dist/arrays.js +3 -2
  10. package/dist/bin.js +12 -11
  11. package/dist/cacache.js +16 -11
  12. package/dist/cache-with-ttl.js +26 -21
  13. package/dist/colors.js +2 -1
  14. package/dist/constants/licenses.js +2 -1
  15. package/dist/constants/lifecycle-script-names.js +2 -1
  16. package/dist/constants/maintained-node-versions.js +2 -1
  17. package/dist/constants/node.js +4 -3
  18. package/dist/constants/package-default-socket-categories.js +2 -1
  19. package/dist/constants/packages.js +4 -3
  20. package/dist/constants/socket.js +1 -1
  21. package/dist/cover/code.js +9 -8
  22. package/dist/cover/formatters.js +12 -11
  23. package/dist/cover/type.js +5 -4
  24. package/dist/crypto.d.ts +36 -0
  25. package/dist/{effects/ultra.js → crypto.js} +33 -37
  26. package/dist/debug.js +12 -15
  27. package/dist/dlx/arborist.js +10 -9
  28. package/dist/dlx/binary.js +27 -24
  29. package/dist/dlx/cache.js +2 -10
  30. package/dist/dlx/detect.js +6 -5
  31. package/dist/dlx/integrity.js +13 -11
  32. package/dist/dlx/lockfile.js +7 -6
  33. package/dist/dlx/manifest.js +6 -5
  34. package/dist/dlx/package.js +17 -16
  35. package/dist/dlx/packages.js +6 -5
  36. package/dist/dlx/paths.d.ts +1 -1
  37. package/dist/dlx/paths.js +2 -1
  38. package/dist/effects/pulse-frames.js +4 -3
  39. package/dist/effects/shimmer-keyframes.d.ts +62 -0
  40. package/dist/effects/shimmer-keyframes.js +55 -0
  41. package/dist/effects/shimmer-terminal.d.ts +66 -0
  42. package/dist/effects/shimmer-terminal.js +57 -0
  43. package/dist/effects/shimmer.d.ts +293 -0
  44. package/dist/effects/shimmer.js +180 -0
  45. package/dist/env/rewire.js +4 -3
  46. package/dist/env.js +5 -4
  47. package/dist/errors.js +1 -1
  48. package/dist/external/@npmcli/package-json/lib/read-package.js +10 -10
  49. package/dist/external/@npmcli/package-json.js +372 -372
  50. package/dist/external/@npmcli/promise-spawn.js +24 -24
  51. package/dist/external/@socketregistry/packageurl-js.js +19 -18
  52. package/dist/external/@socketregistry/yocto-spinner.js +4 -3
  53. package/dist/external/@yarnpkg/extensions.js +2 -1
  54. package/dist/external/adm-zip.js +70 -70
  55. package/dist/external/debug.js +22 -22
  56. package/dist/external/external-pack.js +45 -45
  57. package/dist/external/fast-sort.js +5 -5
  58. package/dist/external/libnpmexec.js +4 -3
  59. package/dist/external/npm-pack.js +369 -369
  60. package/dist/external/p-map.js +9 -9
  61. package/dist/external/pico-pack.js +190 -190
  62. package/dist/external/pony-cause.js +2 -1
  63. package/dist/external/spdx-pack.js +11 -10
  64. package/dist/external/tar-fs.js +58 -58
  65. package/dist/external/which.js +13 -13
  66. package/dist/external/yargs-parser.js +71 -71
  67. package/dist/fs.js +19 -23
  68. package/dist/git.js +14 -13
  69. package/dist/github.d.ts +34 -0
  70. package/dist/github.js +248 -23
  71. package/dist/globs.d.ts +20 -0
  72. package/dist/globs.js +134 -25
  73. package/dist/http-request.d.ts +4 -3
  74. package/dist/http-request.js +39 -32
  75. package/dist/ipc-cli.js +2 -1
  76. package/dist/ipc.js +5 -4
  77. package/dist/json/edit.js +4 -3
  78. package/dist/json/format.js +3 -2
  79. package/dist/json/parse.js +7 -6
  80. package/dist/links.js +2 -1
  81. package/dist/logger.js +21 -14
  82. package/dist/memoization.js +16 -15
  83. package/dist/objects.js +2 -2
  84. package/dist/packages/edit.js +8 -7
  85. package/dist/packages/exports.js +17 -16
  86. package/dist/packages/isolation.js +20 -13
  87. package/dist/packages/licenses.js +6 -3
  88. package/dist/packages/manifest.js +2 -1
  89. package/dist/packages/normalize.js +8 -4
  90. package/dist/packages/operations.js +5 -4
  91. package/dist/packages/provenance.js +7 -6
  92. package/dist/packages/specs.js +2 -1
  93. package/dist/packages/validation.js +2 -1
  94. package/dist/paths/normalize.js +32 -40
  95. package/dist/paths/packages.js +2 -1
  96. package/dist/paths/rewire.js +3 -2
  97. package/dist/performance.js +19 -18
  98. package/dist/primordials.d.ts +9 -0
  99. package/dist/primordials.js +17 -0
  100. package/dist/process-lock.js +14 -13
  101. package/dist/promise-queue.js +17 -9
  102. package/dist/promises.d.ts +29 -6
  103. package/dist/promises.js +19 -15
  104. package/dist/regexps.js +9 -8
  105. package/dist/releases/github-api.d.ts +56 -0
  106. package/dist/releases/github-api.js +275 -0
  107. package/dist/releases/github-archives.d.ts +60 -0
  108. package/dist/releases/github-archives.js +136 -0
  109. package/dist/releases/github-assets.d.ts +21 -0
  110. package/dist/releases/github-assets.js +52 -0
  111. package/dist/releases/github-auth.d.ts +16 -0
  112. package/dist/releases/github-auth.js +51 -0
  113. package/dist/releases/github-downloads.d.ts +42 -0
  114. package/dist/releases/github-downloads.js +155 -0
  115. package/dist/releases/github-types.d.ts +66 -0
  116. package/dist/{effects/types.js → releases/github-types.js} +2 -2
  117. package/dist/releases/socket-btm.d.ts +1 -1
  118. package/dist/releases/socket-btm.js +17 -17
  119. package/dist/schema/parse.js +2 -1
  120. package/dist/schema/validate.js +6 -5
  121. package/dist/shadow.js +2 -1
  122. package/dist/signal-exit.js +2 -2
  123. package/dist/spawn.js +45 -35
  124. package/dist/spinner.d.ts +13 -6
  125. package/dist/spinner.js +75 -57
  126. package/dist/ssri.js +8 -7
  127. package/dist/stdio/footer.js +13 -12
  128. package/dist/stdio/header.js +5 -4
  129. package/dist/stdio/progress.js +13 -12
  130. package/dist/strings.js +19 -18
  131. package/dist/suppress-warnings.js +2 -2
  132. package/dist/tables.js +16 -13
  133. package/dist/temporary-executor.js +2 -1
  134. package/dist/themes/context.js +2 -1
  135. package/dist/themes/types.d.ts +1 -1
  136. package/dist/themes/utils.d.ts +8 -3
  137. package/dist/themes/utils.js +29 -5
  138. package/dist/url.js +4 -3
  139. package/package.json +44 -20
  140. package/dist/effects/text-shimmer.d.ts +0 -58
  141. package/dist/effects/text-shimmer.js +0 -192
  142. package/dist/effects/types.d.ts +0 -47
  143. package/dist/effects/ultra.d.ts +0 -22
  144. package/dist/releases/github.d.ts +0 -234
  145. package/dist/releases/github.js +0 -417
  146. package/dist/themes/index.d.ts +0 -49
  147. package/dist/themes/index.js +0 -60
package/dist/globs.js CHANGED
@@ -20,8 +20,10 @@ var __copyProps = (to, from, except, desc) => {
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
  var globs_exports = {};
22
22
  __export(globs_exports, {
23
+ canUseNodeFsGlob: () => canUseNodeFsGlob,
23
24
  defaultIgnore: () => defaultIgnore,
24
25
  getGlobMatcher: () => getGlobMatcher,
26
+ getMatchesGlob: () => getMatchesGlob,
25
27
  glob: () => glob,
26
28
  globStreamLicenses: () => globStreamLicenses,
27
29
  globSync: () => globSync
@@ -29,10 +31,42 @@ __export(globs_exports, {
29
31
  module.exports = __toCommonJS(globs_exports);
30
32
  var import_objects = require("./objects");
31
33
  var import_globs = require("./paths/globs");
34
+ var import_normalize = require("./paths/normalize");
35
+ var import_promises = require("./promises");
36
+ var import_primordials = require("./primordials");
32
37
  let _fastGlob;
38
+ let _fs;
39
+ let _fsPromises;
33
40
  let _picomatch;
41
+ let _matchesGlob;
42
+ let _matchesGlobProbed = false;
43
+ // @__NO_SIDE_EFFECTS__
44
+ function getFs() {
45
+ if (_fs === void 0) {
46
+ _fs = require("node:fs");
47
+ }
48
+ return _fs;
49
+ }
50
+ // @__NO_SIDE_EFFECTS__
51
+ function getFsPromises() {
52
+ if (_fsPromises === void 0) {
53
+ _fsPromises = require("node:fs/promises");
54
+ }
55
+ return _fsPromises;
56
+ }
57
+ // @__NO_SIDE_EFFECTS__
58
+ function getMatchesGlob() {
59
+ if (!_matchesGlobProbed) {
60
+ const fn = require("node:path").matchesGlob;
61
+ if (typeof fn === "function") {
62
+ _matchesGlob = fn;
63
+ }
64
+ _matchesGlobProbed = true;
65
+ }
66
+ return _matchesGlob;
67
+ }
34
68
  const MATCHER_CACHE_MAX_SIZE = 100;
35
- const matcherCache = /* @__PURE__ */ new Map();
69
+ const matcherCache = new import_primordials.MapCtor();
36
70
  const defaultIgnore = (0, import_objects.objectFreeze)([
37
71
  // Most of these ignored files can be included specifically if included in the
38
72
  // files globs. Exceptions to this are:
@@ -80,6 +114,30 @@ function getFastGlob() {
80
114
  }
81
115
  return _fastGlob;
82
116
  }
117
+ function stripTrailingSlash(pattern) {
118
+ if (pattern.length > 1 && (0, import_primordials.StringPrototypeCharCodeAt)(pattern, pattern.length - 1) === 47) {
119
+ return pattern.slice(0, -1);
120
+ }
121
+ return pattern;
122
+ }
123
+ function normalizeGlobResults(out) {
124
+ for (let i = 0; i < out.length; i += 1) {
125
+ out[i] = (0, import_normalize.normalizePath)(out[i]);
126
+ }
127
+ return out;
128
+ }
129
+ function normalizeIgnorePatterns(ignore) {
130
+ if (!(0, import_primordials.ArrayIsArray)(ignore)) {
131
+ return void 0;
132
+ }
133
+ const source = ignore;
134
+ const { length } = source;
135
+ const normalized = new import_primordials.ArrayCtor(length);
136
+ for (let i = 0; i < length; i++) {
137
+ normalized[i] = stripTrailingSlash(source[i]);
138
+ }
139
+ return normalized;
140
+ }
83
141
  // @__NO_SIDE_EFFECTS__
84
142
  function getPicomatch() {
85
143
  if (_picomatch === void 0) {
@@ -89,12 +147,12 @@ function getPicomatch() {
89
147
  }
90
148
  // @__NO_SIDE_EFFECTS__
91
149
  function getGlobMatcher(glob2, options) {
92
- const patterns = Array.isArray(glob2) ? glob2 : [glob2];
150
+ const patterns = (0, import_primordials.ArrayIsArray)(glob2) ? glob2 : [glob2];
93
151
  const sortedPatterns = [...patterns].sort();
94
- const sortedOptions = options ? Object.keys(options).sort().map((k) => {
152
+ const sortedOptions = options ? (0, import_primordials.ObjectKeys)(options).sort().map((k) => {
95
153
  const value = options[k];
96
- const normalized = Array.isArray(value) ? [...value].sort() : value;
97
- return `${k}:${JSON.stringify(normalized)}`;
154
+ const normalized = (0, import_primordials.ArrayIsArray)(value) ? [...value].sort() : value;
155
+ return `${k}:${(0, import_primordials.JSONStringify)(normalized)}`;
98
156
  }).join(",") : "";
99
157
  const key = `${sortedPatterns.join("|")}:${sortedOptions}`;
100
158
  const existing = matcherCache.get(key);
@@ -109,26 +167,63 @@ function getGlobMatcher(glob2, options) {
109
167
  matcherCache.delete(oldest);
110
168
  }
111
169
  }
112
- const positivePatterns = patterns.filter((p) => !p.startsWith("!"));
113
- const negativePatterns = patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1));
114
- const matchOptions = {
115
- dot: true,
116
- nocase: true,
117
- ...options,
118
- ...negativePatterns.length > 0 ? { ignore: negativePatterns } : {}
119
- };
120
- const picomatch = /* @__PURE__ */ getPicomatch();
121
- const matcher = picomatch(
122
- positivePatterns.length > 0 ? positivePatterns : patterns,
123
- matchOptions
124
- );
170
+ let matcher;
171
+ if (patterns.length === 1 && !(0, import_primordials.StringPrototypeStartsWith)(patterns[0], "!") && options !== void 0 && options.nocase === false && options.dot === false && (options.ignore === void 0 || options.ignore.length === 0)) {
172
+ const matchesGlob = /* @__PURE__ */ getMatchesGlob();
173
+ if (matchesGlob !== void 0) {
174
+ const pattern = patterns[0];
175
+ matcher = (p) => matchesGlob(p, pattern);
176
+ }
177
+ }
178
+ if (matcher === void 0) {
179
+ const positivePatterns = patterns.filter(
180
+ (p) => !(0, import_primordials.StringPrototypeStartsWith)(p, "!")
181
+ );
182
+ const negativePatterns = patterns.filter((p) => (0, import_primordials.StringPrototypeStartsWith)(p, "!")).map((p) => p.slice(1));
183
+ const matchOptions = {
184
+ dot: true,
185
+ nocase: true,
186
+ ...options,
187
+ ...negativePatterns.length > 0 ? { ignore: negativePatterns } : {}
188
+ };
189
+ const picomatch = /* @__PURE__ */ getPicomatch();
190
+ matcher = picomatch(
191
+ positivePatterns.length > 0 ? positivePatterns : patterns,
192
+ matchOptions
193
+ );
194
+ }
125
195
  matcherCache.set(key, matcher);
126
196
  return matcher;
127
197
  }
198
+ function canUseNodeFsGlob(options) {
199
+ if (!options) {
200
+ return true;
201
+ }
202
+ for (const key of (0, import_primordials.ObjectKeys)(options)) {
203
+ if (key !== "cwd" && key !== "ignore") {
204
+ return false;
205
+ }
206
+ }
207
+ return true;
208
+ }
128
209
  // @__NO_SIDE_EFFECTS__
129
- function glob(patterns, options) {
210
+ async function glob(patterns, options) {
211
+ const normalizedIgnore = normalizeIgnorePatterns(options?.ignore);
212
+ if (canUseNodeFsGlob(options)) {
213
+ const out2 = await (0, import_promises.fromAsync)(
214
+ (/* @__PURE__ */ getFsPromises()).glob(patterns, {
215
+ ...options?.cwd ? { cwd: options.cwd } : {},
216
+ ...normalizedIgnore ? { exclude: normalizedIgnore } : {}
217
+ })
218
+ );
219
+ return normalizeGlobResults(out2);
220
+ }
130
221
  const fastGlob = /* @__PURE__ */ getFastGlob();
131
- return fastGlob.glob(patterns, options);
222
+ const out = await fastGlob.glob(patterns, {
223
+ ...options,
224
+ ...normalizedIgnore ? { ignore: normalizedIgnore } : {}
225
+ });
226
+ return normalizeGlobResults(out);
132
227
  }
133
228
  // @__NO_SIDE_EFFECTS__
134
229
  function globStreamLicenses(dirname, options) {
@@ -138,10 +233,8 @@ function globStreamLicenses(dirname, options) {
138
233
  recursive,
139
234
  ...globOptions
140
235
  } = { __proto__: null, ...options };
141
- const ignore = [
142
- ...Array.isArray(ignoreOpt) ? ignoreOpt : defaultIgnore,
143
- "**/*.{cjs,cts,js,json,mjs,mts,ts}"
144
- ];
236
+ const baseIgnore = (0, import_primordials.ArrayIsArray)(ignoreOpt) ? normalizeIgnorePatterns(ignoreOpt) : defaultIgnore;
237
+ const ignore = [...baseIgnore, "**/*.{cjs,cts,js,json,mjs,mts,ts}"];
145
238
  if (ignoreOriginals) {
146
239
  ignore.push(import_globs.LICENSE_ORIGINAL_GLOB_RECURSIVE);
147
240
  }
@@ -160,13 +253,29 @@ function globStreamLicenses(dirname, options) {
160
253
  }
161
254
  // @__NO_SIDE_EFFECTS__
162
255
  function globSync(patterns, options) {
256
+ const normalizedIgnore = normalizeIgnorePatterns(options?.ignore);
257
+ if (canUseNodeFsGlob(options)) {
258
+ return normalizeGlobResults([
259
+ ...(/* @__PURE__ */ getFs()).globSync(patterns, {
260
+ ...options?.cwd ? { cwd: options.cwd } : {},
261
+ ...normalizedIgnore ? { exclude: normalizedIgnore } : {}
262
+ })
263
+ ]);
264
+ }
163
265
  const fastGlob = /* @__PURE__ */ getFastGlob();
164
- return fastGlob.globSync(patterns, options);
266
+ return normalizeGlobResults(
267
+ fastGlob.globSync(patterns, {
268
+ ...options,
269
+ ...normalizedIgnore ? { ignore: normalizedIgnore } : {}
270
+ })
271
+ );
165
272
  }
166
273
  // Annotate the CommonJS export names for ESM import in node:
167
274
  0 && (module.exports = {
275
+ canUseNodeFsGlob,
168
276
  defaultIgnore,
169
277
  getGlobMatcher,
278
+ getMatchesGlob,
170
279
  glob,
171
280
  globStreamLicenses,
172
281
  globSync
@@ -905,9 +905,10 @@ export declare function parseChecksums(text: string): Checksums;
905
905
  *
906
906
  * @example
907
907
  * ```ts
908
- * const delay = parseRetryAfterHeader(response.headers['retry-after'])
909
- * if (delay !== undefined) {
910
- * await new Promise(resolve => setTimeout(resolve, delay))
908
+ * import { setTimeout as delay } from 'node:timers/promises'
909
+ * const ms = parseRetryAfterHeader(response.headers['retry-after'])
910
+ * if (ms !== undefined) {
911
+ * await delay(ms)
911
912
  * }
912
913
  * ```
913
914
  */
@@ -33,8 +33,10 @@ __export(http_request_exports, {
33
33
  sanitizeHeaders: () => sanitizeHeaders
34
34
  });
35
35
  module.exports = __toCommonJS(http_request_exports);
36
+ var import_promises = require("node:timers/promises");
36
37
  var import_socket = require("./constants/socket");
37
38
  var import_fs = require("./fs");
39
+ var import_primordials = require("./primordials");
38
40
  class HttpResponseError extends Error {
39
41
  response;
40
42
  constructor(response, message) {
@@ -104,19 +106,24 @@ async function httpDownloadAttempt(url, destPath, options) {
104
106
  }
105
107
  const res = response.rawResponse;
106
108
  if (!res) {
107
- throw new Error("Stream response missing rawResponse");
109
+ throw new import_primordials.ErrorCtor("Stream response missing rawResponse");
108
110
  }
109
111
  const { createWriteStream } = /* @__PURE__ */ getFs();
110
- const totalSize = Number.parseInt(
112
+ const totalSize = (0, import_primordials.NumberParseInt)(
111
113
  response.headers["content-length"] || "0",
112
114
  10
113
115
  );
114
- return await new Promise((resolve, reject) => {
116
+ return await new import_primordials.PromiseCtor((resolve, reject) => {
115
117
  let downloadedSize = 0;
116
118
  const fileStream = createWriteStream(destPath);
117
119
  const cleanupPartial = () => {
118
- (/* @__PURE__ */ getFs()).promises.unlink(destPath).catch(() => {
119
- });
120
+ ;
121
+ (async () => {
122
+ try {
123
+ await (/* @__PURE__ */ getFs()).promises.unlink(destPath);
124
+ } catch {
125
+ }
126
+ })();
120
127
  };
121
128
  fileStream.on("error", (error) => {
122
129
  fileStream.destroy();
@@ -164,7 +171,7 @@ async function httpRequestAttempt(url, options) {
164
171
  stream = false,
165
172
  timeout = 3e4
166
173
  } = { __proto__: null, ...options };
167
- const startTime = Date.now();
174
+ const startTime = (0, import_primordials.DateNow)();
168
175
  const streamHeaders = body && typeof body === "object" && "getHeaders" in body && typeof body.getHeaders === "function" ? body.getHeaders() : void 0;
169
176
  const mergedHeaders = {
170
177
  "User-Agent": import_socket.SOCKET_LIB_USER_AGENT,
@@ -172,7 +179,7 @@ async function httpRequestAttempt(url, options) {
172
179
  ...headers
173
180
  };
174
181
  hooks?.onRequest?.({ method, url, headers: mergedHeaders, timeout });
175
- return await new Promise((resolve, reject) => {
182
+ return await new import_primordials.PromiseCtor((resolve, reject) => {
176
183
  let settled = false;
177
184
  const resolveOnce = (response) => {
178
185
  if (settled) {
@@ -193,7 +200,7 @@ async function httpRequestAttempt(url, options) {
193
200
  emitResponse({ error: err });
194
201
  reject(err);
195
202
  };
196
- const parsedUrl = new URL(url);
203
+ const parsedUrl = new import_primordials.URLCtor(url);
197
204
  const isHttps = parsedUrl.protocol === "https:";
198
205
  const httpModule = isHttps ? /* @__PURE__ */ getHttps() : /* @__PURE__ */ getHttp();
199
206
  const requestOptions = {
@@ -210,7 +217,7 @@ async function httpRequestAttempt(url, options) {
210
217
  const emitResponse = (info) => {
211
218
  try {
212
219
  hooks?.onResponse?.({
213
- duration: Date.now() - startTime,
220
+ duration: (0, import_primordials.DateNow)() - startTime,
214
221
  method,
215
222
  url,
216
223
  ...info
@@ -429,7 +436,7 @@ async function fetchChecksums(url, options) {
429
436
  };
430
437
  const response = await httpRequest(url, { ca, headers, timeout });
431
438
  if (!response.ok) {
432
- throw new Error(
439
+ throw new import_primordials.ErrorCtor(
433
440
  `Failed to fetch checksums from ${url}: ${response.status} ${response.statusText}`
434
441
  );
435
442
  }
@@ -455,7 +462,7 @@ async function httpDownload(url, destPath, options) {
455
462
  } else if (logger) {
456
463
  let lastPercent = 0;
457
464
  progressCallback = (downloaded, total) => {
458
- const percent = total === 0 ? 0 : Math.floor(downloaded / total * 100);
465
+ const percent = total === 0 ? 0 : (0, import_primordials.MathFloor)(downloaded / total * 100);
459
466
  if (percent >= lastPercent + progressInterval) {
460
467
  logger.log(
461
468
  ` Progress: ${percent}% (${(downloaded / 1024 / 1024).toFixed(1)} MB / ${(total / 1024 / 1024).toFixed(1)} MB)`
@@ -487,11 +494,11 @@ async function httpDownload(url, destPath, options) {
487
494
  const computedHash = crypto.createHash("sha256").update(fileContent).digest("hex");
488
495
  const expectedHash = sha256.toLowerCase();
489
496
  if (computedHash.length !== expectedHash.length || !crypto.timingSafeEqual(
490
- Buffer.from(computedHash),
497
+ (0, import_primordials.BufferFrom)(computedHash),
491
498
  Buffer.from(expectedHash)
492
499
  )) {
493
500
  await (0, import_fs.safeDelete)(tempPath);
494
- throw new Error(
501
+ throw new import_primordials.ErrorCtor(
495
502
  `Checksum verification failed for ${url}
496
503
  Expected: ${expectedHash}
497
504
  Computed: ${computedHash}`
@@ -512,10 +519,10 @@ Computed: ${computedHash}`
512
519
  break;
513
520
  }
514
521
  const delayMs = retryDelay * 2 ** attempt;
515
- await new Promise((resolve) => setTimeout(resolve, delayMs));
522
+ await (0, import_promises.setTimeout)(delayMs);
516
523
  }
517
524
  }
518
- throw lastError || new Error("Download failed after retries");
525
+ throw lastError || new import_primordials.ErrorCtor("Download failed after retries");
519
526
  }
520
527
  async function httpJson(url, options) {
521
528
  const {
@@ -547,7 +554,7 @@ async function httpJson(url, options) {
547
554
  try {
548
555
  return response.json();
549
556
  } catch (e) {
550
- throw new Error("Failed to parse JSON response", { cause: e });
557
+ throw new import_primordials.ErrorCtor("Failed to parse JSON response", { cause: e });
551
558
  }
552
559
  }
553
560
  async function httpRequest(url, options) {
@@ -569,7 +576,7 @@ async function httpRequest(url, options) {
569
576
  } = { __proto__: null, ...options };
570
577
  const isStreamBody = body !== void 0 && typeof body === "object" && typeof body.pipe === "function";
571
578
  if (isStreamBody && retries > 0) {
572
- throw new Error(
579
+ throw new import_primordials.ErrorCtor(
573
580
  "Streaming body (Readable/FormData) cannot be used with retries. Streams are consumed on first attempt and cannot be replayed. Set retries: 0 or buffer the body as a string/Buffer."
574
581
  );
575
582
  }
@@ -606,14 +613,14 @@ async function httpRequest(url, options) {
606
613
  if (retryResult === false) {
607
614
  break;
608
615
  }
609
- const actualDelay = typeof retryResult === "number" && !Number.isNaN(retryResult) ? Math.max(0, retryResult) : delayMs;
610
- await new Promise((resolve) => setTimeout(resolve, actualDelay));
616
+ const actualDelay = typeof retryResult === "number" && !(0, import_primordials.NumberIsNaN)(retryResult) ? (0, import_primordials.MathMax)(0, retryResult) : delayMs;
617
+ await (0, import_promises.setTimeout)(actualDelay);
611
618
  } else {
612
- await new Promise((resolve) => setTimeout(resolve, delayMs));
619
+ await (0, import_promises.setTimeout)(delayMs);
613
620
  }
614
621
  }
615
622
  }
616
- throw lastError || new Error("Request failed after retries");
623
+ throw lastError || new import_primordials.ErrorCtor("Request failed after retries");
617
624
  }
618
625
  async function httpText(url, options) {
619
626
  const {
@@ -649,9 +656,9 @@ const CHECKSUM_GNU_RE = /^([a-fA-F0-9]{64})\s+(.+)$/;
649
656
  const RETRY_AFTER_INT_RE = /^\d+$/;
650
657
  function parseChecksums(text) {
651
658
  const checksums = { __proto__: null };
652
- for (const line of text.split("\n")) {
659
+ for (const line of (0, import_primordials.StringPrototypeSplit)(text, "\n")) {
653
660
  const trimmed = line.trim();
654
- if (!trimmed || trimmed.startsWith("#")) {
661
+ if (!trimmed || (0, import_primordials.StringPrototypeStartsWith)(trimmed, "#")) {
655
662
  continue;
656
663
  }
657
664
  const bsdMatch = CHECKSUM_BSD_RE.exec(trimmed);
@@ -670,7 +677,7 @@ function parseRetryAfterHeader(value) {
670
677
  if (!value) {
671
678
  return void 0;
672
679
  }
673
- const raw = Array.isArray(value) ? value[0] : value;
680
+ const raw = (0, import_primordials.ArrayIsArray)(value) ? value[0] : value;
674
681
  if (!raw) {
675
682
  return void 0;
676
683
  }
@@ -679,9 +686,9 @@ function parseRetryAfterHeader(value) {
679
686
  const seconds = Number(trimmed);
680
687
  return seconds * 1e3;
681
688
  }
682
- const date = new Date(raw);
683
- if (!Number.isNaN(date.getTime())) {
684
- const delayMs = date.getTime() - Date.now();
689
+ const date = new import_primordials.DateCtor(raw);
690
+ if (!(0, import_primordials.NumberIsNaN)(date.getTime())) {
691
+ const delayMs = date.getTime() - (0, import_primordials.DateNow)();
685
692
  if (delayMs > 0) {
686
693
  return delayMs;
687
694
  }
@@ -693,7 +700,7 @@ async function readIncomingResponse(msg) {
693
700
  for await (const chunk of msg) {
694
701
  chunks.push(chunk);
695
702
  }
696
- const body = Buffer.concat(chunks);
703
+ const body = (0, import_primordials.BufferConcat)(chunks);
697
704
  const status = msg.statusCode ?? 0;
698
705
  const statusText = msg.statusMessage ?? "";
699
706
  return {
@@ -703,7 +710,7 @@ async function readIncomingResponse(msg) {
703
710
  ),
704
711
  body,
705
712
  headers: msg.headers,
706
- json: () => JSON.parse(body.toString("utf8")),
713
+ json: () => (0, import_primordials.JSONParse)(body.toString("utf8")),
707
714
  ok: status >= 200 && status < 300,
708
715
  rawResponse: msg,
709
716
  status,
@@ -715,7 +722,7 @@ function sanitizeHeaders(headers) {
715
722
  if (!headers) {
716
723
  return {};
717
724
  }
718
- const sensitiveHeaders = /* @__PURE__ */ new Set([
725
+ const sensitiveHeaders = new import_primordials.SetCtor([
719
726
  "authorization",
720
727
  "cookie",
721
728
  "proxy-authorization",
@@ -726,11 +733,11 @@ function sanitizeHeaders(headers) {
726
733
  const result = {
727
734
  __proto__: null
728
735
  };
729
- for (const key of Object.keys(headers)) {
736
+ for (const key of (0, import_primordials.ObjectKeys)(headers)) {
730
737
  const value = headers[key];
731
738
  if (sensitiveHeaders.has(key.toLowerCase())) {
732
739
  result[key] = "[REDACTED]";
733
- } else if (Array.isArray(value)) {
740
+ } else if ((0, import_primordials.ArrayIsArray)(value)) {
734
741
  result[key] = value.join(", ");
735
742
  } else if (value !== void 0 && value !== null) {
736
743
  result[key] = String(value);
package/dist/ipc-cli.js CHANGED
@@ -23,6 +23,7 @@ __export(ipc_cli_exports, {
23
23
  getIpc: () => getIpc
24
24
  });
25
25
  module.exports = __toCommonJS(ipc_cli_exports);
26
+ var import_primordials = require("./primordials");
26
27
  let _ipcObject;
27
28
  async function getIpc(key) {
28
29
  if (_ipcObject === void 0) {
@@ -49,7 +50,7 @@ async function getIpc(key) {
49
50
  if (env["SOCKET_CLI_SHADOW_SILENT"]) {
50
51
  _ipcObject.SOCKET_CLI_SHADOW_SILENT = env["SOCKET_CLI_SHADOW_SILENT"] === "true" || env["SOCKET_CLI_SHADOW_SILENT"] === "1";
51
52
  }
52
- Object.freeze(_ipcObject);
53
+ (0, import_primordials.ObjectFreeze)(_ipcObject);
53
54
  }
54
55
  return key ? _ipcObject[key] : _ipcObject;
55
56
  }
package/dist/ipc.js CHANGED
@@ -38,6 +38,7 @@ var import_node_process = __toESM(require("node:process"));
38
38
  var import_typebox = require("./external/@sinclair/typebox");
39
39
  var import_socket = require("./paths/socket");
40
40
  var import_parse = require("./schema/parse");
41
+ var import_primordials = require("./primordials");
41
42
  const IpcStubSchema = import_typebox.Type.Object({
42
43
  /** Process ID that created the stub. */
43
44
  pid: import_typebox.Type.Integer({ minimum: 1 }),
@@ -58,12 +59,12 @@ async function ensureIpcDirectory(filePath) {
58
59
  }
59
60
  const stats = await fs.promises.lstat(dir);
60
61
  if (!stats.isDirectory()) {
61
- throw new Error(`IPC path is not a directory: ${dir}`);
62
+ throw new import_primordials.ErrorCtor(`IPC path is not a directory: ${dir}`);
62
63
  }
63
64
  const getuid = import_node_process.default.getuid;
64
65
  const ownUid = typeof getuid === "function" ? getuid.call(import_node_process.default) : -1;
65
66
  if (ownUid !== -1 && stats.uid !== ownUid) {
66
- throw new Error(
67
+ throw new import_primordials.ErrorCtor(
67
68
  `IPC directory ${dir} is owned by another user (uid ${stats.uid}); refusing to use it.`
68
69
  );
69
70
  }
@@ -98,7 +99,7 @@ async function writeIpcStub(appName, data) {
98
99
  const ipcData = {
99
100
  data,
100
101
  pid: import_node_process.default.pid,
101
- timestamp: Date.now()
102
+ timestamp: (0, import_primordials.DateNow)()
102
103
  };
103
104
  const validated = (0, import_parse.parseSchema)(IpcStubSchema, ipcData);
104
105
  const fs = /* @__PURE__ */ getFs();
@@ -116,7 +117,7 @@ async function writeIpcStub(appName, data) {
116
117
  }
117
118
  }
118
119
  try {
119
- await handle.writeFile(JSON.stringify(validated, null, 2), "utf8");
120
+ await handle.writeFile((0, import_primordials.JSONStringify)(validated, null, 2), "utf8");
120
121
  } finally {
121
122
  await handle.close();
122
123
  }
package/dist/json/edit.js CHANGED
@@ -36,6 +36,7 @@ module.exports = __toCommonJS(edit_exports);
36
36
  var import_node_process = __toESM(require("node:process"));
37
37
  var import_promises = require("node:timers/promises");
38
38
  var import_errors = require("../errors");
39
+ var import_primordials = require("../primordials");
39
40
  var import_format = require("./format");
40
41
  const identSymbol = import_format.INDENT_SYMBOL;
41
42
  const newlineSymbol = import_format.NEWLINE_SYMBOL;
@@ -68,7 +69,7 @@ async function readFile(filepath) {
68
69
  await (0, import_promises.setTimeout)(delay);
69
70
  }
70
71
  }
71
- throw new Error("Unreachable code");
72
+ throw new import_primordials.ErrorCtor("Unreachable code");
72
73
  }
73
74
  async function retryWrite(filepath, content, retries = 3, baseDelay = 10) {
74
75
  const fs = /* @__PURE__ */ getFs();
@@ -190,7 +191,7 @@ function getEditableJsonClass() {
190
191
  }
191
192
  async save(options) {
192
193
  if (!this._canSave || this.content === void 0) {
193
- throw new Error("No file path to save to");
194
+ throw new import_primordials.ErrorCtor("No file path to save to");
194
195
  }
195
196
  if (!(0, import_format.shouldSave)(
196
197
  this.content,
@@ -215,7 +216,7 @@ function getEditableJsonClass() {
215
216
  }
216
217
  saveSync(options) {
217
218
  if (!this._canSave || this.content === void 0) {
218
- throw new Error("No file path to save to");
219
+ throw new import_primordials.ErrorCtor("No file path to save to");
219
220
  }
220
221
  if (!(0, import_format.shouldSave)(
221
222
  this.content,
@@ -33,6 +33,7 @@ __export(format_exports, {
33
33
  stripFormattingSymbols: () => stripFormattingSymbols
34
34
  });
35
35
  module.exports = __toCommonJS(format_exports);
36
+ var import_primordials = require("../primordials");
36
37
  const INDENT_SYMBOL = Symbol.for("indent");
37
38
  const NEWLINE_SYMBOL = Symbol.for("newline");
38
39
  function detectIndent(json) {
@@ -85,7 +86,7 @@ function shouldSave(currentContent, originalContent, originalFileContent, option
85
86
  }
86
87
  function sortKeys(obj) {
87
88
  const sorted = { __proto__: null };
88
- const keys = Object.keys(obj).sort();
89
+ const keys = (0, import_primordials.ObjectKeys)(obj).sort();
89
90
  for (const key of keys) {
90
91
  sorted[key] = obj[key];
91
92
  }
@@ -95,7 +96,7 @@ function stringifyWithFormatting(content, formatting) {
95
96
  const { indent, newline } = formatting;
96
97
  const format = indent === void 0 || indent === null ? " " : indent;
97
98
  const eol = newline === void 0 || newline === null ? "\n" : newline;
98
- return `${JSON.stringify(content, void 0, format)}
99
+ return `${(0, import_primordials.JSONStringify)(content, void 0, format)}
99
100
  `.replace(/\n/g, eol);
100
101
  }
101
102
  function stripFormattingSymbols(content) {
@@ -27,6 +27,7 @@ __export(parse_exports, {
27
27
  module.exports = __toCommonJS(parse_exports);
28
28
  var import_validate = require("../schema/validate");
29
29
  var import_strings = require("../strings");
30
+ var import_primordials = require("../primordials");
30
31
  const JSONParse = JSON.parse;
31
32
  // @__NO_SIDE_EFFECTS__
32
33
  function isBuffer(x) {
@@ -71,10 +72,10 @@ function jsonParse(content, options) {
71
72
  }
72
73
  return void 0;
73
74
  }
74
- const DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
75
+ const DANGEROUS_KEYS = new import_primordials.SetCtor(["__proto__", "constructor", "prototype"]);
75
76
  function prototypePollutionReviver(key, value) {
76
77
  if (DANGEROUS_KEYS.has(key)) {
77
- throw new Error(
78
+ throw new import_primordials.ErrorCtor(
78
79
  "JSON contains potentially malicious prototype pollution keys"
79
80
  );
80
81
  }
@@ -84,9 +85,9 @@ const DEFAULT_MAX_SIZE = 10 * 1024 * 1024;
84
85
  // @__NO_SIDE_EFFECTS__
85
86
  function safeJsonParse(jsonString, schema, options = {}) {
86
87
  const { allowPrototype = false, maxSize = DEFAULT_MAX_SIZE } = options;
87
- const byteLength = Buffer.byteLength(jsonString, "utf8");
88
+ const byteLength = (0, import_primordials.BufferByteLength)(jsonString, "utf8");
88
89
  if (byteLength > maxSize) {
89
- throw new Error(
90
+ throw new import_primordials.ErrorCtor(
90
91
  `JSON string exceeds maximum size limit${maxSize !== DEFAULT_MAX_SIZE ? ` of ${maxSize} bytes` : ""}`
91
92
  );
92
93
  }
@@ -94,13 +95,13 @@ function safeJsonParse(jsonString, schema, options = {}) {
94
95
  try {
95
96
  parsed = allowPrototype ? JSONParse(jsonString) : JSONParse(jsonString, prototypePollutionReviver);
96
97
  } catch (e) {
97
- throw new Error(`Failed to parse JSON: ${e}`);
98
+ throw new import_primordials.ErrorCtor(`Failed to parse JSON: ${e}`);
98
99
  }
99
100
  if (schema) {
100
101
  const result = (0, import_validate.validateSchema)(schema, parsed);
101
102
  if (!result.ok) {
102
103
  const summary = result.errors.map((e) => `${e.path.join(".") || "(root)"}: ${e.message}`).join(", ");
103
- throw new Error(`Validation failed: ${summary}`);
104
+ throw new import_primordials.ErrorCtor(`Validation failed: ${summary}`);
104
105
  }
105
106
  return result.value;
106
107
  }
package/dist/links.js CHANGED
@@ -38,6 +38,7 @@ var import_yoctocolors_cjs = __toESM(require("./external/yoctocolors-cjs"));
38
38
  var import_context = require("./themes/context");
39
39
  var import_themes = require("./themes/themes");
40
40
  var import_utils = require("./themes/utils");
41
+ var import_primordials = require("./primordials");
41
42
  function link(text, url, options) {
42
43
  const opts = { __proto__: null, fallback: false, ...options };
43
44
  const theme = typeof opts.theme === "string" ? import_themes.THEMES[opts.theme] : opts.theme ?? (0, import_context.getTheme)();
@@ -47,7 +48,7 @@ function link(text, url, options) {
47
48
  if (typeof linkColor === "string" && linkColor !== "inherit") {
48
49
  const colorMethod = colors[linkColor];
49
50
  colored = colorMethod ? colorMethod(text) : colors.cyan(text);
50
- } else if (Array.isArray(linkColor)) {
51
+ } else if ((0, import_primordials.ArrayIsArray)(linkColor)) {
51
52
  colored = colors.cyan(text);
52
53
  } else {
53
54
  colored = colors.cyan(text);