@socketsecurity/lib 5.11.1 → 5.11.3

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 (60) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/abort.js +1 -3
  3. package/dist/agent.js +12 -1
  4. package/dist/ansi.js +1 -1
  5. package/dist/archives.js +7 -6
  6. package/dist/argv/flags.d.ts +0 -7
  7. package/dist/argv/flags.js +12 -1
  8. package/dist/argv/parse.js +5 -9
  9. package/dist/bin.js +2 -1
  10. package/dist/cache-with-ttl.js +10 -3
  11. package/dist/constants/node.js +14 -3
  12. package/dist/cover/code.js +13 -2
  13. package/dist/cover/type.js +12 -1
  14. package/dist/dlx/binary.js +16 -5
  15. package/dist/dlx/manifest.js +22 -33
  16. package/dist/env/package-manager.js +12 -1
  17. package/dist/env/rewire.js +14 -3
  18. package/dist/external/@npmcli/package-json.js +5 -3
  19. package/dist/external/adm-zip.js +1 -0
  20. package/dist/external/debug.js +18 -10
  21. package/dist/external/external-pack.js +8 -2
  22. package/dist/external/libnpmexec.js +2 -2
  23. package/dist/external/npm-pack.js +380 -367
  24. package/dist/external/p-map.js +240 -0
  25. package/dist/external/pico-pack.js +245 -12
  26. package/dist/external/zod.js +1 -0
  27. package/dist/fs.d.ts +0 -4
  28. package/dist/fs.js +13 -2
  29. package/dist/git.js +12 -1
  30. package/dist/github.js +15 -6
  31. package/dist/http-request.d.ts +29 -0
  32. package/dist/http-request.js +23 -2
  33. package/dist/ipc.js +17 -5
  34. package/dist/json/edit.js +14 -3
  35. package/dist/logger.js +5 -4
  36. package/dist/memoization.js +46 -13
  37. package/dist/packages/isolation.js +9 -1
  38. package/dist/performance.js +13 -2
  39. package/dist/process-lock.js +16 -3
  40. package/dist/promise-queue.d.ts +2 -0
  41. package/dist/promise-queue.js +20 -9
  42. package/dist/promises.js +1 -3
  43. package/dist/releases/github.js +9 -4
  44. package/dist/sea.js +12 -1
  45. package/dist/shadow.js +14 -3
  46. package/dist/spawn.js +5 -4
  47. package/dist/spinner.d.ts +0 -4
  48. package/dist/spinner.js +2 -1
  49. package/dist/stdio/clear.d.ts +0 -21
  50. package/dist/stdio/clear.js +20 -9
  51. package/dist/stdio/mask.js +27 -16
  52. package/dist/stdio/progress.js +3 -2
  53. package/dist/stdio/stderr.d.ts +0 -13
  54. package/dist/stdio/stderr.js +12 -1
  55. package/dist/stdio/stdout.js +17 -6
  56. package/dist/suppress-warnings.d.ts +0 -9
  57. package/dist/suppress-warnings.js +17 -6
  58. package/dist/temporary-executor.js +14 -3
  59. package/dist/validation/json-parser.js +10 -12
  60. package/package.json +8 -6
package/dist/github.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
+ var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
6
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
9
  var __export = (target, all) => {
8
10
  for (var name in all)
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
16
18
  }
17
19
  return to;
18
20
  };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
  var github_exports = {};
21
31
  __export(github_exports, {
@@ -30,6 +40,7 @@ __export(github_exports, {
30
40
  resolveRefToSha: () => resolveRefToSha
31
41
  });
32
42
  module.exports = __toCommonJS(github_exports);
43
+ var import_node_process = __toESM(require("node:process"));
33
44
  var import_cache_with_ttl = require("./cache-with-ttl");
34
45
  var import_github = require("./env/github");
35
46
  var import_socket_cli = require("./env/socket-cli");
@@ -100,7 +111,7 @@ async function resolveRefToSha(owner, repo, ref, options) {
100
111
  ...options
101
112
  };
102
113
  const cacheKey = `${owner}/${repo}@${ref}`;
103
- if (process.env["DISABLE_GITHUB_CACHE"]) {
114
+ if (import_node_process.default.env["DISABLE_GITHUB_CACHE"]) {
104
115
  return await fetchRefSha(owner, repo, ref, opts);
105
116
  }
106
117
  const cache = getGithubCache();
@@ -189,14 +200,12 @@ async function fetchGhsaDetails(ghsaId, options) {
189
200
  async function cacheFetchGhsa(ghsaId, options) {
190
201
  const cache = getGithubCache();
191
202
  const key = `ghsa:${ghsaId}`;
192
- if (process.env["DISABLE_GITHUB_CACHE"]) {
203
+ if (import_node_process.default.env["DISABLE_GITHUB_CACHE"]) {
193
204
  return await fetchGhsaDetails(ghsaId, options);
194
205
  }
195
- const cached = await cache.getOrFetch(key, async () => {
196
- const data = await fetchGhsaDetails(ghsaId, options);
197
- return JSON.stringify(data);
206
+ return await cache.getOrFetch(key, async () => {
207
+ return await fetchGhsaDetails(ghsaId, options);
198
208
  });
199
- return JSON.parse(cached);
200
209
  }
201
210
  // Annotate the CommonJS export names for ESM import in node:
202
211
  0 && (module.exports = {
@@ -25,6 +25,24 @@ export interface HttpRequestOptions {
25
25
  * ```
26
26
  */
27
27
  body?: Buffer | string | undefined;
28
+ /**
29
+ * Custom CA certificates for TLS connections.
30
+ * When provided, these certificates are combined with the default trust
31
+ * store via an HTTPS agent. Useful when SSL_CERT_FILE is set but
32
+ * NODE_EXTRA_CA_CERTS was not available at process startup.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { rootCertificates } from 'node:tls'
37
+ * import { readFileSync } from 'node:fs'
38
+ *
39
+ * const extraCerts = readFileSync('/path/to/cert.pem', 'utf-8')
40
+ * await httpRequest('https://api.example.com', {
41
+ * ca: [...rootCertificates, extraCerts]
42
+ * })
43
+ * ```
44
+ */
45
+ ca?: string[] | undefined;
28
46
  /**
29
47
  * Whether to automatically follow HTTP redirects (3xx status codes).
30
48
  *
@@ -257,6 +275,12 @@ export interface HttpResponse {
257
275
  * Configuration options for file downloads.
258
276
  */
259
277
  export interface HttpDownloadOptions {
278
+ /**
279
+ * Custom CA certificates for TLS connections.
280
+ * When provided, these certificates are used for the download request.
281
+ * See `HttpRequestOptions.ca` for details.
282
+ */
283
+ ca?: string[] | undefined;
260
284
  /**
261
285
  * Whether to automatically follow HTTP redirects (3xx status codes).
262
286
  * This is essential for downloading from services that use CDN redirects,
@@ -501,6 +525,11 @@ export declare function parseChecksums(text: string): Checksums;
501
525
  * Options for fetching checksums from a URL.
502
526
  */
503
527
  export interface FetchChecksumsOptions {
528
+ /**
529
+ * Custom CA certificates for TLS connections.
530
+ * See `HttpRequestOptions.ca` for details.
531
+ */
532
+ ca?: string[] | undefined;
504
533
  /**
505
534
  * HTTP headers to send with the request.
506
535
  */
@@ -82,11 +82,15 @@ function parseChecksums(text) {
82
82
  return checksums;
83
83
  }
84
84
  async function fetchChecksums(url, options) {
85
- const { headers = {}, timeout = 3e4 } = {
85
+ const {
86
+ ca,
87
+ headers = {},
88
+ timeout = 3e4
89
+ } = {
86
90
  __proto__: null,
87
91
  ...options
88
92
  };
89
- const response = await httpRequest(url, { headers, timeout });
93
+ const response = await httpRequest(url, { ca, headers, timeout });
90
94
  if (!response.ok) {
91
95
  throw new Error(
92
96
  `Failed to fetch checksums from ${url}: ${response.status} ${response.statusText}`
@@ -96,6 +100,7 @@ async function fetchChecksums(url, options) {
96
100
  }
97
101
  async function httpDownloadAttempt(url, destPath, options) {
98
102
  const {
103
+ ca,
99
104
  followRedirects = true,
100
105
  headers = {},
101
106
  maxRedirects = 5,
@@ -117,6 +122,9 @@ async function httpDownloadAttempt(url, destPath, options) {
117
122
  port: parsedUrl.port,
118
123
  timeout
119
124
  };
125
+ if (ca && isHttps) {
126
+ requestOptions["ca"] = ca;
127
+ }
120
128
  const { createWriteStream } = /* @__PURE__ */ getFs();
121
129
  let fileStream;
122
130
  let streamClosed = false;
@@ -141,6 +149,7 @@ async function httpDownloadAttempt(url, destPath, options) {
141
149
  const redirectUrl = res.headers.location.startsWith("http") ? res.headers.location : new URL(res.headers.location, url).toString();
142
150
  resolve(
143
151
  httpDownloadAttempt(redirectUrl, destPath, {
152
+ ca,
144
153
  followRedirects,
145
154
  headers,
146
155
  maxRedirects: maxRedirects - 1,
@@ -223,6 +232,7 @@ async function httpDownloadAttempt(url, destPath, options) {
223
232
  async function httpRequestAttempt(url, options) {
224
233
  const {
225
234
  body,
235
+ ca,
226
236
  followRedirects = true,
227
237
  headers = {},
228
238
  maxRedirects = 5,
@@ -244,6 +254,9 @@ async function httpRequestAttempt(url, options) {
244
254
  port: parsedUrl.port,
245
255
  timeout
246
256
  };
257
+ if (ca && isHttps) {
258
+ requestOptions["ca"] = ca;
259
+ }
247
260
  const request = httpModule.request(
248
261
  requestOptions,
249
262
  (res) => {
@@ -260,6 +273,7 @@ async function httpRequestAttempt(url, options) {
260
273
  resolve(
261
274
  httpRequestAttempt(redirectUrl, {
262
275
  body,
276
+ ca,
263
277
  followRedirects,
264
278
  headers,
265
279
  maxRedirects: maxRedirects - 1,
@@ -297,6 +311,9 @@ async function httpRequestAttempt(url, options) {
297
311
  };
298
312
  resolve(response);
299
313
  });
314
+ res.on("error", (error) => {
315
+ reject(error);
316
+ });
300
317
  }
301
318
  );
302
319
  request.on("error", (error) => {
@@ -328,6 +345,7 @@ async function httpRequestAttempt(url, options) {
328
345
  }
329
346
  async function httpDownload(url, destPath, options) {
330
347
  const {
348
+ ca,
331
349
  followRedirects = true,
332
350
  headers = {},
333
351
  logger,
@@ -363,6 +381,7 @@ async function httpDownload(url, destPath, options) {
363
381
  for (let attempt = 0; attempt <= retries; attempt++) {
364
382
  try {
365
383
  const result = await httpDownloadAttempt(url, tempPath, {
384
+ ca,
366
385
  followRedirects,
367
386
  headers,
368
387
  maxRedirects,
@@ -437,6 +456,7 @@ async function httpJson(url, options) {
437
456
  async function httpRequest(url, options) {
438
457
  const {
439
458
  body,
459
+ ca,
440
460
  followRedirects = true,
441
461
  headers = {},
442
462
  maxRedirects = 5,
@@ -450,6 +470,7 @@ async function httpRequest(url, options) {
450
470
  try {
451
471
  return await httpRequestAttempt(url, {
452
472
  body,
473
+ ca,
453
474
  followRedirects,
454
475
  headers,
455
476
  maxRedirects,
package/dist/ipc.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
+ var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
6
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
9
  var __export = (target, all) => {
8
10
  for (var name in all)
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
16
18
  }
17
19
  return to;
18
20
  };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
  var ipc_exports = {};
21
31
  __export(ipc_exports, {
@@ -33,6 +43,7 @@ __export(ipc_exports, {
33
43
  writeIpcStub: () => writeIpcStub
34
44
  });
35
45
  module.exports = __toCommonJS(ipc_exports);
46
+ var import_node_process = __toESM(require("node:process"));
36
47
  var import_fs = require("./fs");
37
48
  var import_socket = require("./paths/socket");
38
49
  var import_zod = require("./zod");
@@ -93,13 +104,13 @@ const IpcStubSchema = import_zod.z.object({
93
104
  });
94
105
  function createIpcChannelId(prefix = "socket") {
95
106
  const crypto = /* @__PURE__ */ getCrypto();
96
- return `${prefix}-${process.pid}-${crypto.randomBytes(8).toString("hex")}`;
107
+ return `${prefix}-${import_node_process.default.pid}-${crypto.randomBytes(8).toString("hex")}`;
97
108
  }
98
109
  function getIpcStubPath(appName) {
99
110
  const tempDir = (0, import_socket.getOsTmpDir)();
100
111
  const path = /* @__PURE__ */ getPath();
101
112
  const stubDir = path.join(tempDir, ".socket-ipc", appName);
102
- return path.join(stubDir, `stub-${process.pid}.json`);
113
+ return path.join(stubDir, `stub-${import_node_process.default.pid}.json`);
103
114
  }
104
115
  async function ensureIpcDirectory(filePath) {
105
116
  const fs = /* @__PURE__ */ getFs();
@@ -112,7 +123,7 @@ async function writeIpcStub(appName, data) {
112
123
  await ensureIpcDirectory(stubPath);
113
124
  const ipcData = {
114
125
  data,
115
- pid: process.pid,
126
+ pid: import_node_process.default.pid,
116
127
  timestamp: Date.now()
117
128
  };
118
129
  const validated = IpcStubSchema.parse(ipcData);
@@ -198,9 +209,9 @@ function onIpc(handler) {
198
209
  handler(parsed);
199
210
  }
200
211
  };
201
- process.on("message", listener);
212
+ import_node_process.default.on("message", listener);
202
213
  return () => {
203
- process.off("message", listener);
214
+ import_node_process.default.off("message", listener);
204
215
  };
205
216
  }
206
217
  function waitForIpc(messageType, options = {}) {
@@ -228,6 +239,7 @@ function waitForIpc(messageType, options = {}) {
228
239
  cleanup = onIpc(handleMessage);
229
240
  if (timeout > 0) {
230
241
  timeoutId = setTimeout(handleTimeout, timeout);
242
+ timeoutId.unref();
231
243
  }
232
244
  });
233
245
  }
package/dist/json/edit.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
+ var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
6
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
9
  var __export = (target, all) => {
8
10
  for (var name in all)
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
16
18
  }
17
19
  return to;
18
20
  };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
  var edit_exports = {};
21
31
  __export(edit_exports, {
@@ -23,6 +33,7 @@ __export(edit_exports, {
23
33
  });
24
34
  module.exports = __toCommonJS(edit_exports);
25
35
  var import_promises = require("node:timers/promises");
36
+ var import_node_process = __toESM(require("node:process"));
26
37
  var import_format = require("./format");
27
38
  const identSymbol = import_format.INDENT_SYMBOL;
28
39
  const newlineSymbol = import_format.NEWLINE_SYMBOL;
@@ -41,7 +52,7 @@ async function retryWrite(filepath, content, retries = 3, baseDelay = 10) {
41
52
  for (let attempt = 0; attempt <= retries; attempt++) {
42
53
  try {
43
54
  await fsPromises.writeFile(filepath, content);
44
- if (process.platform === "win32") {
55
+ if (import_node_process.default.platform === "win32") {
45
56
  await (0, import_promises.setTimeout)(50);
46
57
  let accessRetries = 0;
47
58
  const maxAccessRetries = 5;
@@ -74,7 +85,7 @@ function parseJson(content) {
74
85
  }
75
86
  async function readFile(filepath) {
76
87
  const { promises: fsPromises } = /* @__PURE__ */ getFs();
77
- const maxRetries = process.platform === "win32" ? 5 : 1;
88
+ const maxRetries = import_node_process.default.platform === "win32" ? 5 : 1;
78
89
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
79
90
  try {
80
91
  return await fsPromises.readFile(filepath, "utf8");
@@ -84,7 +95,7 @@ async function readFile(filepath) {
84
95
  if (!isEnoent || isLastAttempt) {
85
96
  throw err;
86
97
  }
87
- const delay = process.platform === "win32" ? 50 * (attempt + 1) : 20;
98
+ const delay = import_node_process.default.platform === "win32" ? 50 * (attempt + 1) : 20;
88
99
  await (0, import_promises.setTimeout)(delay);
89
100
  }
90
101
  }
package/dist/logger.js CHANGED
@@ -36,6 +36,7 @@ __export(logger_exports, {
36
36
  lastWasBlankSymbol: () => lastWasBlankSymbol
37
37
  });
38
38
  module.exports = __toCommonJS(logger_exports);
39
+ var import_node_process = __toESM(require("node:process"));
39
40
  var import_is_unicode_supported = __toESM(require("./external/@socketregistry/is-unicode-supported"));
40
41
  var import_yoctocolors_cjs = __toESM(require("./external/yoctocolors-cjs"));
41
42
  var import_strings = require("./strings");
@@ -282,8 +283,8 @@ class Logger {
282
283
  con = /* @__PURE__ */ constructConsole(...ctorArgs);
283
284
  } else {
284
285
  con = /* @__PURE__ */ constructConsole({
285
- stdout: process.stdout,
286
- stderr: process.stderr
286
+ stdout: import_node_process.default.stdout,
287
+ stderr: import_node_process.default.stderr
287
288
  });
288
289
  for (const { 0: key, 1: method } of boundConsoleEntries) {
289
290
  con[key] = method;
@@ -1442,8 +1443,8 @@ function ensurePrototypeInitialized() {
1442
1443
  con = /* @__PURE__ */ constructConsole(...ctorArgs);
1443
1444
  } else {
1444
1445
  con = /* @__PURE__ */ constructConsole({
1445
- stdout: process.stdout,
1446
- stderr: process.stderr
1446
+ stdout: import_node_process.default.stdout,
1447
+ stderr: import_node_process.default.stderr
1447
1448
  });
1448
1449
  for (const { 0: k, 1: method } of boundConsoleEntries) {
1449
1450
  con[k] = method;
@@ -29,6 +29,7 @@ __export(memoization_exports, {
29
29
  });
30
30
  module.exports = __toCommonJS(memoization_exports);
31
31
  var import_debug = require("./debug");
32
+ const cacheRegistry = [];
32
33
  function memoize(fn, options = {}) {
33
34
  const {
34
35
  keyGen = (...args) => JSON.stringify(args),
@@ -41,6 +42,10 @@ function memoize(fn, options = {}) {
41
42
  }
42
43
  const cache = /* @__PURE__ */ new Map();
43
44
  const accessOrder = [];
45
+ cacheRegistry.push(() => {
46
+ cache.clear();
47
+ accessOrder.length = 0;
48
+ });
44
49
  function evictLRU() {
45
50
  if (cache.size >= maxSize && accessOrder.length > 0) {
46
51
  const oldest = accessOrder.shift();
@@ -62,15 +67,22 @@ function memoize(fn, options = {}) {
62
67
  return function memoized(...args) {
63
68
  const key = keyGen(...args);
64
69
  const cached = cache.get(key);
65
- if (cached && !isExpired(cached)) {
66
- cached.hits++;
70
+ if (cached) {
71
+ if (!isExpired(cached)) {
72
+ cached.hits++;
73
+ const index2 = accessOrder.indexOf(key);
74
+ if (index2 !== -1) {
75
+ accessOrder.splice(index2, 1);
76
+ }
77
+ accessOrder.push(key);
78
+ (0, import_debug.debugLog)(`[memoize:${name}] hit`, { key, hits: cached.hits });
79
+ return cached.value;
80
+ }
81
+ cache.delete(key);
67
82
  const index = accessOrder.indexOf(key);
68
83
  if (index !== -1) {
69
84
  accessOrder.splice(index, 1);
70
85
  }
71
- accessOrder.push(key);
72
- (0, import_debug.debugLog)(`[memoize:${name}] hit`, { key, hits: cached.hits });
73
- return cached.value;
74
86
  }
75
87
  (0, import_debug.debugLog)(`[memoize:${name}] miss`, { key });
76
88
  const value = fn(...args);
@@ -94,6 +106,10 @@ function memoizeAsync(fn, options = {}) {
94
106
  } = options;
95
107
  const cache = /* @__PURE__ */ new Map();
96
108
  const accessOrder = [];
109
+ cacheRegistry.push(() => {
110
+ cache.clear();
111
+ accessOrder.length = 0;
112
+ });
97
113
  function evictLRU() {
98
114
  if (cache.size >= maxSize && accessOrder.length > 0) {
99
115
  const oldest = accessOrder.shift();
@@ -112,22 +128,36 @@ function memoizeAsync(fn, options = {}) {
112
128
  }
113
129
  return Date.now() - entry.timestamp > ttl;
114
130
  }
131
+ const refreshing = /* @__PURE__ */ new Set();
115
132
  return async function memoized(...args) {
116
133
  const key = keyGen(...args);
117
134
  const cached = cache.get(key);
118
- if (cached && !isExpired(cached)) {
119
- cached.hits++;
135
+ if (cached) {
136
+ if (!isExpired(cached)) {
137
+ cached.hits++;
138
+ const index2 = accessOrder.indexOf(key);
139
+ if (index2 !== -1) {
140
+ accessOrder.splice(index2, 1);
141
+ }
142
+ accessOrder.push(key);
143
+ (0, import_debug.debugLog)(`[memoizeAsync:${name}] hit`, { key, hits: cached.hits });
144
+ return await cached.value;
145
+ }
146
+ if (refreshing.has(key)) {
147
+ (0, import_debug.debugLog)(`[memoizeAsync:${name}] stale-dedup`, { key });
148
+ return await cached.value;
149
+ }
150
+ cache.delete(key);
120
151
  const index = accessOrder.indexOf(key);
121
152
  if (index !== -1) {
122
153
  accessOrder.splice(index, 1);
123
154
  }
124
- accessOrder.push(key);
125
- (0, import_debug.debugLog)(`[memoizeAsync:${name}] hit`, { key, hits: cached.hits });
126
- return await cached.value;
127
155
  }
128
156
  (0, import_debug.debugLog)(`[memoizeAsync:${name}] miss`, { key });
157
+ refreshing.add(key);
129
158
  const promise = fn(...args).then(
130
159
  (result) => {
160
+ refreshing.delete(key);
131
161
  const entry = cache.get(key);
132
162
  if (entry) {
133
163
  entry.value = Promise.resolve(result);
@@ -135,6 +165,7 @@ function memoizeAsync(fn, options = {}) {
135
165
  return result;
136
166
  },
137
167
  (error) => {
168
+ refreshing.delete(key);
138
169
  cache.delete(key);
139
170
  const index = accessOrder.indexOf(key);
140
171
  if (index !== -1) {
@@ -167,14 +198,16 @@ function Memoize(options = {}) {
167
198
  }
168
199
  function clearAllMemoizationCaches() {
169
200
  (0, import_debug.debugLog)("[memoize:all] clear", { action: "clear-all-caches" });
201
+ for (const clear of cacheRegistry) {
202
+ clear();
203
+ }
170
204
  }
171
205
  function memoizeWeak(fn) {
172
206
  const cache = /* @__PURE__ */ new WeakMap();
173
207
  return function memoized(key) {
174
- const cached = cache.get(key);
175
- if (cached !== void 0) {
208
+ if (cache.has(key)) {
176
209
  (0, import_debug.debugLog)(`[memoizeWeak:${fn.name}] hit`);
177
- return cached;
210
+ return cache.get(key);
178
211
  }
179
212
  (0, import_debug.debugLog)(`[memoizeWeak:${fn.name}] miss`);
180
213
  const result = fn(key);
@@ -69,7 +69,15 @@ async function resolveRealPath(pathStr) {
69
69
  }
70
70
  async function mergePackageJson(pkgJsonPath, originalPkgJson) {
71
71
  const fs = /* @__PURE__ */ getFs();
72
- const pkgJson = JSON.parse(await fs.promises.readFile(pkgJsonPath, "utf8"));
72
+ let pkgJson;
73
+ try {
74
+ pkgJson = JSON.parse(await fs.promises.readFile(pkgJsonPath, "utf8"));
75
+ } catch (error) {
76
+ throw new Error(
77
+ `Failed to parse ${pkgJsonPath}: ${error instanceof Error ? error.message : String(error)}`,
78
+ { cause: error }
79
+ );
80
+ }
73
81
  const mergedPkgJson = originalPkgJson ? { ...originalPkgJson, ...pkgJson } : pkgJson;
74
82
  return mergedPkgJson;
75
83
  }
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
+ var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
6
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
9
  var __export = (target, all) => {
8
10
  for (var name in all)
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
16
18
  }
17
19
  return to;
18
20
  };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
  var performance_exports = {};
21
31
  __export(performance_exports, {
@@ -31,10 +41,11 @@ __export(performance_exports, {
31
41
  trackMemory: () => trackMemory
32
42
  });
33
43
  module.exports = __toCommonJS(performance_exports);
44
+ var import_node_process = __toESM(require("node:process"));
34
45
  var import_debug = require("./debug");
35
46
  const performanceMetrics = [];
36
47
  function isPerfEnabled() {
37
- return process.env["DEBUG"]?.includes("perf") || false;
48
+ return import_node_process.default.env["DEBUG"]?.includes("perf") || false;
38
49
  }
39
50
  function perfTimer(operation, metadata) {
40
51
  if (!isPerfEnabled()) {
@@ -155,7 +166,7 @@ function trackMemory(label) {
155
166
  if (!isPerfEnabled()) {
156
167
  return 0;
157
168
  }
158
- const usage = process.memoryUsage();
169
+ const usage = import_node_process.default.memoryUsage();
159
170
  const heapUsedMB = Math.round(usage.heapUsed / 1024 / 1024 * 100) / 100;
160
171
  (0, import_debug.debugLog)(`[perf] [MEMORY] ${label}: ${heapUsedMB}MB heap used`);
161
172
  const metric = {
@@ -179,7 +179,14 @@ class ProcessLockManager {
179
179
  if (existsSync(lockPath)) {
180
180
  throw new Error(`Lock already exists: ${lockPath}`);
181
181
  }
182
- mkdirSync(lockPath, { recursive: true });
182
+ const lastSlash = Math.max(
183
+ lockPath.lastIndexOf("/"),
184
+ lockPath.lastIndexOf("\\")
185
+ );
186
+ if (lastSlash > 0) {
187
+ mkdirSync(lockPath.slice(0, lastSlash), { recursive: true });
188
+ }
189
+ mkdirSync(lockPath);
183
190
  this.activeLocks.add(lockPath);
184
191
  this.startTouchTimer(lockPath, touchIntervalMs);
185
192
  return () => this.release(lockPath);
@@ -204,7 +211,10 @@ class ProcessLockManager {
204
211
  );
205
212
  }
206
213
  if (code === "ENOTDIR") {
207
- const lastSlashIndex = lockPath.lastIndexOf("/");
214
+ const lastSlashIndex = Math.max(
215
+ lockPath.lastIndexOf("/"),
216
+ lockPath.lastIndexOf("\\")
217
+ );
208
218
  const parentDir = lastSlashIndex === -1 ? "." : lockPath.slice(0, lastSlashIndex);
209
219
  throw new Error(
210
220
  `Cannot create lock directory: ${lockPath}
@@ -218,7 +228,10 @@ To resolve:
218
228
  );
219
229
  }
220
230
  if (code === "ENOENT") {
221
- const lastSlashIndex = lockPath.lastIndexOf("/");
231
+ const lastSlashIndex = Math.max(
232
+ lockPath.lastIndexOf("/"),
233
+ lockPath.lastIndexOf("\\")
234
+ );
222
235
  const parentDir = lastSlashIndex === -1 ? "." : lockPath.slice(0, lastSlashIndex);
223
236
  throw new Error(
224
237
  `Cannot create lock directory: ${lockPath}
@@ -1,6 +1,7 @@
1
1
  export declare class PromiseQueue {
2
2
  private queue;
3
3
  private running;
4
+ private idleResolvers;
4
5
  private readonly maxConcurrency;
5
6
  private readonly maxQueueLength;
6
7
  /**
@@ -16,6 +17,7 @@ export declare class PromiseQueue {
16
17
  */
17
18
  add<T>(fn: () => Promise<T>): Promise<T>;
18
19
  private runNext;
20
+ private notifyIdleIfNeeded;
19
21
  /**
20
22
  * Wait for all queued and running tasks to complete
21
23
  */