@socketsecurity/lib 5.2.1 → 5.3.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [5.3.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.3.0) - 2026-01-07
9
+
10
+ ### Added
11
+
12
+ - **releases/socket-btm**: Exported helper functions for external use
13
+ - `detectLibc()`: Detect musl vs glibc on Linux systems
14
+ - `getBinaryAssetName()`: Get GitHub asset name for platform/arch
15
+ - `getBinaryName()`: Get binary filename with platform-appropriate extension
16
+ - `getPlatformArch()`: Get platform-arch identifier for directory structure
17
+
18
+ - **releases/github**: Exported `getAuthHeaders()` for GitHub API authentication
19
+ - Returns headers with `Accept`, `X-GitHub-Api-Version`, and optional `Authorization`
20
+ - Checks `GH_TOKEN` and `GITHUB_TOKEN` environment variables
21
+
8
22
  ## [5.2.1](https://github.com/SocketDev/socket-lib/releases/tag/v5.2.1) - 2026-01-06
9
23
 
10
24
  ### Fixed
package/dist/bin.d.ts CHANGED
@@ -1,9 +1,3 @@
1
- // ============================================================================
2
- // Private Helper Functions
3
- // ============================================================================
4
- // ============================================================================
5
- // Types and Interfaces
6
- // ============================================================================
7
1
  /**
8
2
  * Options for the which function.
9
3
  */
@@ -21,9 +15,6 @@ export interface WhichOptions {
21
15
  /** Current working directory for resolving relative paths. */
22
16
  cwd?: string | undefined;
23
17
  }
24
- // ============================================================================
25
- // Public API (alphabetically sorted)
26
- // ============================================================================
27
18
  /**
28
19
  * Execute a binary with the given arguments.
29
20
  */
package/dist/bin.js CHANGED
@@ -42,8 +42,6 @@ __export(bin_exports, {
42
42
  whichSync: () => whichSync
43
43
  });
44
44
  module.exports = __toCommonJS(bin_exports);
45
- var import_node_fs = __toESM(require("node:fs"));
46
- var import_node_path = __toESM(require("node:path"));
47
45
  var import_home = require("./env/home");
48
46
  var import_windows = require("./env/windows");
49
47
  var import_xdg = require("./env/xdg");
@@ -52,6 +50,22 @@ var import_which = __toESM(require("./external/which"));
52
50
  var import_fs = require("./fs");
53
51
  var import_normalize = require("./paths/normalize");
54
52
  var import_spawn = require("./spawn");
53
+ let _fs;
54
+ // @__NO_SIDE_EFFECTS__
55
+ function getFs() {
56
+ if (_fs === void 0) {
57
+ _fs = require("fs");
58
+ }
59
+ return _fs;
60
+ }
61
+ let _path;
62
+ // @__NO_SIDE_EFFECTS__
63
+ function getPath() {
64
+ if (_path === void 0) {
65
+ _path = require("path");
66
+ }
67
+ return _path;
68
+ }
55
69
  // @__NO_SIDE_EFFECTS__
56
70
  async function execBin(binPath, args, options) {
57
71
  const resolvedPath = (0, import_normalize.isPath)(binPath) ? /* @__PURE__ */ resolveRealBinSync(binPath) : await whichReal(binPath);
@@ -77,19 +91,21 @@ To resolve:
77
91
  });
78
92
  }
79
93
  function findRealBin(binName, commonPaths = []) {
94
+ const fs = /* @__PURE__ */ getFs();
95
+ const path = /* @__PURE__ */ getPath();
80
96
  for (const binPath2 of commonPaths) {
81
- if (import_node_fs.default.existsSync(binPath2)) {
97
+ if (fs.existsSync(binPath2)) {
82
98
  return binPath2;
83
99
  }
84
100
  }
85
101
  const binPath = import_which.default.sync(binName, { nothrow: true });
86
102
  if (binPath) {
87
- const binDir = import_node_path.default.dirname(binPath);
103
+ const binDir = path.dirname(binPath);
88
104
  if (isShadowBinPath(binDir)) {
89
105
  const allPaths = import_which.default.sync(binName, { all: true, nothrow: true }) || [];
90
106
  const pathsArray = Array.isArray(allPaths) ? allPaths : typeof allPaths === "string" ? [allPaths] : [];
91
107
  for (const altPath of pathsArray) {
92
- const altDir = import_node_path.default.dirname(altPath);
108
+ const altDir = path.dirname(altPath);
93
109
  if (!isShadowBinPath(altDir)) {
94
110
  return altPath;
95
111
  }
@@ -100,49 +116,53 @@ function findRealBin(binName, commonPaths = []) {
100
116
  return void 0;
101
117
  }
102
118
  function findRealNpm() {
103
- const nodeDir = import_node_path.default.dirname(process.execPath);
104
- const npmInNodeDir = import_node_path.default.join(nodeDir, "npm");
105
- if (import_node_fs.default.existsSync(npmInNodeDir)) {
119
+ const fs = /* @__PURE__ */ getFs();
120
+ const path = /* @__PURE__ */ getPath();
121
+ const nodeDir = path.dirname(process.execPath);
122
+ const npmInNodeDir = path.join(nodeDir, "npm");
123
+ if (fs.existsSync(npmInNodeDir)) {
106
124
  return npmInNodeDir;
107
125
  }
108
126
  const commonPaths = ["/usr/local/bin/npm", "/usr/bin/npm"];
109
127
  const result = findRealBin("npm", commonPaths);
110
- if (result && import_node_fs.default.existsSync(result)) {
128
+ if (result && fs.existsSync(result)) {
111
129
  return result;
112
130
  }
113
131
  const npmPath = whichRealSync("npm", { nothrow: true });
114
- if (npmPath && typeof npmPath === "string" && import_node_fs.default.existsSync(npmPath)) {
132
+ if (npmPath && typeof npmPath === "string" && fs.existsSync(npmPath)) {
115
133
  return npmPath;
116
134
  }
117
135
  return "npm";
118
136
  }
119
137
  function findRealPnpm() {
138
+ const path = /* @__PURE__ */ getPath();
120
139
  const commonPaths = import_platform.WIN32 ? [
121
140
  // Windows common paths.
122
- import_node_path.default.join((0, import_windows.getAppdata)(), "npm", "pnpm.cmd"),
123
- import_node_path.default.join((0, import_windows.getAppdata)(), "npm", "pnpm"),
124
- import_node_path.default.join((0, import_windows.getLocalappdata)(), "pnpm", "pnpm.cmd"),
125
- import_node_path.default.join((0, import_windows.getLocalappdata)(), "pnpm", "pnpm"),
141
+ path.join((0, import_windows.getAppdata)(), "npm", "pnpm.cmd"),
142
+ path.join((0, import_windows.getAppdata)(), "npm", "pnpm"),
143
+ path.join((0, import_windows.getLocalappdata)(), "pnpm", "pnpm.cmd"),
144
+ path.join((0, import_windows.getLocalappdata)(), "pnpm", "pnpm"),
126
145
  "C:\\Program Files\\nodejs\\pnpm.cmd",
127
146
  "C:\\Program Files\\nodejs\\pnpm"
128
147
  ].filter(Boolean) : [
129
148
  // Unix common paths.
130
149
  "/usr/local/bin/pnpm",
131
150
  "/usr/bin/pnpm",
132
- import_node_path.default.join(
151
+ path.join(
133
152
  (0, import_xdg.getXdgDataHome)() || `${(0, import_home.getHome)()}/.local/share`,
134
153
  "pnpm/pnpm"
135
154
  ),
136
- import_node_path.default.join((0, import_home.getHome)(), ".pnpm/pnpm")
155
+ path.join((0, import_home.getHome)(), ".pnpm/pnpm")
137
156
  ].filter(Boolean);
138
157
  return findRealBin("pnpm", commonPaths) ?? "";
139
158
  }
140
159
  function findRealYarn() {
160
+ const path = /* @__PURE__ */ getPath();
141
161
  const commonPaths = [
142
162
  "/usr/local/bin/yarn",
143
163
  "/usr/bin/yarn",
144
- import_node_path.default.join((0, import_home.getHome)(), ".yarn/bin/yarn"),
145
- import_node_path.default.join(
164
+ path.join((0, import_home.getHome)(), ".yarn/bin/yarn"),
165
+ path.join(
146
166
  (0, import_home.getHome)(),
147
167
  ".config/yarn/global/node_modules/.bin/yarn"
148
168
  )
@@ -158,7 +178,9 @@ function isShadowBinPath(dirPath) {
158
178
  }
159
179
  // @__NO_SIDE_EFFECTS__
160
180
  function resolveRealBinSync(binPath) {
161
- if (!import_node_path.default.isAbsolute(binPath)) {
181
+ const fs = /* @__PURE__ */ getFs();
182
+ const path = /* @__PURE__ */ getPath();
183
+ if (!path.isAbsolute(binPath)) {
162
184
  try {
163
185
  const resolved = whichRealSync(binPath);
164
186
  if (resolved) {
@@ -171,17 +193,17 @@ function resolveRealBinSync(binPath) {
171
193
  if (binPath === ".") {
172
194
  return binPath;
173
195
  }
174
- const ext = import_node_path.default.extname(binPath);
196
+ const ext = path.extname(binPath);
175
197
  const extLowered = ext.toLowerCase();
176
- const basename = import_node_path.default.basename(binPath, ext);
198
+ const basename = path.basename(binPath, ext);
177
199
  const voltaIndex = basename === "node" ? -1 : /(?<=\/)\.volta\//i.exec(binPath)?.index ?? -1;
178
200
  if (voltaIndex !== -1) {
179
201
  const voltaPath = binPath.slice(0, voltaIndex);
180
- const voltaToolsPath = import_node_path.default.join(voltaPath, "tools");
181
- const voltaImagePath = import_node_path.default.join(voltaToolsPath, "image");
182
- const voltaUserPath = import_node_path.default.join(voltaToolsPath, "user");
202
+ const voltaToolsPath = path.join(voltaPath, "tools");
203
+ const voltaImagePath = path.join(voltaToolsPath, "image");
204
+ const voltaUserPath = path.join(voltaToolsPath, "user");
183
205
  const voltaPlatform = (0, import_fs.readJsonSync)(
184
- import_node_path.default.join(voltaUserPath, "platform.json"),
206
+ path.join(voltaUserPath, "platform.json"),
185
207
  { throws: false }
186
208
  );
187
209
  const voltaNodeVersion = voltaPlatform?.node?.runtime;
@@ -190,35 +212,35 @@ function resolveRealBinSync(binPath) {
190
212
  if (basename === "npm" || basename === "npx") {
191
213
  if (voltaNpmVersion) {
192
214
  const relCliPath = `bin/${basename}-cli.js`;
193
- voltaBinPath = import_node_path.default.join(
215
+ voltaBinPath = path.join(
194
216
  voltaImagePath,
195
217
  `npm/${voltaNpmVersion}/${relCliPath}`
196
218
  );
197
- if (voltaNodeVersion && !import_node_fs.default.existsSync(voltaBinPath)) {
198
- voltaBinPath = import_node_path.default.join(
219
+ if (voltaNodeVersion && !fs.existsSync(voltaBinPath)) {
220
+ voltaBinPath = path.join(
199
221
  voltaImagePath,
200
222
  `node/${voltaNodeVersion}/lib/node_modules/npm/${relCliPath}`
201
223
  );
202
- if (!import_node_fs.default.existsSync(voltaBinPath)) {
224
+ if (!fs.existsSync(voltaBinPath)) {
203
225
  voltaBinPath = "";
204
226
  }
205
227
  }
206
228
  }
207
229
  } else {
208
- const voltaUserBinPath = import_node_path.default.join(voltaUserPath, "bin");
230
+ const voltaUserBinPath = path.join(voltaUserPath, "bin");
209
231
  const binInfo = (0, import_fs.readJsonSync)(
210
- import_node_path.default.join(voltaUserBinPath, `${basename}.json`),
232
+ path.join(voltaUserBinPath, `${basename}.json`),
211
233
  { throws: false }
212
234
  );
213
235
  const binPackage = binInfo?.package;
214
236
  if (binPackage) {
215
- voltaBinPath = import_node_path.default.join(
237
+ voltaBinPath = path.join(
216
238
  voltaImagePath,
217
239
  `packages/${binPackage}/bin/${basename}`
218
240
  );
219
- if (!import_node_fs.default.existsSync(voltaBinPath)) {
241
+ if (!fs.existsSync(voltaBinPath)) {
220
242
  voltaBinPath = `${voltaBinPath}.cmd`;
221
- if (!import_node_fs.default.existsSync(voltaBinPath)) {
243
+ if (!fs.existsSync(voltaBinPath)) {
222
244
  voltaBinPath = "";
223
245
  }
224
246
  }
@@ -226,7 +248,7 @@ function resolveRealBinSync(binPath) {
226
248
  }
227
249
  if (voltaBinPath) {
228
250
  try {
229
- return (0, import_normalize.normalizePath)(import_node_fs.default.realpathSync.native(voltaBinPath));
251
+ return (0, import_normalize.normalizePath)(fs.realpathSync.native(voltaBinPath));
230
252
  } catch {
231
253
  }
232
254
  return voltaBinPath;
@@ -237,13 +259,13 @@ function resolveRealBinSync(binPath) {
237
259
  const isNpmOrNpx = basename === "npm" || basename === "npx";
238
260
  const isPnpmOrYarn = basename === "pnpm" || basename === "yarn";
239
261
  if (hasKnownExt && isNpmOrNpx) {
240
- const quickPath = import_node_path.default.join(
241
- import_node_path.default.dirname(binPath),
262
+ const quickPath = path.join(
263
+ path.dirname(binPath),
242
264
  `node_modules/npm/bin/${basename}-cli.js`
243
265
  );
244
- if (import_node_fs.default.existsSync(quickPath)) {
266
+ if (fs.existsSync(quickPath)) {
245
267
  try {
246
- return import_node_fs.default.realpathSync.native(quickPath);
268
+ return fs.realpathSync.native(quickPath);
247
269
  } catch {
248
270
  }
249
271
  return quickPath;
@@ -253,8 +275,8 @@ function resolveRealBinSync(binPath) {
253
275
  if (hasKnownExt && // Only parse shell scripts and batch files, not actual executables.
254
276
  // .exe files are already executables and don't need path resolution from wrapper scripts.
255
277
  extLowered !== ".exe" && // Check if file exists before attempting to read it to avoid ENOENT errors.
256
- import_node_fs.default.existsSync(binPath)) {
257
- const source = import_node_fs.default.readFileSync(binPath, "utf8");
278
+ fs.existsSync(binPath)) {
279
+ const source = fs.readFileSync(binPath, "utf8");
258
280
  if (isNpmOrNpx) {
259
281
  if (extLowered === ".cmd") {
260
282
  relPath = basename === "npm" ? /(?<="NPM_CLI_JS=%~dp0\\).*(?=")/.exec(source)?.[0] || "" : /(?<="NPX_CLI_JS=%~dp0\\).*(?=")/.exec(source)?.[0] || "";
@@ -301,7 +323,7 @@ function resolveRealBinSync(binPath) {
301
323
  relPath = /(?<="\$basedir\/).*(?=" $args\n)/.exec(source)?.[0] || "";
302
324
  }
303
325
  if (relPath) {
304
- binPath = (0, import_normalize.normalizePath)(import_node_path.default.resolve(import_node_path.default.dirname(binPath), relPath));
326
+ binPath = (0, import_normalize.normalizePath)(path.resolve(path.dirname(binPath), relPath));
305
327
  }
306
328
  }
307
329
  } else {
@@ -313,10 +335,10 @@ function resolveRealBinSync(binPath) {
313
335
  if (binIndex !== -1) {
314
336
  const baseBinPath = binPath.slice(0, binIndex + "/.bin/pnpm".length);
315
337
  try {
316
- const stats = import_node_fs.default.statSync(baseBinPath);
338
+ const stats = fs.statSync(baseBinPath);
317
339
  if (stats.isFile()) {
318
340
  binPath = (0, import_normalize.normalizePath)(baseBinPath);
319
- hasNoExt = !import_node_path.default.extname(binPath);
341
+ hasNoExt = !path.extname(binPath);
320
342
  }
321
343
  } catch {
322
344
  }
@@ -324,8 +346,8 @@ function resolveRealBinSync(binPath) {
324
346
  }
325
347
  if (hasNoExt && (isPnpmOrYarn || isNpmOrNpx) && // For extensionless files (Unix shell scripts), verify existence before reading.
326
348
  // This prevents ENOENT errors when the bin path doesn't exist.
327
- import_node_fs.default.existsSync(binPath)) {
328
- const source = import_node_fs.default.readFileSync(binPath, "utf8");
349
+ fs.existsSync(binPath)) {
350
+ const source = fs.readFileSync(binPath, "utf8");
329
351
  let relPath = "";
330
352
  if (isPnpmOrYarn) {
331
353
  relPath = /(?<="\$basedir\/)\.tools\/[^"]+(?="\s+"\$@")/.exec(source)?.[0] || "";
@@ -347,12 +369,12 @@ function resolveRealBinSync(binPath) {
347
369
  relPath = basename === "npm" ? /(?<=NPM_CLI_JS="\$CLI_BASEDIR\/).*(?=")/.exec(source)?.[0] || "" : /(?<=NPX_CLI_JS="\$CLI_BASEDIR\/).*(?=")/.exec(source)?.[0] || "";
348
370
  }
349
371
  if (relPath) {
350
- binPath = (0, import_normalize.normalizePath)(import_node_path.default.resolve(import_node_path.default.dirname(binPath), relPath));
372
+ binPath = (0, import_normalize.normalizePath)(path.resolve(path.dirname(binPath), relPath));
351
373
  }
352
374
  }
353
375
  }
354
376
  try {
355
- const realPath = import_node_fs.default.realpathSync.native(binPath);
377
+ const realPath = fs.realpathSync.native(binPath);
356
378
  return (0, import_normalize.normalizePath)(realPath);
357
379
  } catch {
358
380
  }
@@ -70,8 +70,8 @@ const NPM_BIN_PATH = /* @__PURE__ */ (() => {
70
70
  })();
71
71
  const NPM_REAL_EXEC_PATH = /* @__PURE__ */ (() => {
72
72
  try {
73
- const { existsSync } = require("node:fs");
74
- const path = require("node:path");
73
+ const { existsSync } = require("fs");
74
+ const path = require("path");
75
75
  const npmBin = import_which.default.sync("npm", { nothrow: true });
76
76
  if (!npmBin) {
77
77
  return void 0;
@@ -1,3 +1,24 @@
1
+ /**
2
+ * CPU architecture type.
3
+ */
4
+ export type Arch = NodeJS.Architecture;
5
+ /**
6
+ * Linux libc variant.
7
+ */
8
+ export type Libc = 'glibc' | 'musl';
9
+ /**
10
+ * Operating system platform type.
11
+ */
12
+ export type Platform = NodeJS.Platform;
13
+ /**
14
+ * Get the current CPU architecture (memoized).
15
+ */
16
+ export declare function getArch(): Arch;
17
+ /**
18
+ * Get the current platform (memoized).
19
+ */
20
+ export declare function getPlatform(): Platform;
21
+ // Platform detection (memoized at module load).
1
22
  export declare const DARWIN: boolean;
2
23
  export declare const WIN32: boolean;
3
24
  // File permission modes.
@@ -23,13 +23,35 @@ __export(platform_exports, {
23
23
  S_IXGRP: () => S_IXGRP,
24
24
  S_IXOTH: () => S_IXOTH,
25
25
  S_IXUSR: () => S_IXUSR,
26
- WIN32: () => WIN32
26
+ WIN32: () => WIN32,
27
+ getArch: () => getArch,
28
+ getPlatform: () => getPlatform
27
29
  });
28
30
  module.exports = __toCommonJS(platform_exports);
29
- var import_os = require("os");
30
- const _platform = (0, import_os.platform)();
31
- const DARWIN = _platform === "darwin";
32
- const WIN32 = _platform === "win32";
31
+ let _os;
32
+ // @__NO_SIDE_EFFECTS__
33
+ function getOs() {
34
+ if (_os === void 0) {
35
+ _os = require("os");
36
+ }
37
+ return _os;
38
+ }
39
+ let _arch;
40
+ function getArch() {
41
+ if (_arch === void 0) {
42
+ _arch = (/* @__PURE__ */ getOs()).arch();
43
+ }
44
+ return _arch;
45
+ }
46
+ let _platform;
47
+ function getPlatform() {
48
+ if (_platform === void 0) {
49
+ _platform = (/* @__PURE__ */ getOs()).platform();
50
+ }
51
+ return _platform;
52
+ }
53
+ const DARWIN = getPlatform() === "darwin";
54
+ const WIN32 = getPlatform() === "win32";
33
55
  const S_IXUSR = 64;
34
56
  const S_IXGRP = 8;
35
57
  const S_IXOTH = 1;
@@ -39,5 +61,7 @@ const S_IXOTH = 1;
39
61
  S_IXGRP,
40
62
  S_IXOTH,
41
63
  S_IXUSR,
42
- WIN32
64
+ WIN32,
65
+ getArch,
66
+ getPlatform
43
67
  });
@@ -30,7 +30,7 @@ let _path;
30
30
  // @__NO_SIDE_EFFECTS__
31
31
  function getPath() {
32
32
  if (_path === void 0) {
33
- _path = require("node:path");
33
+ _path = require("path");
34
34
  }
35
35
  return _path;
36
36
  }
package/dist/debug.js CHANGED
@@ -72,7 +72,7 @@ let _util;
72
72
  // @__NO_SIDE_EFFECTS__
73
73
  function getUtil() {
74
74
  if (_util === void 0) {
75
- _util = require("node:util");
75
+ _util = require("util");
76
76
  }
77
77
  return _util;
78
78
  }
@@ -1,5 +1,5 @@
1
- import type { SpawnExtra, SpawnOptions } from '../spawn';
2
1
  import { spawn } from '../spawn';
2
+ import type { SpawnExtra, SpawnOptions } from '../spawn';
3
3
  export interface DlxBinaryOptions {
4
4
  /**
5
5
  * URL to download the binary from.
@@ -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),