@socketsecurity/lib 5.26.0 → 5.27.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 (183) hide show
  1. package/CHANGELOG.md +371 -1185
  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} +26 -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 +71 -71
  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 +50 -68
  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/node/async-hooks.d.ts +6 -0
  84. package/dist/node/async-hooks.js +34 -0
  85. package/dist/node/child-process.d.ts +11 -0
  86. package/dist/node/child-process.js +34 -0
  87. package/dist/node/crypto.d.ts +6 -0
  88. package/dist/node/crypto.js +34 -0
  89. package/dist/node/events.d.ts +6 -0
  90. package/dist/node/events.js +34 -0
  91. package/dist/node/fs-promises.d.ts +6 -0
  92. package/dist/node/fs-promises.js +34 -0
  93. package/dist/node/fs.d.ts +14 -0
  94. package/dist/node/fs.js +34 -0
  95. package/dist/node/http.d.ts +6 -0
  96. package/dist/node/http.js +34 -0
  97. package/dist/node/https.d.ts +6 -0
  98. package/dist/node/https.js +34 -0
  99. package/dist/node/os.d.ts +6 -0
  100. package/dist/node/os.js +34 -0
  101. package/dist/node/path.d.ts +6 -0
  102. package/dist/node/path.js +34 -0
  103. package/dist/node/timers-promises.d.ts +6 -0
  104. package/dist/node/timers-promises.js +34 -0
  105. package/dist/node/url.d.ts +6 -0
  106. package/dist/node/url.js +34 -0
  107. package/dist/node/util.d.ts +6 -0
  108. package/dist/node/util.js +34 -0
  109. package/dist/objects.js +2 -2
  110. package/dist/packages/edit.js +8 -7
  111. package/dist/packages/exports.js +17 -16
  112. package/dist/packages/isolation.js +20 -13
  113. package/dist/packages/licenses.js +6 -3
  114. package/dist/packages/manifest.js +2 -1
  115. package/dist/packages/normalize.js +8 -4
  116. package/dist/packages/operations.js +5 -4
  117. package/dist/packages/provenance.js +7 -6
  118. package/dist/packages/specs.js +2 -1
  119. package/dist/packages/validation.js +2 -1
  120. package/dist/paths/normalize.js +32 -40
  121. package/dist/paths/packages.js +2 -1
  122. package/dist/paths/rewire.js +3 -2
  123. package/dist/performance.js +19 -18
  124. package/dist/primordials.d.ts +85 -2
  125. package/dist/primordials.js +311 -23
  126. package/dist/process-lock.js +14 -13
  127. package/dist/promise-queue.js +17 -9
  128. package/dist/promises.d.ts +29 -6
  129. package/dist/promises.js +19 -15
  130. package/dist/regexps.js +9 -8
  131. package/dist/releases/github-api.d.ts +56 -0
  132. package/dist/releases/github-api.js +275 -0
  133. package/dist/releases/github-archives.d.ts +60 -0
  134. package/dist/releases/github-archives.js +136 -0
  135. package/dist/releases/github-assets.d.ts +21 -0
  136. package/dist/releases/github-assets.js +52 -0
  137. package/dist/releases/github-auth.d.ts +16 -0
  138. package/dist/releases/github-auth.js +51 -0
  139. package/dist/releases/github-downloads.d.ts +42 -0
  140. package/dist/releases/github-downloads.js +155 -0
  141. package/dist/releases/github-types.d.ts +66 -0
  142. package/dist/{effects/types.js → releases/github-types.js} +2 -2
  143. package/dist/releases/socket-btm.d.ts +1 -1
  144. package/dist/releases/socket-btm.js +17 -17
  145. package/dist/schema/parse.js +2 -1
  146. package/dist/schema/validate.js +6 -5
  147. package/dist/sea/util.d.ts +43 -0
  148. package/dist/{sea.js → sea/util.js} +7 -7
  149. package/dist/shadow.js +2 -1
  150. package/dist/signal-exit.js +2 -2
  151. package/dist/smol/primordial.d.ts +80 -0
  152. package/dist/smol/primordial.js +46 -0
  153. package/dist/smol/util.d.ts +87 -0
  154. package/dist/smol/util.js +59 -0
  155. package/dist/smol/versions.d.ts +46 -0
  156. package/dist/smol/versions.js +46 -0
  157. package/dist/spawn.js +58 -63
  158. package/dist/spinner.d.ts +13 -6
  159. package/dist/spinner.js +75 -57
  160. package/dist/ssri.js +8 -7
  161. package/dist/stdio/footer.js +13 -12
  162. package/dist/stdio/header.js +5 -4
  163. package/dist/stdio/progress.js +13 -12
  164. package/dist/strings.js +19 -18
  165. package/dist/suppress-warnings.js +2 -2
  166. package/dist/tables.js +16 -13
  167. package/dist/temporary-executor.js +2 -1
  168. package/dist/themes/context.js +2 -1
  169. package/dist/themes/types.d.ts +1 -1
  170. package/dist/themes/utils.d.ts +8 -3
  171. package/dist/themes/utils.js +29 -5
  172. package/dist/url.js +4 -3
  173. package/dist/versions.js +27 -22
  174. package/package.json +120 -26
  175. package/dist/effects/text-shimmer.d.ts +0 -58
  176. package/dist/effects/text-shimmer.js +0 -192
  177. package/dist/effects/types.d.ts +0 -47
  178. package/dist/effects/ultra.d.ts +0 -22
  179. package/dist/releases/github.d.ts +0 -234
  180. package/dist/releases/github.js +0 -417
  181. package/dist/sea.d.ts +0 -30
  182. package/dist/themes/index.d.ts +0 -49
  183. package/dist/themes/index.js +0 -60
@@ -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);
package/dist/logger.js CHANGED
@@ -94,7 +94,7 @@ const LOG_SYMBOLS = /* @__PURE__ */ (() => {
94
94
  }
95
95
  updateSymbols();
96
96
  };
97
- for (const trapName of Reflect.ownKeys(Reflect)) {
97
+ for (const trapName of (0, import_primordials.ReflectOwnKeys)(Reflect)) {
98
98
  const fn = Reflect[trapName];
99
99
  if (typeof fn === "function") {
100
100
  ;
@@ -107,7 +107,7 @@ const LOG_SYMBOLS = /* @__PURE__ */ (() => {
107
107
  (0, import_context.onThemeChange)(() => {
108
108
  reset();
109
109
  });
110
- return new Proxy(target, handler);
110
+ return new import_primordials.ProxyCtor(target, handler);
111
111
  })();
112
112
  const boundConsoleEntries = [
113
113
  // Add bound properties from console[kBindProperties](ignoreErrors, colorMode, groupIndentation).
@@ -146,8 +146,8 @@ const consolePropAttributes = {
146
146
  configurable: true
147
147
  };
148
148
  const maxIndentation = 1e3;
149
- const privateConsole = /* @__PURE__ */ new WeakMap();
150
- const privateConstructorArgs = /* @__PURE__ */ new WeakMap();
149
+ const privateConsole = new import_primordials.WeakMapCtor();
150
+ const privateConstructorArgs = new import_primordials.WeakMapCtor();
151
151
  const incLogCallCountSymbol = Symbol.for("logger.logCallCount++");
152
152
  const lastWasBlankSymbol = Symbol.for("logger.lastWasBlank");
153
153
  class Logger {
@@ -220,11 +220,14 @@ class Logger {
220
220
  */
221
221
  #apply(methodName, args, stream) {
222
222
  const con = this.#getConsole();
223
- const text = args.at(0);
223
+ const text = (0, import_primordials.ArrayPrototypeAt)(args, 0);
224
224
  const hasText = typeof text === "string";
225
225
  const targetStream = stream || (methodName === "log" ? "stdout" : "stderr");
226
226
  const indent = this.#getIndent(targetStream);
227
- const logArgs = hasText ? [(0, import_strings.applyLinePrefix)(text, { prefix: indent }), ...args.slice(1)] : args;
227
+ const logArgs = hasText ? [
228
+ (0, import_strings.applyLinePrefix)(text, { prefix: indent }),
229
+ ...(0, import_primordials.ArrayPrototypeSlice)(args, 1)
230
+ ] : args;
228
231
  (0, import_primordials.ReflectApply)(
229
232
  con[methodName],
230
233
  con,
@@ -350,7 +353,11 @@ class Logger {
350
353
  * @private
351
354
  */
352
355
  #stripSymbols(text) {
353
- return text.replace(/^(?:[✖✗×⚠‼✔✓√ℹ→∴↻]|:.)[\uFE0F\s]*/u, "");
356
+ return (0, import_primordials.StringPrototypeReplace)(
357
+ text,
358
+ /^(?:[✖✗×⚠‼✔✓√ℹ→∴↻]|:.)[\uFE0F\s]*/u,
359
+ ""
360
+ );
354
361
  }
355
362
  /**
356
363
  * Apply a method with a symbol prefix.
@@ -358,11 +365,11 @@ class Logger {
358
365
  */
359
366
  #symbolApply(symbolType, args) {
360
367
  const con = this.#getConsole();
361
- let text = args.at(0);
368
+ let text = (0, import_primordials.ArrayPrototypeAt)(args, 0);
362
369
  let extras;
363
370
  if (typeof text === "string") {
364
371
  text = this.#stripSymbols(text);
365
- extras = args.slice(1);
372
+ extras = (0, import_primordials.ArrayPrototypeSlice)(args, 1);
366
373
  } else {
367
374
  extras = args;
368
375
  text = "";
@@ -587,7 +594,7 @@ class Logger {
587
594
  */
588
595
  clearVisible() {
589
596
  if (this.#boundStream) {
590
- throw new Error(
597
+ throw new import_primordials.ErrorCtor(
591
598
  "clearVisible() is only available on the main logger instance, not on stream-bound instances"
592
599
  );
593
600
  }
@@ -932,7 +939,7 @@ class Logger {
932
939
  * ```
933
940
  */
934
941
  indent(spaces = 2) {
935
- const spacesToAdd = " ".repeat(Math.min(spaces, maxIndentation));
942
+ const spacesToAdd = " ".repeat((0, import_primordials.MathMin)(spaces, maxIndentation));
936
943
  if (this.#boundStream) {
937
944
  const current = this.#getIndent(this.#boundStream);
938
945
  this.#setIndent(this.#boundStream, current + spacesToAdd);
@@ -1423,7 +1430,7 @@ function ensurePrototypeInitialized() {
1423
1430
  }
1424
1431
  ]
1425
1432
  ];
1426
- for (const { 0: key, 1: value } of Object.entries(globalConsole)) {
1433
+ for (const { 0: key, 1: value } of (0, import_primordials.ObjectEntries)(globalConsole)) {
1427
1434
  if (!Logger.prototype[key] && typeof value === "function") {
1428
1435
  const { [key]: func } = {
1429
1436
  [key](...args) {
@@ -1457,11 +1464,11 @@ function ensurePrototypeInitialized() {
1457
1464
  ]);
1458
1465
  }
1459
1466
  }
1460
- Object.defineProperties(Logger.prototype, Object.fromEntries(entries));
1467
+ (0, import_primordials.ObjectDefineProperties)(Logger.prototype, Object.fromEntries(entries));
1461
1468
  }
1462
1469
  function getConsoleSymbols() {
1463
1470
  if (_consoleSymbols === void 0) {
1464
- _consoleSymbols = Object.getOwnPropertySymbols(globalConsole);
1471
+ _consoleSymbols = (0, import_primordials.ObjectGetOwnPropertySymbols)(globalConsole);
1465
1472
  }
1466
1473
  return _consoleSymbols;
1467
1474
  }
@@ -29,9 +29,10 @@ __export(memoization_exports, {
29
29
  });
30
30
  module.exports = __toCommonJS(memoization_exports);
31
31
  var import_debug = require("./debug");
32
+ var import_primordials = require("./primordials");
32
33
  const cacheRegistry = [];
33
34
  function defaultKeyGen(args) {
34
- return JSON.stringify(args, (_key, value) => {
35
+ return (0, import_primordials.JSONStringify)(args, (_key, value) => {
35
36
  if (value === void 0) {
36
37
  return "\0undefined";
37
38
  }
@@ -74,9 +75,9 @@ function memoize(fn, options = {}) {
74
75
  ttl = Number.POSITIVE_INFINITY
75
76
  } = options;
76
77
  if (ttl < 0) {
77
- throw new TypeError("TTL must be non-negative");
78
+ throw new import_primordials.TypeErrorCtor("TTL must be non-negative");
78
79
  }
79
- const cache = /* @__PURE__ */ new Map();
80
+ const cache = new import_primordials.MapCtor();
80
81
  cacheRegistry.push(() => {
81
82
  cache.clear();
82
83
  });
@@ -96,7 +97,7 @@ function memoize(fn, options = {}) {
96
97
  if (ttl === Number.POSITIVE_INFINITY) {
97
98
  return false;
98
99
  }
99
- return Date.now() - entry.timestamp > ttl;
100
+ return (0, import_primordials.DateNow)() - entry.timestamp > ttl;
100
101
  }
101
102
  return function memoized(...args) {
102
103
  const key = keyGen(...args);
@@ -130,7 +131,7 @@ function memoizeAsync(fn, options = {}) {
130
131
  name = fn.name || "anonymous",
131
132
  ttl = Number.POSITIVE_INFINITY
132
133
  } = options;
133
- const cache = /* @__PURE__ */ new Map();
134
+ const cache = new import_primordials.MapCtor();
134
135
  cacheRegistry.push(() => {
135
136
  cache.clear();
136
137
  });
@@ -150,13 +151,13 @@ function memoizeAsync(fn, options = {}) {
150
151
  if (ttl === Number.POSITIVE_INFINITY) {
151
152
  return false;
152
153
  }
153
- return Date.now() - entry.timestamp > ttl;
154
+ return (0, import_primordials.DateNow)() - entry.timestamp > ttl;
154
155
  }
155
156
  function bumpRecency(key, entry) {
156
157
  cache.delete(key);
157
158
  cache.set(key, entry);
158
159
  }
159
- const refreshing = /* @__PURE__ */ new Map();
160
+ const refreshing = new import_primordials.MapCtor();
160
161
  return async function memoized(...args) {
161
162
  const key = keyGen(...args);
162
163
  const cached = cache.get(key);
@@ -176,23 +177,23 @@ function memoizeAsync(fn, options = {}) {
176
177
  cache.delete(key);
177
178
  }
178
179
  (0, import_debug.debugLog)(`[memoizeAsync:${name}] miss`, { key });
179
- const promise = fn(...args).then(
180
- (result) => {
180
+ const promise = (async () => {
181
+ try {
182
+ const result = await fn(...args);
181
183
  refreshing.delete(key);
182
184
  const entry = cache.get(key);
183
185
  if (entry) {
184
- entry.value = Promise.resolve(result);
185
- entry.timestamp = Date.now();
186
+ entry.value = (0, import_primordials.PromiseResolve)(result);
187
+ entry.timestamp = (0, import_primordials.DateNow)();
186
188
  }
187
189
  return result;
188
- },
189
- (error) => {
190
+ } catch (error) {
190
191
  refreshing.delete(key);
191
192
  cache.delete(key);
192
193
  (0, import_debug.debugLog)(`[memoizeAsync:${name}] error`, { key, error });
193
194
  throw error;
194
195
  }
195
- );
196
+ })();
196
197
  refreshing.set(key, promise);
197
198
  evictLRU();
198
199
  cache.set(key, {
@@ -205,7 +206,7 @@ function memoizeAsync(fn, options = {}) {
205
206
  };
206
207
  }
207
208
  function memoizeWeak(fn) {
208
- const cache = /* @__PURE__ */ new WeakMap();
209
+ const cache = new import_primordials.WeakMapCtor();
209
210
  return function memoized(key) {
210
211
  if (cache.has(key)) {
211
212
  (0, import_debug.debugLog)(`[memoizeWeak:${fn.name}] hit`);
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @fileoverview Lazy-loader for `node:async_hooks`. See `node/fs.ts`
3
+ * for the design rationale shared across all `node/*.ts` lazy-loaders.
4
+ */
5
+ import type * as NodeAsyncHooks from 'node:async_hooks';
6
+ export declare function getNodeAsyncHooks(): typeof NodeAsyncHooks;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ /* Socket Lib - Built with esbuild */
3
+ "use strict";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var async_hooks_exports = {};
22
+ __export(async_hooks_exports, {
23
+ getNodeAsyncHooks: () => getNodeAsyncHooks
24
+ });
25
+ module.exports = __toCommonJS(async_hooks_exports);
26
+ let _asyncHooks;
27
+ // @__NO_SIDE_EFFECTS__
28
+ function getNodeAsyncHooks() {
29
+ return _asyncHooks ??= require("node:async_hooks");
30
+ }
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ getNodeAsyncHooks
34
+ });