@socketsecurity/lib 5.2.1 → 5.4.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 (60) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/bin.d.ts +0 -9
  3. package/dist/bin.js +70 -48
  4. package/dist/constants/agents.js +2 -2
  5. package/dist/constants/platform.d.ts +21 -0
  6. package/dist/constants/platform.js +30 -6
  7. package/dist/cover/code.js +13 -5
  8. package/dist/debug.js +1 -1
  9. package/dist/dlx/binary.d.ts +1 -1
  10. package/dist/dlx/binary.js +49 -39
  11. package/dist/dlx/cache.js +10 -2
  12. package/dist/dlx/dir.js +1 -1
  13. package/dist/dlx/manifest.d.ts +2 -1
  14. package/dist/dlx/manifest.js +45 -41
  15. package/dist/dlx/package.js +39 -19
  16. package/dist/dlx/packages.js +1 -1
  17. package/dist/dlx/paths.js +1 -1
  18. package/dist/env/rewire.js +10 -2
  19. package/dist/external/@inquirer/checkbox.js +4 -2528
  20. package/dist/external/@inquirer/confirm.js +4 -2371
  21. package/dist/external/@inquirer/input.js +4 -2395
  22. package/dist/external/@inquirer/password.js +4 -2503
  23. package/dist/external/@inquirer/search.js +4 -2500
  24. package/dist/external/@inquirer/select.js +4 -2617
  25. package/dist/external/del.js +4 -7139
  26. package/dist/external/fast-glob.js +4 -5776
  27. package/dist/external/inquirer-pack.js +4610 -0
  28. package/dist/external/npm-core.js +3 -1
  29. package/dist/external/pico-pack.js +7162 -0
  30. package/dist/external/picomatch.js +4 -1523
  31. package/dist/external/spdx-correct.js +4 -1384
  32. package/dist/external/spdx-expression-parse.js +4 -1047
  33. package/dist/external/spdx-pack.js +1640 -0
  34. package/dist/external/validate-npm-package-name.js +4 -104
  35. package/dist/fs.js +3 -3
  36. package/dist/git.js +41 -38
  37. package/dist/http-request.js +12 -4
  38. package/dist/ipc.js +53 -29
  39. package/dist/json/edit.js +1 -1
  40. package/dist/json/format.js +1 -1
  41. package/dist/logger.js +1 -1
  42. package/dist/packages/edit.js +3 -3
  43. package/dist/packages/isolation.js +45 -23
  44. package/dist/packages/licenses.js +10 -2
  45. package/dist/paths/normalize.js +3 -3
  46. package/dist/paths/packages.js +1 -1
  47. package/dist/paths/socket.d.ts +2 -2
  48. package/dist/paths/socket.js +27 -21
  49. package/dist/process-lock.js +23 -14
  50. package/dist/promises.js +1 -1
  51. package/dist/releases/github.d.ts +82 -137
  52. package/dist/releases/github.js +91 -48
  53. package/dist/releases/socket-btm.d.ts +78 -192
  54. package/dist/releases/socket-btm.js +112 -50
  55. package/dist/signal-exit.js +1 -1
  56. package/dist/spawn.js +11 -4
  57. package/dist/stdio/mask.d.ts +6 -21
  58. package/dist/stdio/mask.js +18 -14
  59. package/dist/themes/context.js +10 -2
  60. package/package.json +3 -2
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
- var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
7
  var __export = (target, all) => {
10
8
  for (var name in all)
@@ -18,14 +16,6 @@ var __copyProps = (to, from, except, desc) => {
18
16
  }
19
17
  return to;
20
18
  };
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
- ));
29
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
20
  var binary_exports = {};
31
21
  __export(binary_exports, {
@@ -37,9 +27,6 @@ __export(binary_exports, {
37
27
  listDlxCache: () => listDlxCache
38
28
  });
39
29
  module.exports = __toCommonJS(binary_exports);
40
- var import_crypto = require("crypto");
41
- var import_os = __toESM(require("os"));
42
- var import_path = __toESM(require("path"));
43
30
  var import_platform = require("../constants/platform");
44
31
  var import_time = require("../constants/time");
45
32
  var import_cache = require("./cache");
@@ -51,16 +38,32 @@ var import_normalize = require("../paths/normalize");
51
38
  var import_socket = require("../paths/socket");
52
39
  var import_process_lock = require("../process-lock");
53
40
  var import_spawn = require("../spawn");
41
+ let _crypto;
42
+ // @__NO_SIDE_EFFECTS__
43
+ function getCrypto() {
44
+ if (_crypto === void 0) {
45
+ _crypto = require("crypto");
46
+ }
47
+ return _crypto;
48
+ }
54
49
  let _fs;
55
50
  // @__NO_SIDE_EFFECTS__
56
51
  function getFs() {
57
52
  if (_fs === void 0) {
58
- _fs = require("node:fs");
53
+ _fs = require("fs");
59
54
  }
60
55
  return _fs;
61
56
  }
57
+ let _path;
58
+ // @__NO_SIDE_EFFECTS__
59
+ function getPath() {
60
+ if (_path === void 0) {
61
+ _path = require("path");
62
+ }
63
+ return _path;
64
+ }
62
65
  function getMetadataPath(cacheEntryPath) {
63
- return import_path.default.join(cacheEntryPath, ".dlx-metadata.json");
66
+ return (/* @__PURE__ */ getPath()).join(cacheEntryPath, ".dlx-metadata.json");
64
67
  }
65
68
  async function isCacheValid(cacheEntryPath, cacheTtl) {
66
69
  const fs = /* @__PURE__ */ getFs();
@@ -85,17 +88,19 @@ async function isCacheValid(cacheEntryPath, cacheTtl) {
85
88
  }
86
89
  }
87
90
  async function downloadBinaryFile(url, destPath, checksum) {
88
- const cacheEntryDir = import_path.default.dirname(destPath);
89
- const lockPath = import_path.default.join(cacheEntryDir, "concurrency.lock");
91
+ const crypto = /* @__PURE__ */ getCrypto();
92
+ const fs = /* @__PURE__ */ getFs();
93
+ const path = /* @__PURE__ */ getPath();
94
+ const cacheEntryDir = path.dirname(destPath);
95
+ const lockPath = path.join(cacheEntryDir, "concurrency.lock");
90
96
  return await import_process_lock.processLock.withLock(
91
97
  lockPath,
92
98
  async () => {
93
- const fs = /* @__PURE__ */ getFs();
94
99
  if (fs.existsSync(destPath)) {
95
100
  const stats = await fs.promises.stat(destPath);
96
101
  if (stats.size > 0) {
97
102
  const fileBuffer2 = await fs.promises.readFile(destPath);
98
- const hasher2 = (0, import_crypto.createHash)("sha256");
103
+ const hasher2 = crypto.createHash("sha256");
99
104
  hasher2.update(fileBuffer2);
100
105
  return hasher2.digest("hex");
101
106
  }
@@ -111,7 +116,7 @@ Check your internet connection or verify the URL is accessible.`,
111
116
  );
112
117
  }
113
118
  const fileBuffer = await fs.promises.readFile(destPath);
114
- const hasher = (0, import_crypto.createHash)("sha256");
119
+ const hasher = crypto.createHash("sha256");
115
120
  hasher.update(fileBuffer);
116
121
  const actualChecksum = hasher.digest("hex");
117
122
  if (checksum && actualChecksum !== checksum) {
@@ -140,8 +145,8 @@ async function writeMetadata(cacheEntryPath, cacheKey, url, binaryName, checksum
140
145
  timestamp: Date.now(),
141
146
  checksum,
142
147
  checksum_algorithm: "sha256",
143
- platform: import_os.default.platform(),
144
- arch: import_os.default.arch(),
148
+ platform: (0, import_platform.getPlatform)(),
149
+ arch: (0, import_platform.getArch)(),
145
150
  size,
146
151
  source: {
147
152
  type: "download",
@@ -154,9 +159,9 @@ async function writeMetadata(cacheEntryPath, cacheKey, url, binaryName, checksum
154
159
  const spec = `${url}:${binaryName}`;
155
160
  await import_manifest.dlxManifest.setBinaryEntry(spec, cacheKey, {
156
161
  checksum,
157
- checksum_algorithm: "sha256",
158
- platform: import_os.default.platform(),
159
- arch: import_os.default.arch(),
162
+ checksum_algorithm: metadata.checksum_algorithm,
163
+ platform: metadata.platform,
164
+ arch: metadata.arch,
160
165
  size,
161
166
  source: {
162
167
  type: "download",
@@ -174,9 +179,10 @@ async function cleanDlxCache(maxAge = import_time.DLX_BINARY_CACHE_TTL) {
174
179
  }
175
180
  let cleaned = 0;
176
181
  const now = Date.now();
182
+ const path = /* @__PURE__ */ getPath();
177
183
  const entries = await fs.promises.readdir(cacheDir);
178
184
  for (const entry of entries) {
179
- const entryPath = import_path.default.join(cacheDir, entry);
185
+ const entryPath = path.join(cacheDir, entry);
180
186
  const metaPath = getMetadataPath(entryPath);
181
187
  try {
182
188
  if (!await (0, import_fs.isDir)(entryPath)) {
@@ -215,14 +221,15 @@ async function dlxBinary(args, options, spawnExtra) {
215
221
  url,
216
222
  yes
217
223
  } = { __proto__: null, ...options };
224
+ const fs = /* @__PURE__ */ getFs();
225
+ const path = /* @__PURE__ */ getPath();
218
226
  const force = yes === true ? true : userForce;
219
227
  const cacheDir = getDlxCachePath();
220
- const binaryName = name || `binary-${process.platform}-${import_os.default.arch()}`;
228
+ const binaryName = name || `binary-${process.platform}-${(0, import_platform.getArch)()}`;
221
229
  const spec = `${url}:${binaryName}`;
222
230
  const cacheKey = (0, import_cache.generateCacheKey)(spec);
223
- const cacheEntryDir = import_path.default.join(cacheDir, cacheKey);
224
- const binaryPath = (0, import_normalize.normalizePath)(import_path.default.join(cacheEntryDir, binaryName));
225
- const fs = /* @__PURE__ */ getFs();
231
+ const cacheEntryDir = path.join(cacheDir, cacheKey);
232
+ const binaryPath = (0, import_normalize.normalizePath)(path.join(cacheEntryDir, binaryName));
226
233
  let downloaded = false;
227
234
  let computedChecksum = checksum;
228
235
  if (!force && fs.existsSync(cacheEntryDir) && await isCacheValid(cacheEntryDir, cacheTtl)) {
@@ -280,7 +287,7 @@ Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`
280
287
  ...spawnOptions,
281
288
  env: {
282
289
  ...spawnOptions?.env,
283
- PATH: `${cacheEntryDir}${import_path.default.delimiter}${process.env["PATH"] || ""}`
290
+ PATH: `${cacheEntryDir}${(/* @__PURE__ */ getPath()).delimiter}${process.env["PATH"] || ""}`
284
291
  },
285
292
  shell: true
286
293
  } : spawnOptions;
@@ -299,13 +306,14 @@ async function downloadBinary(options) {
299
306
  name,
300
307
  url
301
308
  } = { __proto__: null, ...options };
309
+ const fs = /* @__PURE__ */ getFs();
310
+ const path = /* @__PURE__ */ getPath();
302
311
  const cacheDir = getDlxCachePath();
303
- const binaryName = name || `binary-${process.platform}-${import_os.default.arch()}`;
312
+ const binaryName = name || `binary-${process.platform}-${(0, import_platform.getArch)()}`;
304
313
  const spec = `${url}:${binaryName}`;
305
314
  const cacheKey = (0, import_cache.generateCacheKey)(spec);
306
- const cacheEntryDir = import_path.default.join(cacheDir, cacheKey);
307
- const binaryPath = (0, import_normalize.normalizePath)(import_path.default.join(cacheEntryDir, binaryName));
308
- const fs = /* @__PURE__ */ getFs();
315
+ const cacheEntryDir = path.join(cacheDir, cacheKey);
316
+ const binaryPath = (0, import_normalize.normalizePath)(path.join(cacheEntryDir, binaryName));
309
317
  let downloaded = false;
310
318
  if (!force && fs.existsSync(cacheEntryDir) && await isCacheValid(cacheEntryDir, cacheTtl)) {
311
319
  downloaded = false;
@@ -352,12 +360,13 @@ Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`
352
360
  }
353
361
  function executeBinary(binaryPath, args, spawnOptions, spawnExtra) {
354
362
  const needsShell = import_platform.WIN32 && /\.(?:bat|cmd|ps1)$/i.test(binaryPath);
355
- const cacheEntryDir = import_path.default.dirname(binaryPath);
363
+ const path = /* @__PURE__ */ getPath();
364
+ const cacheEntryDir = path.dirname(binaryPath);
356
365
  const finalSpawnOptions = needsShell ? {
357
366
  ...spawnOptions,
358
367
  env: {
359
368
  ...spawnOptions?.env,
360
- PATH: `${cacheEntryDir}${import_path.default.delimiter}${process.env["PATH"] || ""}`
369
+ PATH: `${cacheEntryDir}${path.delimiter}${process.env["PATH"] || ""}`
361
370
  },
362
371
  shell: true
363
372
  } : spawnOptions;
@@ -374,9 +383,10 @@ async function listDlxCache() {
374
383
  }
375
384
  const results = [];
376
385
  const now = Date.now();
386
+ const path = /* @__PURE__ */ getPath();
377
387
  const entries = await fs.promises.readdir(cacheDir);
378
388
  for (const entry of entries) {
379
- const entryPath = import_path.default.join(cacheDir, entry);
389
+ const entryPath = path.join(cacheDir, entry);
380
390
  try {
381
391
  if (!await (0, import_fs.isDir)(entryPath)) {
382
392
  continue;
@@ -392,7 +402,7 @@ async function listDlxCache() {
392
402
  const files = await fs.promises.readdir(entryPath);
393
403
  const binaryFile = files.find((f) => !f.startsWith("."));
394
404
  if (binaryFile) {
395
- const binaryPath = import_path.default.join(entryPath, binaryFile);
405
+ const binaryPath = path.join(entryPath, binaryFile);
396
406
  const binaryStats = await fs.promises.stat(binaryPath);
397
407
  results.push({
398
408
  age: now - (metaObj["timestamp"] || 0),
package/dist/dlx/cache.js CHANGED
@@ -22,9 +22,17 @@ __export(cache_exports, {
22
22
  generateCacheKey: () => generateCacheKey
23
23
  });
24
24
  module.exports = __toCommonJS(cache_exports);
25
- var import_node_crypto = require("node:crypto");
25
+ let _crypto;
26
+ // @__NO_SIDE_EFFECTS__
27
+ function getCrypto() {
28
+ if (_crypto === void 0) {
29
+ _crypto = require("crypto");
30
+ }
31
+ return _crypto;
32
+ }
26
33
  function generateCacheKey(spec) {
27
- return (0, import_node_crypto.createHash)("sha512").update(spec).digest("hex").substring(0, 16);
34
+ const crypto = /* @__PURE__ */ getCrypto();
35
+ return crypto.createHash("sha512").update(spec).digest("hex").substring(0, 16);
28
36
  }
29
37
  // Annotate the CommonJS export names for ESM import in node:
30
38
  0 && (module.exports = {
package/dist/dlx/dir.js CHANGED
@@ -35,7 +35,7 @@ let _fs;
35
35
  // @__NO_SIDE_EFFECTS__
36
36
  function getFs() {
37
37
  if (_fs === void 0) {
38
- _fs = require("node:fs");
38
+ _fs = require("fs");
39
39
  }
40
40
  return _fs;
41
41
  }
@@ -15,7 +15,7 @@ export interface PackageDetails {
15
15
  */
16
16
  export interface BinaryDetails {
17
17
  checksum: string;
18
- checksum_algorithm: 'sha256' | 'sha512';
18
+ checksum_algorithm: ChecksumAlgorithm;
19
19
  platform: string;
20
20
  arch: string;
21
21
  size: number;
@@ -24,6 +24,7 @@ export interface BinaryDetails {
24
24
  url: string;
25
25
  };
26
26
  }
27
+ export type ChecksumAlgorithm = 'sha256' | 'sha512';
27
28
  /**
28
29
  * Unified manifest entry for all cached items (packages and binaries).
29
30
  * Shared fields at root, type-specific fields in details.
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
- var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
7
  var __export = (target, all) => {
10
8
  for (var name in all)
@@ -18,14 +16,6 @@ var __copyProps = (to, from, except, desc) => {
18
16
  }
19
17
  return to;
20
18
  };
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
- ));
29
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
20
  var manifest_exports = {};
31
21
  __export(manifest_exports, {
@@ -35,12 +25,26 @@ __export(manifest_exports, {
35
25
  isPackageEntry: () => isPackageEntry
36
26
  });
37
27
  module.exports = __toCommonJS(manifest_exports);
38
- var import_fs = require("fs");
39
- var import_path = __toESM(require("path"));
40
- var import_fs2 = require("../fs");
28
+ var import_fs = require("../fs");
41
29
  var import_logger = require("../logger");
42
30
  var import_socket = require("../paths/socket");
43
31
  var import_process_lock = require("../process-lock");
32
+ let _fs;
33
+ let _path;
34
+ // @__NO_SIDE_EFFECTS__
35
+ function getFs() {
36
+ if (_fs === void 0) {
37
+ _fs = require("fs");
38
+ }
39
+ return _fs;
40
+ }
41
+ // @__NO_SIDE_EFFECTS__
42
+ function getPath() {
43
+ if (_path === void 0) {
44
+ _path = require("path");
45
+ }
46
+ return _path;
47
+ }
44
48
  const logger = (0, import_logger.getDefaultLogger)();
45
49
  const MANIFEST_FILE_NAME = ".dlx-manifest.json";
46
50
  function isPackageEntry(entry) {
@@ -53,7 +57,7 @@ class DlxManifest {
53
57
  manifestPath;
54
58
  lockPath;
55
59
  constructor(options = {}) {
56
- this.manifestPath = options.manifestPath ?? import_path.default.join((0, import_socket.getSocketDlxDir)(), MANIFEST_FILE_NAME);
60
+ this.manifestPath = options.manifestPath ?? (/* @__PURE__ */ getPath()).join((0, import_socket.getSocketDlxDir)(), MANIFEST_FILE_NAME);
57
61
  this.lockPath = `${this.manifestPath}.lock`;
58
62
  }
59
63
  /**
@@ -61,10 +65,10 @@ class DlxManifest {
61
65
  */
62
66
  readManifest() {
63
67
  try {
64
- if (!(0, import_fs.existsSync)(this.manifestPath)) {
68
+ if (!(/* @__PURE__ */ getFs()).existsSync(this.manifestPath)) {
65
69
  return /* @__PURE__ */ Object.create(null);
66
70
  }
67
- const rawContent = (0, import_fs2.readFileUtf8Sync)(this.manifestPath);
71
+ const rawContent = (0, import_fs.readFileUtf8Sync)(this.manifestPath);
68
72
  const content = (typeof rawContent === "string" ? rawContent : rawContent.toString("utf8")).trim();
69
73
  if (!content) {
70
74
  return /* @__PURE__ */ Object.create(null);
@@ -134,9 +138,9 @@ class DlxManifest {
134
138
  * Write the manifest file atomically.
135
139
  */
136
140
  async writeManifest(data) {
137
- const manifestDir = import_path.default.dirname(this.manifestPath);
141
+ const manifestDir = (/* @__PURE__ */ getPath()).dirname(this.manifestPath);
138
142
  try {
139
- (0, import_fs2.safeMkdirSync)(manifestDir, { recursive: true });
143
+ (0, import_fs.safeMkdirSync)(manifestDir, { recursive: true });
140
144
  } catch (error) {
141
145
  logger.warn(
142
146
  `Failed to create manifest directory: ${error instanceof Error ? error.message : String(error)}`
@@ -145,18 +149,18 @@ class DlxManifest {
145
149
  const content = JSON.stringify(data, null, 2);
146
150
  const tempPath = `${this.manifestPath}.tmp`;
147
151
  try {
148
- (0, import_fs.writeFileSync)(tempPath, content, "utf8");
149
- (0, import_fs.writeFileSync)(this.manifestPath, content, "utf8");
152
+ (/* @__PURE__ */ getFs()).writeFileSync(tempPath, content, "utf8");
153
+ (/* @__PURE__ */ getFs()).writeFileSync(this.manifestPath, content, "utf8");
150
154
  try {
151
- if ((0, import_fs.existsSync)(tempPath)) {
152
- (0, import_fs.unlinkSync)(tempPath);
155
+ if ((/* @__PURE__ */ getFs()).existsSync(tempPath)) {
156
+ (/* @__PURE__ */ getFs()).unlinkSync(tempPath);
153
157
  }
154
158
  } catch {
155
159
  }
156
160
  } catch (error) {
157
161
  try {
158
- if ((0, import_fs.existsSync)(tempPath)) {
159
- (0, import_fs.unlinkSync)(tempPath);
162
+ if ((/* @__PURE__ */ getFs()).existsSync(tempPath)) {
163
+ (/* @__PURE__ */ getFs()).unlinkSync(tempPath);
160
164
  }
161
165
  } catch {
162
166
  }
@@ -171,8 +175,8 @@ class DlxManifest {
171
175
  await import_process_lock.processLock.withLock(this.lockPath, async () => {
172
176
  let data = /* @__PURE__ */ Object.create(null);
173
177
  try {
174
- if ((0, import_fs.existsSync)(this.manifestPath)) {
175
- const content2 = (0, import_fs.readFileSync)(this.manifestPath, "utf8");
178
+ if ((/* @__PURE__ */ getFs()).existsSync(this.manifestPath)) {
179
+ const content2 = (/* @__PURE__ */ getFs()).readFileSync(this.manifestPath, "utf8");
176
180
  if (content2.trim()) {
177
181
  data = JSON.parse(content2);
178
182
  }
@@ -183,9 +187,9 @@ class DlxManifest {
183
187
  );
184
188
  }
185
189
  data[name] = record;
186
- const manifestDir = import_path.default.dirname(this.manifestPath);
190
+ const manifestDir = (/* @__PURE__ */ getPath()).dirname(this.manifestPath);
187
191
  try {
188
- (0, import_fs2.safeMkdirSync)(manifestDir, { recursive: true });
192
+ (0, import_fs.safeMkdirSync)(manifestDir, { recursive: true });
189
193
  } catch (error) {
190
194
  logger.warn(
191
195
  `Failed to create manifest directory: ${error instanceof Error ? error.message : String(error)}`
@@ -194,18 +198,18 @@ class DlxManifest {
194
198
  const content = JSON.stringify(data, null, 2);
195
199
  const tempPath = `${this.manifestPath}.tmp`;
196
200
  try {
197
- (0, import_fs.writeFileSync)(tempPath, content, "utf8");
198
- (0, import_fs.writeFileSync)(this.manifestPath, content, "utf8");
201
+ (/* @__PURE__ */ getFs()).writeFileSync(tempPath, content, "utf8");
202
+ (/* @__PURE__ */ getFs()).writeFileSync(this.manifestPath, content, "utf8");
199
203
  try {
200
- if ((0, import_fs.existsSync)(tempPath)) {
201
- (0, import_fs.unlinkSync)(tempPath);
204
+ if ((/* @__PURE__ */ getFs()).existsSync(tempPath)) {
205
+ (/* @__PURE__ */ getFs()).unlinkSync(tempPath);
202
206
  }
203
207
  } catch {
204
208
  }
205
209
  } catch (error) {
206
210
  try {
207
- if ((0, import_fs.existsSync)(tempPath)) {
208
- (0, import_fs.unlinkSync)(tempPath);
211
+ if ((/* @__PURE__ */ getFs()).existsSync(tempPath)) {
212
+ (/* @__PURE__ */ getFs()).unlinkSync(tempPath);
209
213
  }
210
214
  } catch {
211
215
  }
@@ -219,17 +223,17 @@ class DlxManifest {
219
223
  async clear(name) {
220
224
  await import_process_lock.processLock.withLock(this.lockPath, async () => {
221
225
  try {
222
- if (!(0, import_fs.existsSync)(this.manifestPath)) {
226
+ if (!(/* @__PURE__ */ getFs()).existsSync(this.manifestPath)) {
223
227
  return;
224
228
  }
225
- const content = (0, import_fs.readFileSync)(this.manifestPath, "utf8");
229
+ const content = (/* @__PURE__ */ getFs()).readFileSync(this.manifestPath, "utf8");
226
230
  if (!content.trim()) {
227
231
  return;
228
232
  }
229
233
  const data = JSON.parse(content);
230
234
  delete data[name];
231
235
  const updatedContent = JSON.stringify(data, null, 2);
232
- (0, import_fs.writeFileSync)(this.manifestPath, updatedContent, "utf8");
236
+ (/* @__PURE__ */ getFs()).writeFileSync(this.manifestPath, updatedContent, "utf8");
233
237
  } catch (error) {
234
238
  logger.warn(
235
239
  `Failed to clear cache for ${name}: ${error instanceof Error ? error.message : String(error)}`
@@ -243,8 +247,8 @@ class DlxManifest {
243
247
  async clearAll() {
244
248
  await import_process_lock.processLock.withLock(this.lockPath, async () => {
245
249
  try {
246
- if ((0, import_fs.existsSync)(this.manifestPath)) {
247
- (0, import_fs.unlinkSync)(this.manifestPath);
250
+ if ((/* @__PURE__ */ getFs()).existsSync(this.manifestPath)) {
251
+ (/* @__PURE__ */ getFs()).unlinkSync(this.manifestPath);
248
252
  }
249
253
  } catch (error) {
250
254
  logger.warn(
@@ -268,10 +272,10 @@ class DlxManifest {
268
272
  */
269
273
  getAllPackages() {
270
274
  try {
271
- if (!(0, import_fs.existsSync)(this.manifestPath)) {
275
+ if (!(/* @__PURE__ */ getFs()).existsSync(this.manifestPath)) {
272
276
  return [];
273
277
  }
274
- const rawContent = (0, import_fs2.readFileUtf8Sync)(this.manifestPath);
278
+ const rawContent = (0, import_fs.readFileUtf8Sync)(this.manifestPath);
275
279
  const content = (typeof rawContent === "string" ? rawContent : rawContent.toString("utf8")).trim();
276
280
  if (!content) {
277
281
  return [];
@@ -34,8 +34,6 @@ __export(package_exports, {
34
34
  executePackage: () => executePackage
35
35
  });
36
36
  module.exports = __toCommonJS(package_exports);
37
- var import_node_fs = __toESM(require("node:fs"));
38
- var import_path = __toESM(require("path"));
39
37
  var import_platform = require("../constants/platform");
40
38
  var import_packages = require("../constants/packages");
41
39
  var import_cache = require("./cache");
@@ -48,6 +46,22 @@ var import_normalize = require("../paths/normalize");
48
46
  var import_socket = require("../paths/socket");
49
47
  var import_process_lock = require("../process-lock");
50
48
  var import_spawn = require("../spawn");
49
+ let _fs;
50
+ // @__NO_SIDE_EFFECTS__
51
+ function getFs() {
52
+ if (_fs === void 0) {
53
+ _fs = require("fs");
54
+ }
55
+ return _fs;
56
+ }
57
+ let _path;
58
+ // @__NO_SIDE_EFFECTS__
59
+ function getPath() {
60
+ if (_path === void 0) {
61
+ _path = require("path");
62
+ }
63
+ return _path;
64
+ }
51
65
  const rangeOperatorsRegExp = /[~^><=xX* ]|\|\|/;
52
66
  function parsePackageSpec(spec) {
53
67
  try {
@@ -69,10 +83,12 @@ function parsePackageSpec(spec) {
69
83
  }
70
84
  }
71
85
  async function ensurePackageInstalled(packageName, packageSpec, force) {
86
+ const fs = /* @__PURE__ */ getFs();
87
+ const path = /* @__PURE__ */ getPath();
72
88
  const cacheKey = (0, import_cache.generateCacheKey)(packageSpec);
73
- const packageDir = (0, import_normalize.normalizePath)(import_path.default.join((0, import_socket.getSocketDlxDir)(), cacheKey));
89
+ const packageDir = (0, import_normalize.normalizePath)(path.join((0, import_socket.getSocketDlxDir)(), cacheKey));
74
90
  const installedDir = (0, import_normalize.normalizePath)(
75
- import_path.default.join(packageDir, "node_modules", packageName)
91
+ path.join(packageDir, "node_modules", packageName)
76
92
  );
77
93
  try {
78
94
  await (0, import_fs.safeMkdir)(packageDir);
@@ -96,13 +112,13 @@ Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`
96
112
  cause: e
97
113
  });
98
114
  }
99
- const lockPath = import_path.default.join(packageDir, "concurrency.lock");
115
+ const lockPath = path.join(packageDir, "concurrency.lock");
100
116
  return await import_process_lock.processLock.withLock(
101
117
  lockPath,
102
118
  async () => {
103
- if (!force && import_node_fs.default.existsSync(installedDir)) {
104
- const pkgJsonPath = import_path.default.join(installedDir, "package.json");
105
- if (import_node_fs.default.existsSync(pkgJsonPath)) {
119
+ if (!force && fs.existsSync(installedDir)) {
120
+ const pkgJsonPath = path.join(installedDir, "package.json");
121
+ if (fs.existsSync(pkgJsonPath)) {
106
122
  return { installed: false, packageDir };
107
123
  }
108
124
  }
@@ -110,11 +126,11 @@ Ensure the filesystem is writable or set SOCKET_DLX_DIR to a writable location.`
110
126
  try {
111
127
  await import_pacote.default.extract(packageSpec, installedDir, {
112
128
  // Use consistent pacote cache path (respects npm cache locations when available).
113
- cache: pacoteCachePath || import_path.default.join(packageDir, ".cache")
129
+ cache: pacoteCachePath || path.join(packageDir, ".cache")
114
130
  });
115
131
  const arb = new import_arborist.default({
116
132
  path: installedDir,
117
- cache: pacoteCachePath || import_path.default.join(packageDir, ".cache"),
133
+ cache: pacoteCachePath || path.join(packageDir, ".cache"),
118
134
  // Skip devDependencies (production-only like npx).
119
135
  omit: ["dev"],
120
136
  // Security: Skip install/preinstall/postinstall scripts to prevent arbitrary code execution.
@@ -167,20 +183,22 @@ function resolveBinaryPath(basePath) {
167
183
  if (!import_platform.WIN32) {
168
184
  return basePath;
169
185
  }
186
+ const fs = /* @__PURE__ */ getFs();
170
187
  const extensions = [".cmd", ".bat", ".ps1", ".exe", ""];
171
188
  for (const ext of extensions) {
172
189
  const testPath = basePath + ext;
173
- if (import_node_fs.default.existsSync(testPath)) {
190
+ if (fs.existsSync(testPath)) {
174
191
  return testPath;
175
192
  }
176
193
  }
177
194
  return basePath;
178
195
  }
179
196
  function findBinaryPath(packageDir, packageName, binaryName) {
197
+ const path = /* @__PURE__ */ getPath();
180
198
  const installedDir = (0, import_normalize.normalizePath)(
181
- import_path.default.join(packageDir, "node_modules", packageName)
199
+ path.join(packageDir, "node_modules", packageName)
182
200
  );
183
- const pkgJsonPath = import_path.default.join(installedDir, "package.json");
201
+ const pkgJsonPath = path.join(installedDir, "package.json");
184
202
  const pkgJson = (0, import_fs.readJsonSync)(pkgJsonPath);
185
203
  const bin = pkgJson["bin"];
186
204
  let binName;
@@ -226,7 +244,7 @@ function findBinaryPath(packageDir, packageName, binaryName) {
226
244
  if (!binPath) {
227
245
  throw new Error(`No binary found for package "${packageName}"`);
228
246
  }
229
- const rawPath = (0, import_normalize.normalizePath)(import_path.default.join(installedDir, binPath));
247
+ const rawPath = (0, import_normalize.normalizePath)(path.join(installedDir, binPath));
230
248
  return resolveBinaryPath(rawPath);
231
249
  }
232
250
  async function dlxPackage(args, options, spawnExtra) {
@@ -246,10 +264,12 @@ function makePackageBinsExecutable(packageDir, packageName) {
246
264
  if (import_platform.WIN32) {
247
265
  return;
248
266
  }
267
+ const fs = /* @__PURE__ */ getFs();
268
+ const path = /* @__PURE__ */ getPath();
249
269
  const installedDir = (0, import_normalize.normalizePath)(
250
- import_path.default.join(packageDir, "node_modules", packageName)
270
+ path.join(packageDir, "node_modules", packageName)
251
271
  );
252
- const pkgJsonPath = import_path.default.join(installedDir, "package.json");
272
+ const pkgJsonPath = path.join(installedDir, "package.json");
253
273
  try {
254
274
  const pkgJson = (0, import_fs.readJsonSync)(pkgJsonPath);
255
275
  const bin = pkgJson["bin"];
@@ -264,10 +284,10 @@ function makePackageBinsExecutable(packageDir, packageName) {
264
284
  binPaths.push(...Object.values(binObj));
265
285
  }
266
286
  for (const binPath of binPaths) {
267
- const fullPath = (0, import_normalize.normalizePath)(import_path.default.join(installedDir, binPath));
268
- if (import_node_fs.default.existsSync(fullPath)) {
287
+ const fullPath = (0, import_normalize.normalizePath)(path.join(installedDir, binPath));
288
+ if (fs.existsSync(fullPath)) {
269
289
  try {
270
- import_node_fs.default.chmodSync(fullPath, 493);
290
+ fs.chmodSync(fullPath, 493);
271
291
  } catch {
272
292
  }
273
293
  }
@@ -34,7 +34,7 @@ let _fs;
34
34
  // @__NO_SIDE_EFFECTS__
35
35
  function getFs() {
36
36
  if (_fs === void 0) {
37
- _fs = require("node:fs");
37
+ _fs = require("fs");
38
38
  }
39
39
  return _fs;
40
40
  }
package/dist/dlx/paths.js CHANGED
@@ -32,7 +32,7 @@ let _path;
32
32
  // @__NO_SIDE_EFFECTS__
33
33
  function getPath() {
34
34
  if (_path === void 0) {
35
- _path = require("node:path");
35
+ _path = require("path");
36
36
  }
37
37
  return _path;
38
38
  }
@@ -28,9 +28,17 @@ __export(rewire_exports, {
28
28
  withEnvSync: () => withEnvSync
29
29
  });
30
30
  module.exports = __toCommonJS(rewire_exports);
31
- var import_async_hooks = require("async_hooks");
32
31
  var import_helpers = require("./helpers");
33
- const isolatedOverridesStorage = new import_async_hooks.AsyncLocalStorage();
32
+ let _async_hooks;
33
+ // @__NO_SIDE_EFFECTS__
34
+ function getAsyncHooks() {
35
+ if (_async_hooks === void 0) {
36
+ _async_hooks = require("async_hooks");
37
+ }
38
+ return _async_hooks;
39
+ }
40
+ const { AsyncLocalStorage } = /* @__PURE__ */ getAsyncHooks();
41
+ const isolatedOverridesStorage = new AsyncLocalStorage();
34
42
  const sharedOverridesSymbol = Symbol.for(
35
43
  "@socketsecurity/lib/env/rewire/test-overrides"
36
44
  );