@socketsecurity/lib 5.26.0 → 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 +345 -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} +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
@@ -37,6 +37,7 @@ __export(arborist_exports, {
37
37
  module.exports = __toCommonJS(arborist_exports);
38
38
  var import_arborist = __toESM(require("../external/@npmcli/arborist"));
39
39
  var import_socket = require("../paths/socket");
40
+ var import_primordials = require("../primordials");
40
41
  let _fs;
41
42
  // @__NO_SIDE_EFFECTS__
42
43
  function getFs() {
@@ -70,11 +71,11 @@ function getBaseArboristOptions(installPath, quiet) {
70
71
  function readSingleDependency(packageJsonPath) {
71
72
  const fs = /* @__PURE__ */ getFs();
72
73
  const raw = fs.readFileSync(packageJsonPath, "utf8");
73
- const pkg = JSON.parse(raw);
74
+ const pkg = (0, import_primordials.JSONParse)(raw);
74
75
  const deps = pkg.dependencies ?? {};
75
- const names = Object.keys(deps);
76
+ const names = (0, import_primordials.ObjectKeys)(deps);
76
77
  if (names.length !== 1) {
77
- throw new Error(
78
+ throw new import_primordials.ErrorCtor(
78
79
  `safeIdealTree expects exactly one top-level dependency in ${packageJsonPath}, found ${names.length}`
79
80
  );
80
81
  }
@@ -84,7 +85,7 @@ function readTopLevelFromIdealTree(tree, targetName) {
84
85
  const root = tree;
85
86
  const inventory = root?.inventory;
86
87
  if (!inventory || typeof inventory.values !== "function") {
87
- throw new Error("Arborist idealTree missing inventory");
88
+ throw new import_primordials.ErrorCtor("Arborist idealTree missing inventory");
88
89
  }
89
90
  for (const node of inventory.values()) {
90
91
  if (node.isProjectRoot) {
@@ -92,7 +93,7 @@ function readTopLevelFromIdealTree(tree, targetName) {
92
93
  }
93
94
  if (node.name === targetName && node.depth === 1) {
94
95
  if (!node.version || !node.integrity) {
95
- throw new Error(
96
+ throw new import_primordials.ErrorCtor(
96
97
  `Arborist idealTree node for ${targetName} missing version/integrity`
97
98
  );
98
99
  }
@@ -103,7 +104,7 @@ function readTopLevelFromIdealTree(tree, targetName) {
103
104
  };
104
105
  }
105
106
  }
106
- throw new Error(
107
+ throw new import_primordials.ErrorCtor(
107
108
  `Arborist idealTree inventory has no top-level node for ${targetName}`
108
109
  );
109
110
  }
@@ -145,7 +146,7 @@ async function writeSafeNpmrc(installPath, options) {
145
146
  ...options
146
147
  };
147
148
  if (minReleaseDays !== void 0 && minReleaseMins !== void 0) {
148
- throw new Error(
149
+ throw new import_primordials.ErrorCtor(
149
150
  "writeSafeNpmrc: minReleaseDays and minReleaseMins are mutually exclusive"
150
151
  );
151
152
  }
@@ -158,10 +159,10 @@ async function writeSafeNpmrc(installPath, options) {
158
159
  "progress=false"
159
160
  ];
160
161
  if (minReleaseDays !== void 0) {
161
- lines.push(`min-release-age=${minReleaseDays}`);
162
+ (0, import_primordials.ArrayPrototypePush)(lines, `min-release-age=${minReleaseDays}`);
162
163
  }
163
164
  if (minReleaseMins !== void 0) {
164
- lines.push(`minimum-release-age=${minReleaseMins}`);
165
+ (0, import_primordials.ArrayPrototypePush)(lines, `minimum-release-age=${minReleaseMins}`);
165
166
  }
166
167
  await fs.promises.writeFile(
167
168
  path.join(installPath, ".npmrc"),
@@ -52,8 +52,10 @@ var import_normalize = require("../paths/normalize");
52
52
  var import_socket = require("../paths/socket");
53
53
  var import_process_lock = require("../process-lock");
54
54
  var import_spawn = require("../spawn");
55
+ var import_crypto = require("../crypto");
55
56
  var import_cache = require("./cache");
56
57
  var import_integrity = require("./integrity");
58
+ var import_primordials = require("../primordials");
57
59
  let _crypto;
58
60
  // @__NO_SIDE_EFFECTS__
59
61
  function getCrypto() {
@@ -85,7 +87,7 @@ async function cleanDlxCache(maxAge = import_time.DLX_BINARY_CACHE_TTL) {
85
87
  return 0;
86
88
  }
87
89
  let cleaned = 0;
88
- const now = Date.now();
90
+ const now = (0, import_primordials.DateNow)();
89
91
  const path = /* @__PURE__ */ getPath();
90
92
  const entries = await fs.promises.readdir(cacheDir);
91
93
  for (const entry of entries) {
@@ -96,7 +98,7 @@ async function cleanDlxCache(maxAge = import_time.DLX_BINARY_CACHE_TTL) {
96
98
  continue;
97
99
  }
98
100
  const metadata = await (0, import_fs.readJson)(metaPath, { throws: false });
99
- if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
101
+ if (!metadata || typeof metadata !== "object" || (0, import_primordials.ArrayIsArray)(metadata)) {
100
102
  continue;
101
103
  }
102
104
  const timestamp = metadata["timestamp"];
@@ -122,7 +124,7 @@ async function dlxBinary(args, options, spawnExtra) {
122
124
  const {
123
125
  cacheTtl = import_time.DLX_BINARY_CACHE_TTL,
124
126
  force: userForce = false,
125
- hash,
127
+ hash: hash2,
126
128
  integrity: rawIntegrity,
127
129
  name,
128
130
  sha256: rawSha256,
@@ -132,8 +134,8 @@ async function dlxBinary(args, options, spawnExtra) {
132
134
  } = { __proto__: null, ...options };
133
135
  let integrity = rawIntegrity;
134
136
  let sha256 = rawSha256;
135
- if (hash !== void 0) {
136
- const normalized = (0, import_integrity.normalizeHash)(hash);
137
+ if (hash2 !== void 0) {
138
+ const normalized = (0, import_integrity.normalizeHash)(hash2);
137
139
  if (normalized.type === "integrity") {
138
140
  integrity = normalized.value;
139
141
  } else {
@@ -155,7 +157,7 @@ async function dlxBinary(args, options, spawnExtra) {
155
157
  try {
156
158
  const metaPath = getBinaryCacheMetadataPath(cacheEntryDir);
157
159
  const metadata = await (0, import_fs.readJson)(metaPath, { throws: false });
158
- if (metadata && typeof metadata === "object" && !Array.isArray(metadata) && typeof metadata["integrity"] === "string") {
160
+ if (metadata && typeof metadata === "object" && !(0, import_primordials.ArrayIsArray)(metadata) && typeof metadata["integrity"] === "string") {
159
161
  computedIntegrity = metadata["integrity"];
160
162
  if (!fs.existsSync(binaryPath)) {
161
163
  downloaded = true;
@@ -175,20 +177,20 @@ async function dlxBinary(args, options, spawnExtra) {
175
177
  } catch (e) {
176
178
  const code = e.code;
177
179
  if (code === "EACCES" || code === "EPERM") {
178
- throw new Error(
180
+ throw new import_primordials.ErrorCtor(
179
181
  `Permission denied creating binary cache directory: ${cacheEntryDir}
180
182
  Please check directory permissions or run with appropriate access.`,
181
183
  { cause: e }
182
184
  );
183
185
  }
184
186
  if (code === "EROFS") {
185
- throw new Error(
187
+ throw new import_primordials.ErrorCtor(
186
188
  `Cannot create binary cache directory on read-only filesystem: ${cacheEntryDir}
187
189
  Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`,
188
190
  { cause: e }
189
191
  );
190
192
  }
191
- throw new Error(
193
+ throw new import_primordials.ErrorCtor(
192
194
  `Failed to create binary cache directory: ${cacheEntryDir}`,
193
195
  { cause: e }
194
196
  );
@@ -228,7 +230,7 @@ async function downloadBinary(options) {
228
230
  const {
229
231
  cacheTtl = import_time.DLX_BINARY_CACHE_TTL,
230
232
  force = false,
231
- hash,
233
+ hash: hash2,
232
234
  integrity: rawIntegrity,
233
235
  name,
234
236
  sha256: rawSha256,
@@ -236,8 +238,8 @@ async function downloadBinary(options) {
236
238
  } = { __proto__: null, ...options };
237
239
  let integrity = rawIntegrity;
238
240
  let sha256 = rawSha256;
239
- if (hash !== void 0) {
240
- const normalized = (0, import_integrity.normalizeHash)(hash);
241
+ if (hash2 !== void 0) {
242
+ const normalized = (0, import_integrity.normalizeHash)(hash2);
241
243
  if (normalized.type === "integrity") {
242
244
  integrity = normalized.value;
243
245
  } else {
@@ -261,20 +263,20 @@ async function downloadBinary(options) {
261
263
  } catch (e) {
262
264
  const code = e.code;
263
265
  if (code === "EACCES" || code === "EPERM") {
264
- throw new Error(
266
+ throw new import_primordials.ErrorCtor(
265
267
  `Permission denied creating binary cache directory: ${cacheEntryDir}
266
268
  Please check directory permissions or run with appropriate access.`,
267
269
  { cause: e }
268
270
  );
269
271
  }
270
272
  if (code === "EROFS") {
271
- throw new Error(
273
+ throw new import_primordials.ErrorCtor(
272
274
  `Cannot create binary cache directory on read-only filesystem: ${cacheEntryDir}
273
275
  Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`,
274
276
  { cause: e }
275
277
  );
276
278
  }
277
- throw new Error(
279
+ throw new import_primordials.ErrorCtor(
278
280
  `Failed to create binary cache directory: ${cacheEntryDir}`,
279
281
  { cause: e }
280
282
  );
@@ -313,8 +315,7 @@ async function downloadBinaryFile(url, destPath, integrity, sha256) {
313
315
  const stats = await fs.promises.stat(destPath);
314
316
  if (stats.size > 0) {
315
317
  const fileBuffer2 = await fs.promises.readFile(destPath);
316
- const hash2 = crypto.createHash("sha512").update(fileBuffer2).digest("base64");
317
- return `sha512-${hash2}`;
318
+ return `sha512-${(0, import_crypto.hash)("sha512", fileBuffer2, "base64")}`;
318
319
  }
319
320
  }
320
321
  try {
@@ -328,8 +329,7 @@ Check your internet connection or verify the URL is accessible.`,
328
329
  );
329
330
  }
330
331
  const fileBuffer = await fs.promises.readFile(destPath);
331
- const hash = crypto.createHash("sha512").update(fileBuffer).digest("base64");
332
- const actualIntegrity = `sha512-${hash}`;
332
+ const actualIntegrity = `sha512-${(0, import_crypto.hash)("sha512", fileBuffer, "base64")}`;
333
333
  if (integrity) {
334
334
  const integrityMatch = actualIntegrity.length === integrity.length && crypto.timingSafeEqual(
335
335
  Buffer.from(actualIntegrity),
@@ -383,7 +383,7 @@ async function isBinaryCacheValid(cacheEntryPath, cacheTtl) {
383
383
  if (!(0, import_objects.isObjectObject)(metadata)) {
384
384
  return false;
385
385
  }
386
- const now = Date.now();
386
+ const now = (0, import_primordials.DateNow)();
387
387
  const timestamp = metadata["timestamp"];
388
388
  if (typeof timestamp !== "number" || timestamp <= 0) {
389
389
  return false;
@@ -404,7 +404,7 @@ async function listDlxCache() {
404
404
  return [];
405
405
  }
406
406
  const results = [];
407
- const now = Date.now();
407
+ const now = (0, import_primordials.DateNow)();
408
408
  const path = /* @__PURE__ */ getPath();
409
409
  const entries = await fs.promises.readdir(cacheDir);
410
410
  for (const entry of entries) {
@@ -415,14 +415,17 @@ async function listDlxCache() {
415
415
  }
416
416
  const metaPath = getBinaryCacheMetadataPath(entryPath);
417
417
  const metadata = await (0, import_fs.readJson)(metaPath, { throws: false });
418
- if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
418
+ if (!metadata || typeof metadata !== "object" || (0, import_primordials.ArrayIsArray)(metadata)) {
419
419
  continue;
420
420
  }
421
421
  const metaObj = metadata;
422
422
  const source = metaObj["source"];
423
423
  const url = source?.["url"] || metaObj["url"] || "";
424
424
  const files = await fs.promises.readdir(entryPath);
425
- const binaryFile = files.find((f) => !f.startsWith("."));
425
+ const binaryFile = (0, import_primordials.ArrayPrototypeFind)(
426
+ files,
427
+ (f) => !(0, import_primordials.StringPrototypeStartsWith)(f, ".")
428
+ );
426
429
  if (binaryFile) {
427
430
  const binaryPath = path.join(entryPath, binaryFile);
428
431
  const binaryStats = await fs.promises.stat(binaryPath);
@@ -444,7 +447,7 @@ async function writeBinaryCacheMetadata(cacheEntryPath, cacheKey, url, integrity
444
447
  const metadata = {
445
448
  version: "1.0.0",
446
449
  cache_key: cacheKey,
447
- timestamp: Date.now(),
450
+ timestamp: (0, import_primordials.DateNow)(),
448
451
  integrity,
449
452
  size,
450
453
  source: {
package/dist/dlx/cache.js CHANGED
@@ -23,17 +23,9 @@ __export(cache_exports, {
23
23
  generateCacheKey: () => generateCacheKey
24
24
  });
25
25
  module.exports = __toCommonJS(cache_exports);
26
- let _crypto;
27
- // @__NO_SIDE_EFFECTS__
28
- function getCrypto() {
29
- if (_crypto === void 0) {
30
- _crypto = require("node:crypto");
31
- }
32
- return _crypto;
33
- }
26
+ var import_crypto = require("../crypto");
34
27
  function generateCacheKey(spec) {
35
- const crypto = /* @__PURE__ */ getCrypto();
36
- return crypto.createHash("sha512").update(spec).digest("hex").substring(0, 16);
28
+ return (0, import_crypto.hash)("sha512", spec, "hex").substring(0, 16);
37
29
  }
38
30
  // Annotate the CommonJS export names for ESM import in node:
39
31
  0 && (module.exports = {
@@ -30,12 +30,13 @@ __export(detect_exports, {
30
30
  module.exports = __toCommonJS(detect_exports);
31
31
  var import_paths = require("./paths");
32
32
  var import_socket = require("../paths/socket");
33
+ var import_primordials = require("../primordials");
33
34
  let _fs;
34
35
  let _path;
35
- const NODE_JS_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs"]);
36
+ const NODE_JS_EXTENSIONS = new import_primordials.SetCtor([".js", ".mjs", ".cjs"]);
36
37
  const PACKAGE_JSON_PATH_CACHE_MAX_SIZE = 200;
37
38
  const PACKAGE_JSON_NEGATIVE_TTL_MS = 1e4;
38
- const packageJsonPathCache = /* @__PURE__ */ new Map();
39
+ const packageJsonPathCache = new import_primordials.MapCtor();
39
40
  function packageJsonPathCacheSet(key, value) {
40
41
  if (packageJsonPathCache.has(key)) {
41
42
  packageJsonPathCache.delete(key);
@@ -47,7 +48,7 @@ function packageJsonPathCacheSet(key, value) {
47
48
  }
48
49
  packageJsonPathCache.set(key, { path: value, at: Date.now() });
49
50
  }
50
- const packageJsonContentCache = /* @__PURE__ */ new Map();
51
+ const packageJsonContentCache = new import_primordials.MapCtor();
51
52
  function findPackageJson(filePath) {
52
53
  const fs = /* @__PURE__ */ getFs();
53
54
  const path = /* @__PURE__ */ getPath();
@@ -55,7 +56,7 @@ function findPackageJson(filePath) {
55
56
  const cached = packageJsonPathCache.get(startDir);
56
57
  if (cached !== void 0) {
57
58
  if (cached.path === null) {
58
- if (Date.now() - cached.at < PACKAGE_JSON_NEGATIVE_TTL_MS) {
59
+ if ((0, import_primordials.DateNow)() - cached.at < PACKAGE_JSON_NEGATIVE_TTL_MS) {
59
60
  return void 0;
60
61
  }
61
62
  packageJsonPathCache.delete(startDir);
@@ -107,7 +108,7 @@ function readPackageJson(packageJsonPath) {
107
108
  return cached.content;
108
109
  }
109
110
  try {
110
- const content = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
111
+ const content = (0, import_primordials.JSONParse)(fs.readFileSync(packageJsonPath, "utf8"));
111
112
  packageJsonContentCache.set(packageJsonPath, { mtimeMs, content });
112
113
  return content;
113
114
  } catch {
@@ -27,14 +27,16 @@ __export(integrity_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(integrity_exports);
29
29
  var import_node_crypto = require("node:crypto");
30
+ var import_crypto = require("../crypto");
31
+ var import_primordials = require("../primordials");
30
32
  const INTEGRITY_PREFIX = "sha512-";
31
33
  const INTEGRITY_BODY_RE = /^[A-Za-z0-9+/=]+$/;
32
34
  const CHECKSUM_RE = /^[a-f0-9]{64}$/i;
33
35
  function isIntegrityString(s) {
34
- if (!s.startsWith(INTEGRITY_PREFIX)) {
36
+ if (!(0, import_primordials.StringPrototypeStartsWith)(s, INTEGRITY_PREFIX)) {
35
37
  return false;
36
38
  }
37
- const body = s.slice(INTEGRITY_PREFIX.length);
39
+ const body = (0, import_primordials.StringPrototypeSlice)(s, INTEGRITY_PREFIX.length);
38
40
  return body.length > 0 && INTEGRITY_BODY_RE.test(body);
39
41
  }
40
42
  function isChecksumString(s) {
@@ -44,7 +46,7 @@ function normalizeHash(spec) {
44
46
  if (typeof spec === "object" && spec !== null) {
45
47
  if (spec.type === "integrity") {
46
48
  if (!isIntegrityString(spec.value)) {
47
- throw new TypeError(
49
+ throw new import_primordials.TypeErrorCtor(
48
50
  `Expected SRI integrity string "sha512-<base64>", got: ${spec.value}`
49
51
  );
50
52
  }
@@ -52,18 +54,18 @@ function normalizeHash(spec) {
52
54
  }
53
55
  if (spec.type === "checksum") {
54
56
  if (!isChecksumString(spec.value)) {
55
- throw new TypeError(
57
+ throw new import_primordials.TypeErrorCtor(
56
58
  `Expected sha256 hex string (64 hex chars), got: ${spec.value}`
57
59
  );
58
60
  }
59
61
  return { type: "checksum", value: spec.value };
60
62
  }
61
- throw new TypeError(
63
+ throw new import_primordials.TypeErrorCtor(
62
64
  `Unknown hash type: ${spec.type}`
63
65
  );
64
66
  }
65
67
  if (typeof spec !== "string") {
66
- throw new TypeError(
68
+ throw new import_primordials.TypeErrorCtor(
67
69
  `HashSpec must be a string or { type, value } object, got: ${typeof spec}`
68
70
  );
69
71
  }
@@ -73,19 +75,19 @@ function normalizeHash(spec) {
73
75
  if (isChecksumString(spec)) {
74
76
  return { type: "checksum", value: spec };
75
77
  }
76
- throw new TypeError(
78
+ throw new import_primordials.TypeErrorCtor(
77
79
  `Unrecognized hash format. Expected SRI integrity ("sha512-<base64>") or sha256 hex (64 hex chars), got: ${spec}`
78
80
  );
79
81
  }
80
82
  function computeHashes(bytes) {
81
- const integrity = `sha512-${(0, import_node_crypto.createHash)("sha512").update(bytes).digest("base64")}`;
82
- const checksum = (0, import_node_crypto.createHash)("sha256").update(bytes).digest("hex");
83
+ const integrity = `sha512-${(0, import_crypto.hash)("sha512", bytes, "base64")}`;
84
+ const checksum = (0, import_crypto.hash)("sha256", bytes, "hex");
83
85
  return { integrity, checksum };
84
86
  }
85
87
  function verifyHash(expected, computed) {
86
88
  const actual = expected.type === "integrity" ? computed.integrity : computed.checksum;
87
- const expectedBuf = Buffer.from(expected.value);
88
- const actualBuf = Buffer.from(actual);
89
+ const expectedBuf = (0, import_primordials.BufferFrom)(expected.value);
90
+ const actualBuf = (0, import_primordials.BufferFrom)(actual);
89
91
  if (expectedBuf.length !== actualBuf.length || !(0, import_node_crypto.timingSafeEqual)(expectedBuf, actualBuf)) {
90
92
  throw new DlxHashMismatchError(expected, computed);
91
93
  }
@@ -40,6 +40,7 @@ var import_pacote = __toESM(require("../external/pacote"));
40
40
  var import_fs = require("../fs");
41
41
  var import_arborist = require("./arborist");
42
42
  var import_integrity = require("./integrity");
43
+ var import_primordials = require("../primordials");
43
44
  let _fs;
44
45
  // @__NO_SIDE_EFFECTS__
45
46
  function getFs() {
@@ -64,18 +65,18 @@ class DlxLockfileError extends Error {
64
65
  }
65
66
  }
66
67
  function specName(spec) {
67
- const atIdx = spec.lastIndexOf("@");
68
+ const atIdx = (0, import_primordials.StringPrototypeLastIndexOf)(spec, "@");
68
69
  if (atIdx <= 0) {
69
70
  return spec;
70
71
  }
71
- return spec.slice(0, atIdx);
72
+ return (0, import_primordials.StringPrototypeSlice)(spec, 0, atIdx);
72
73
  }
73
74
  function specRange(spec) {
74
- const atIdx = spec.lastIndexOf("@");
75
+ const atIdx = (0, import_primordials.StringPrototypeLastIndexOf)(spec, "@");
75
76
  if (atIdx <= 0) {
76
77
  return "latest";
77
78
  }
78
- return spec.slice(atIdx + 1) || "latest";
79
+ return (0, import_primordials.StringPrototypeSlice)(spec, atIdx + 1) || "latest";
79
80
  }
80
81
  async function generatePackagePin(options) {
81
82
  const fs = /* @__PURE__ */ getFs();
@@ -91,14 +92,14 @@ async function generatePackagePin(options) {
91
92
  }
92
93
  const effectiveDays = minReleaseDays !== void 0 ? minReleaseDays : minReleaseMins !== void 0 ? void 0 : DEFAULT_MIN_RELEASE_DAYS;
93
94
  const ageMs = effectiveDays !== void 0 ? effectiveDays * 864e5 : minReleaseMins !== void 0 ? minReleaseMins * 6e4 : 0;
94
- const before = ageMs > 0 ? new Date(Date.now() - ageMs) : void 0;
95
+ const before = ageMs > 0 ? new import_primordials.DateCtor((0, import_primordials.DateNow)() - ageMs) : void 0;
95
96
  const scratch = path.join(
96
97
  (0, import_node_os.tmpdir)(),
97
98
  `socket-lib-pin-${process.pid}-${Date.now()}`
98
99
  );
99
100
  await (0, import_fs.safeMkdir)(scratch, { recursive: true });
100
101
  try {
101
- const packageJson = JSON.stringify(
102
+ const packageJson = (0, import_primordials.JSONStringify)(
102
103
  {
103
104
  name: "socket-lib-pin",
104
105
  version: "0.0.0",
@@ -31,6 +31,7 @@ var import_fs = require("../fs");
31
31
  var import_logger = require("../logger");
32
32
  var import_socket = require("../paths/socket");
33
33
  var import_process_lock = require("../process-lock");
34
+ var import_primordials = require("../primordials");
34
35
  let _fs;
35
36
  let _path;
36
37
  // @__NO_SIDE_EFFECTS__
@@ -78,7 +79,7 @@ class DlxManifest {
78
79
  if (!content) {
79
80
  return { __proto__: null };
80
81
  }
81
- return JSON.parse(content);
82
+ return (0, import_primordials.JSONParse)(content);
82
83
  } catch (e) {
83
84
  logger.warn(`Failed to read manifest: ${(0, import_errors.errorMessage)(e)}`);
84
85
  return { __proto__: null };
@@ -95,7 +96,7 @@ class DlxManifest {
95
96
  } catch (e) {
96
97
  logger.warn(`Failed to create manifest directory: ${(0, import_errors.errorMessage)(e)}`);
97
98
  }
98
- const content = JSON.stringify(data, null, 2);
99
+ const content = (0, import_primordials.JSONStringify)(data, null, 2);
99
100
  const tempPath = `${this.manifestPath}.tmp`;
100
101
  try {
101
102
  fs.writeFileSync(tempPath, content, "utf8");
@@ -170,8 +171,8 @@ class DlxManifest {
170
171
  if (!content) {
171
172
  return [];
172
173
  }
173
- const data = JSON.parse(content);
174
- return Object.keys(data);
174
+ const data = (0, import_primordials.JSONParse)(content);
175
+ return (0, import_primordials.ObjectKeys)(data);
175
176
  } catch (e) {
176
177
  logger.warn(`Failed to get package list: ${(0, import_errors.errorMessage)(e)}`);
177
178
  return [];
@@ -195,7 +196,7 @@ class DlxManifest {
195
196
  if (!record) {
196
197
  return false;
197
198
  }
198
- const age = Date.now() - record.timestampFetch;
199
+ const age = (0, import_primordials.DateNow)() - record.timestampFetch;
199
200
  return age < ttlMs;
200
201
  }
201
202
  /**
@@ -54,17 +54,18 @@ var import_socket2 = require("../paths/socket");
54
54
  var import_process_lock = require("../process-lock");
55
55
  var import_spawn = require("../spawn");
56
56
  var import_cache = require("./cache");
57
+ var import_primordials = require("../primordials");
57
58
  let _fs;
58
59
  let _path;
59
60
  const rangeOperatorsRegExp = /[~^><=xX* ]|\|\|/;
60
61
  const FIREWALL_API_URL = "https://firewall-api.socket.dev/purl";
61
62
  const FIREWALL_TIMEOUT = 1e4;
62
- const FIREWALL_BLOCK_SEVERITIES = /* @__PURE__ */ new Set([
63
+ const FIREWALL_BLOCK_SEVERITIES = new import_primordials.SetCtor([
63
64
  "critical",
64
65
  "high"
65
66
  ]);
66
67
  const BINARY_PATH_CACHE_MAX_SIZE = 200;
67
- const binaryPathCache = /* @__PURE__ */ new Map();
68
+ const binaryPathCache = new import_primordials.MapCtor();
68
69
  function binaryPathCacheSet(key, value) {
69
70
  if (binaryPathCache.has(key)) {
70
71
  binaryPathCache.delete(key);
@@ -96,7 +97,7 @@ async function checkFirewallPurls(arb, requestedPackage) {
96
97
  return;
97
98
  }
98
99
  const blocked = [];
99
- await Promise.allSettled(
100
+ await (0, import_primordials.PromiseAllSettled)(
100
101
  purls.map(async ({ name, purl, version }) => {
101
102
  try {
102
103
  const data = await (0, import_http_request.httpJson)(
@@ -126,7 +127,7 @@ async function checkFirewallPurls(arb, requestedPackage) {
126
127
  );
127
128
  if (blocked.length > 0) {
128
129
  const details = blocked.map((b) => ` ${b.name}@${b.version}: ${b.alerts.join(", ")}`).join("\n");
129
- throw new Error(
130
+ throw new import_primordials.ErrorCtor(
130
131
  `Socket Firewall blocked installation of "${requestedPackage}".
131
132
  The following dependencies have security alerts:
132
133
  ${details}
@@ -175,7 +176,7 @@ async function downloadPackage(options) {
175
176
  ...options
176
177
  };
177
178
  const { name: packageName, version: packageVersion } = parsePackageSpec(packageSpec);
178
- const isVersionRange = packageVersion !== void 0 && rangeOperatorsRegExp.test(packageVersion);
179
+ const isVersionRange = packageVersion !== void 0 && (0, import_primordials.RegExpPrototypeTest)(rangeOperatorsRegExp, packageVersion);
179
180
  const force = userForce !== void 0 ? userForce : yes === true ? true : isVersionRange;
180
181
  const fullPackageSpec = packageVersion ? `${packageName}@${packageVersion}` : packageName;
181
182
  const { installed, packageDir } = await ensurePackageInstalled(
@@ -205,20 +206,20 @@ async function ensurePackageInstalled(packageName, packageSpec, force, install)
205
206
  } catch (e) {
206
207
  const code = e.code;
207
208
  if (code === "EACCES" || code === "EPERM") {
208
- throw new Error(
209
+ throw new import_primordials.ErrorCtor(
209
210
  `Permission denied creating package directory: ${packageDir}
210
211
  Please check directory permissions or run with appropriate access.`,
211
212
  { cause: e }
212
213
  );
213
214
  }
214
215
  if (code === "EROFS") {
215
- throw new Error(
216
+ throw new import_primordials.ErrorCtor(
216
217
  `Cannot create package directory on read-only filesystem: ${packageDir}
217
218
  Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`,
218
219
  { cause: e }
219
220
  );
220
221
  }
221
- throw new Error(`Failed to create package directory: ${packageDir}`, {
222
+ throw new import_primordials.ErrorCtor(`Failed to create package directory: ${packageDir}`, {
222
223
  cause: e
223
224
  });
224
225
  }
@@ -334,7 +335,7 @@ function findBinaryPath(packageDir, packageName, binaryName) {
334
335
  binPath = bin;
335
336
  } else if (typeof bin === "object" && bin !== null) {
336
337
  const binObj = bin;
337
- const binKeys = Object.keys(binObj);
338
+ const binKeys = (0, import_primordials.ObjectKeys)(binObj);
338
339
  if (binKeys.length === 1) {
339
340
  binName = binKeys[0];
340
341
  binPath = binObj[binName];
@@ -369,7 +370,7 @@ function findBinaryPath(packageDir, packageName, binaryName) {
369
370
  }
370
371
  }
371
372
  if (!binPath) {
372
- throw new Error(`No binary found for package "${packageName}"`);
373
+ throw new import_primordials.ErrorCtor(`No binary found for package "${packageName}"`);
373
374
  }
374
375
  const rawPath = (0, import_normalize.normalizePath)(path.join(installedDir, binPath));
375
376
  return resolveBinaryPath(rawPath);
@@ -395,7 +396,7 @@ function makePackageBinsExecutable(packageDir, packageName) {
395
396
  binPaths.push(bin);
396
397
  } else if (typeof bin === "object" && bin !== null) {
397
398
  const binObj = bin;
398
- binPaths.push(...Object.values(binObj));
399
+ binPaths.push(...(0, import_primordials.ObjectValues)(binObj));
399
400
  }
400
401
  for (const binPath of binPaths) {
401
402
  const fullPath = (0, import_normalize.normalizePath)(path.join(installedDir, binPath));
@@ -410,8 +411,8 @@ function makePackageBinsExecutable(packageDir, packageName) {
410
411
  }
411
412
  }
412
413
  function npmPurl(name, version) {
413
- const encoded = name.startsWith("@") ? `%40${name.slice(1)}` : name;
414
- const encodedVersion = version.replace(/\+/g, "%2B");
414
+ const encoded = (0, import_primordials.StringPrototypeStartsWith)(name, "@") ? `%40${(0, import_primordials.StringPrototypeSlice)(name, 1)}` : name;
415
+ const encodedVersion = (0, import_primordials.StringPrototypeReplace)(version, /\+/g, "%2B");
415
416
  return `pkg:npm/${encoded}@${encodedVersion}`;
416
417
  }
417
418
  function parsePackageSpec(spec) {
@@ -423,13 +424,13 @@ function parsePackageSpec(spec) {
423
424
  version
424
425
  };
425
426
  } catch {
426
- const atIndex = spec.lastIndexOf("@");
427
+ const atIndex = (0, import_primordials.StringPrototypeLastIndexOf)(spec, "@");
427
428
  if (atIndex === -1 || atIndex === 0) {
428
429
  return { name: spec, version: void 0 };
429
430
  }
430
- const sliced = spec.slice(atIndex + 1);
431
+ const sliced = (0, import_primordials.StringPrototypeSlice)(spec, atIndex + 1);
431
432
  return {
432
- name: spec.slice(0, atIndex),
433
+ name: (0, import_primordials.StringPrototypeSlice)(spec, 0, atIndex),
433
434
  // A trailing `@` (e.g. `'pkg@'`) yields an empty slice — normalize
434
435
  // to undefined so downstream "no version" checks behave.
435
436
  version: sliced || void 0
@@ -30,6 +30,7 @@ module.exports = __toCommonJS(packages_exports);
30
30
  var import_fs = require("../fs");
31
31
  var import_socket = require("../paths/socket");
32
32
  var import_paths = require("./paths");
33
+ var import_primordials = require("../primordials");
33
34
  let _fs;
34
35
  // @__NO_SIDE_EFFECTS__
35
36
  function getFs() {
@@ -55,7 +56,7 @@ async function listDlxPackagesAsync() {
55
56
  const entries = await fs.promises.readdir((0, import_socket.getSocketDlxDir)(), {
56
57
  withFileTypes: true
57
58
  });
58
- return entries.filter((e) => e.isDirectory()).map((e) => e.name).sort();
59
+ return (0, import_primordials.ArrayPrototypeFilter)(entries, (e) => e.isDirectory()).map((e) => e.name).sort();
59
60
  } catch {
60
61
  return [];
61
62
  }
@@ -65,7 +66,7 @@ async function removeDlxPackage(packageName) {
65
66
  try {
66
67
  await (0, import_fs.safeDelete)(packageDir, { recursive: true, force: true });
67
68
  } catch (e) {
68
- throw new Error(`Failed to remove DLX package "${packageName}"`, {
69
+ throw new import_primordials.ErrorCtor(`Failed to remove DLX package "${packageName}"`, {
69
70
  cause: e
70
71
  });
71
72
  }
@@ -77,7 +78,7 @@ function removeDlxPackageSync(packageName) {
77
78
  } catch (e) {
78
79
  const code = e.code;
79
80
  if (code === "EACCES" || code === "EPERM") {
80
- throw new Error(
81
+ throw new import_primordials.ErrorCtor(
81
82
  `Permission denied removing DLX package "${packageName}"
82
83
  Directory: ${packageDir}
83
84
  To resolve:
@@ -89,14 +90,14 @@ To resolve:
89
90
  );
90
91
  }
91
92
  if (code === "EROFS") {
92
- throw new Error(
93
+ throw new import_primordials.ErrorCtor(
93
94
  `Cannot remove DLX package "${packageName}" from read-only filesystem
94
95
  Directory: ${packageDir}
95
96
  The filesystem is mounted read-only.`,
96
97
  { cause: e }
97
98
  );
98
99
  }
99
- throw new Error(
100
+ throw new import_primordials.ErrorCtor(
100
101
  `Failed to remove DLX package "${packageName}"
101
102
  Directory: ${packageDir}
102
103
  Check permissions and ensure no programs are using this directory.`,