@socketsecurity/lib 3.5.0 → 4.0.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 (102) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +8 -8
  3. package/dist/agent.js +12 -25
  4. package/dist/bin.d.ts +97 -40
  5. package/dist/bin.js +133 -138
  6. package/dist/cacache.d.ts +5 -2
  7. package/dist/cacache.js +29 -18
  8. package/dist/cache-with-ttl.js +1 -1
  9. package/dist/constants/agents.d.ts +0 -4
  10. package/dist/constants/agents.js +13 -4
  11. package/dist/constants/node.d.ts +1 -0
  12. package/dist/constants/node.js +2 -5
  13. package/dist/constants/packages.js +23 -11
  14. package/dist/constants/process.d.ts +1 -1
  15. package/dist/constants/process.js +2 -2
  16. package/dist/debug.js +3 -3
  17. package/dist/dlx-binary.js +10 -18
  18. package/dist/dlx-manifest.js +2 -2
  19. package/dist/dlx-package.js +22 -62
  20. package/dist/dlx.js +14 -14
  21. package/dist/effects/text-shimmer.js +1 -1
  22. package/dist/env/ci.js +2 -2
  23. package/dist/env/debug.js +1 -1
  24. package/dist/env/github.js +1 -1
  25. package/dist/env/home.js +1 -1
  26. package/dist/env/locale.js +1 -1
  27. package/dist/env/node-auth-token.js +1 -1
  28. package/dist/env/node-env.js +1 -1
  29. package/dist/env/npm.js +1 -1
  30. package/dist/env/package-manager.js +1 -1
  31. package/dist/env/path.js +1 -1
  32. package/dist/env/pre-commit.js +2 -2
  33. package/dist/env/rewire.d.ts +7 -7
  34. package/dist/env/rewire.js +1 -1
  35. package/dist/env/shell.js +1 -1
  36. package/dist/env/socket-cli-shadow.js +2 -2
  37. package/dist/env/socket-cli.js +2 -2
  38. package/dist/env/socket.js +2 -2
  39. package/dist/env/temp-dir.js +1 -1
  40. package/dist/env/term.js +1 -1
  41. package/dist/env/test.js +3 -3
  42. package/dist/env/windows.js +1 -1
  43. package/dist/env/xdg.js +1 -1
  44. package/dist/fs.js +20 -25
  45. package/dist/git.d.ts +6 -6
  46. package/dist/git.js +11 -14
  47. package/dist/github.js +2 -2
  48. package/dist/globs.js +16 -29
  49. package/dist/ipc.d.ts +4 -4
  50. package/dist/ipc.js +3 -3
  51. package/dist/logger.d.ts +0 -25
  52. package/dist/logger.js +0 -26
  53. package/dist/objects.js +1 -1
  54. package/dist/package-default-node-range.js +13 -3
  55. package/dist/package-extensions.d.ts +2 -1
  56. package/dist/package-extensions.js +12 -2
  57. package/dist/packages/editable.d.ts +0 -3
  58. package/dist/packages/editable.js +34 -24
  59. package/dist/packages/exports.js +1 -1
  60. package/dist/packages/isolation.js +33 -33
  61. package/dist/packages/licenses.js +20 -34
  62. package/dist/packages/manifest.js +21 -36
  63. package/dist/packages/normalize.js +20 -52
  64. package/dist/packages/operations.js +39 -103
  65. package/dist/packages/provenance.js +15 -5
  66. package/dist/packages/specs.js +13 -12
  67. package/dist/packages/validation.js +12 -10
  68. package/dist/packages.d.ts +2 -2
  69. package/dist/packages.js +3 -3
  70. package/dist/paths/dirnames.d.ts +13 -0
  71. package/dist/paths/dirnames.js +50 -0
  72. package/dist/paths/exts.d.ts +18 -0
  73. package/dist/paths/exts.js +68 -0
  74. package/dist/paths/filenames.d.ts +16 -0
  75. package/dist/paths/filenames.js +62 -0
  76. package/dist/paths/globs.d.ts +10 -0
  77. package/dist/{argv/quote.js → paths/globs.js} +21 -19
  78. package/dist/{path.d.ts → paths/normalize.d.ts} +41 -0
  79. package/dist/{path.js → paths/normalize.js} +18 -5
  80. package/dist/{packages/paths.js → paths/packages.js} +8 -8
  81. package/dist/paths/rewire.d.ts +1 -1
  82. package/dist/{paths.js → paths/socket.js} +31 -67
  83. package/dist/promises.js +2 -2
  84. package/dist/sea.js +2 -2
  85. package/dist/shadow.js +3 -3
  86. package/dist/sorts.js +12 -2
  87. package/dist/spawn.d.ts +15 -12
  88. package/dist/spawn.js +43 -31
  89. package/dist/spinner.d.ts +2 -6
  90. package/dist/spinner.js +9 -41
  91. package/dist/stdio/prompts.d.ts +8 -10
  92. package/dist/stdio/prompts.js +15 -13
  93. package/dist/streams.d.ts +0 -4
  94. package/dist/streams.js +3 -12
  95. package/dist/temporary-executor.js +4 -4
  96. package/dist/versions.js +31 -28
  97. package/package.json +28 -29
  98. package/dist/argv/quote.d.ts +0 -49
  99. package/dist/constants/paths.d.ts +0 -51
  100. package/dist/constants/paths.js +0 -152
  101. /package/dist/{packages/paths.d.ts → paths/packages.d.ts} +0 -0
  102. /package/dist/{paths.d.ts → paths/socket.d.ts} +0 -0
package/dist/bin.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
+ var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
6
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
9
  var __export = (target, all) => {
8
10
  for (var name in all)
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
16
18
  }
17
19
  return to;
18
20
  };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
  var bin_exports = {};
21
31
  __export(bin_exports, {
@@ -25,47 +35,26 @@ __export(bin_exports, {
25
35
  findRealPnpm: () => findRealPnpm,
26
36
  findRealYarn: () => findRealYarn,
27
37
  isShadowBinPath: () => isShadowBinPath,
28
- resolveBinPathSync: () => resolveBinPathSync,
38
+ resolveRealBinSync: () => resolveRealBinSync,
29
39
  which: () => which,
30
- whichBin: () => whichBin,
31
- whichBinSync: () => whichBinSync,
40
+ whichReal: () => whichReal,
41
+ whichRealSync: () => whichRealSync,
32
42
  whichSync: () => whichSync
33
43
  });
34
44
  module.exports = __toCommonJS(bin_exports);
35
- var import_home = require("#env/home");
36
- var import_windows = require("#env/windows");
37
- var import_xdg = require("#env/xdg");
38
- var import_platform = require("#constants/platform");
45
+ var import_node_fs = __toESM(require("node:fs"));
46
+ var import_node_path = __toESM(require("node:path"));
47
+ var import_home = require("./env/home");
48
+ var import_windows = require("./env/windows");
49
+ var import_xdg = require("./env/xdg");
50
+ var import_platform = require("./constants/platform");
51
+ var import_which = __toESM(require("./external/which"));
39
52
  var import_fs = require("./fs");
40
- var import_path = require("./path");
53
+ var import_normalize = require("./paths/normalize");
41
54
  var import_spawn = require("./spawn");
42
- let _fs;
43
- // @__NO_SIDE_EFFECTS__
44
- function getFs() {
45
- if (_fs === void 0) {
46
- _fs = require("node:fs");
47
- }
48
- return _fs;
49
- }
50
- let _path;
51
- // @__NO_SIDE_EFFECTS__
52
- function getPath() {
53
- if (_path === void 0) {
54
- _path = require("node:path");
55
- }
56
- return _path;
57
- }
58
- let _which;
59
- // @__NO_SIDE_EFFECTS__
60
- function getWhich() {
61
- if (_which === void 0) {
62
- _which = require("./external/which.js");
63
- }
64
- return _which;
65
- }
66
55
  // @__NO_SIDE_EFFECTS__
67
56
  async function execBin(binPath, args, options) {
68
- const resolvedPath = (0, import_path.isPath)(binPath) ? /* @__PURE__ */ resolveBinPathSync(binPath) : await whichBin(binPath);
57
+ const resolvedPath = (0, import_normalize.isPath)(binPath) ? /* @__PURE__ */ resolveRealBinSync(binPath) : await whichReal(binPath);
69
58
  if (!resolvedPath) {
70
59
  const error = new Error(
71
60
  `Binary not found: ${binPath}
@@ -87,61 +76,20 @@ To resolve:
87
76
  ...options
88
77
  });
89
78
  }
90
- async function which(binName, options) {
91
- return await (/* @__PURE__ */ getWhich())(binName, options);
92
- }
93
- function whichSync(binName, options) {
94
- return (/* @__PURE__ */ getWhich()).sync(binName, options);
95
- }
96
- async function whichBin(binName, options) {
97
- const which2 = /* @__PURE__ */ getWhich();
98
- const opts = { nothrow: true, ...options };
99
- const result = await which2(binName, opts);
100
- if (opts?.all) {
101
- const paths = Array.isArray(result) ? result : typeof result === "string" ? [result] : void 0;
102
- return paths?.length ? paths.map((p) => /* @__PURE__ */ resolveBinPathSync(p)) : paths;
103
- }
104
- if (!result) {
105
- return void 0;
106
- }
107
- return /* @__PURE__ */ resolveBinPathSync(result);
108
- }
109
- function whichBinSync(binName, options) {
110
- const opts = { nothrow: true, ...options };
111
- const result = whichSync(binName, opts);
112
- if (opts.all) {
113
- const paths = Array.isArray(result) ? result : typeof result === "string" ? [result] : void 0;
114
- return paths?.length ? paths.map((p) => /* @__PURE__ */ resolveBinPathSync(p)) : paths;
115
- }
116
- if (!result) {
117
- return void 0;
118
- }
119
- return /* @__PURE__ */ resolveBinPathSync(result);
120
- }
121
- function isShadowBinPath(dirPath) {
122
- if (!dirPath) {
123
- return false;
124
- }
125
- const normalized = dirPath.replace(/\\/g, "/");
126
- return normalized.includes("node_modules/.bin");
127
- }
128
79
  function findRealBin(binName, commonPaths = []) {
129
- const fs = /* @__PURE__ */ getFs();
130
- const path = /* @__PURE__ */ getPath();
131
- const which2 = /* @__PURE__ */ getWhich();
132
80
  for (const binPath2 of commonPaths) {
133
- if (fs?.existsSync(binPath2)) {
81
+ if (import_node_fs.default.existsSync(binPath2)) {
134
82
  return binPath2;
135
83
  }
136
84
  }
137
- const binPath = which2?.sync(binName, { nothrow: true });
85
+ const binPath = import_which.default.sync(binName, { nothrow: true });
138
86
  if (binPath) {
139
- const binDir = path?.dirname(binPath);
87
+ const binDir = import_node_path.default.dirname(binPath);
140
88
  if (isShadowBinPath(binDir)) {
141
- const allPaths = which2?.sync(binName, { all: true, nothrow: true }) || [];
89
+ const allPaths = import_which.default.sync(binName, { all: true, nothrow: true }) || [];
142
90
  const pathsArray = Array.isArray(allPaths) ? allPaths : typeof allPaths === "string" ? [allPaths] : [];
143
91
  for (const altPath of pathsArray) {
144
- const altDir = path?.dirname(altPath);
92
+ const altDir = import_node_path.default.dirname(altPath);
145
93
  if (!isShadowBinPath(altDir)) {
146
94
  return altPath;
147
95
  }
@@ -152,87 +100,88 @@ function findRealBin(binName, commonPaths = []) {
152
100
  return void 0;
153
101
  }
154
102
  function findRealNpm() {
155
- const fs = /* @__PURE__ */ getFs();
156
- const path = /* @__PURE__ */ getPath();
157
- const nodeDir = path?.dirname(process.execPath);
158
- const npmInNodeDir = path?.join(nodeDir, "npm");
159
- if (fs?.existsSync(npmInNodeDir)) {
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)) {
160
106
  return npmInNodeDir;
161
107
  }
162
108
  const commonPaths = ["/usr/local/bin/npm", "/usr/bin/npm"];
163
109
  const result = findRealBin("npm", commonPaths);
164
- if (result && fs?.existsSync(result)) {
110
+ if (result && import_node_fs.default.existsSync(result)) {
165
111
  return result;
166
112
  }
167
- const npmPath = whichBinSync("npm", { nothrow: true });
168
- if (npmPath && typeof npmPath === "string" && fs?.existsSync(npmPath)) {
113
+ const npmPath = whichRealSync("npm", { nothrow: true });
114
+ if (npmPath && typeof npmPath === "string" && import_node_fs.default.existsSync(npmPath)) {
169
115
  return npmPath;
170
116
  }
171
117
  return "npm";
172
118
  }
173
119
  function findRealPnpm() {
174
- const path = /* @__PURE__ */ getPath();
175
120
  const commonPaths = import_platform.WIN32 ? [
176
121
  // Windows common paths.
177
- path?.join((0, import_windows.getAppdata)(), "npm", "pnpm.cmd"),
178
- path?.join((0, import_windows.getAppdata)(), "npm", "pnpm"),
179
- path?.join((0, import_windows.getLocalappdata)(), "pnpm", "pnpm.cmd"),
180
- path?.join((0, import_windows.getLocalappdata)(), "pnpm", "pnpm"),
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"),
181
126
  "C:\\Program Files\\nodejs\\pnpm.cmd",
182
127
  "C:\\Program Files\\nodejs\\pnpm"
183
128
  ].filter(Boolean) : [
184
129
  // Unix common paths.
185
130
  "/usr/local/bin/pnpm",
186
131
  "/usr/bin/pnpm",
187
- path?.join(
132
+ import_node_path.default.join(
188
133
  (0, import_xdg.getXdgDataHome)() || `${(0, import_home.getHome)()}/.local/share`,
189
134
  "pnpm/pnpm"
190
135
  ),
191
- path?.join((0, import_home.getHome)(), ".pnpm/pnpm")
136
+ import_node_path.default.join((0, import_home.getHome)(), ".pnpm/pnpm")
192
137
  ].filter(Boolean);
193
138
  return findRealBin("pnpm", commonPaths) ?? "";
194
139
  }
195
140
  function findRealYarn() {
196
- const path = /* @__PURE__ */ getPath();
197
141
  const commonPaths = [
198
142
  "/usr/local/bin/yarn",
199
143
  "/usr/bin/yarn",
200
- path?.join((0, import_home.getHome)(), ".yarn/bin/yarn"),
201
- path?.join(
144
+ import_node_path.default.join((0, import_home.getHome)(), ".yarn/bin/yarn"),
145
+ import_node_path.default.join(
202
146
  (0, import_home.getHome)(),
203
147
  ".config/yarn/global/node_modules/.bin/yarn"
204
148
  )
205
149
  ].filter(Boolean);
206
150
  return findRealBin("yarn", commonPaths) ?? "";
207
151
  }
152
+ function isShadowBinPath(dirPath) {
153
+ if (!dirPath) {
154
+ return false;
155
+ }
156
+ const normalized = dirPath.replace(/\\/g, "/");
157
+ return normalized.includes("node_modules/.bin");
158
+ }
208
159
  // @__NO_SIDE_EFFECTS__
209
- function resolveBinPathSync(binPath) {
210
- const fs = /* @__PURE__ */ getFs();
211
- const path = /* @__PURE__ */ getPath();
212
- if (!path?.isAbsolute(binPath)) {
160
+ function resolveRealBinSync(binPath) {
161
+ if (!import_node_path.default.isAbsolute(binPath)) {
213
162
  try {
214
- const resolved = whichBinSync(binPath);
163
+ const resolved = whichRealSync(binPath);
215
164
  if (resolved) {
216
165
  binPath = resolved;
217
166
  }
218
167
  } catch {
219
168
  }
220
169
  }
221
- binPath = (0, import_path.normalizePath)(binPath);
170
+ binPath = (0, import_normalize.normalizePath)(binPath);
222
171
  if (binPath === ".") {
223
172
  return binPath;
224
173
  }
225
- const ext = path?.extname(binPath);
174
+ const ext = import_node_path.default.extname(binPath);
226
175
  const extLowered = ext.toLowerCase();
227
- const basename = path?.basename(binPath, ext);
176
+ const basename = import_node_path.default.basename(binPath, ext);
228
177
  const voltaIndex = basename === "node" ? -1 : /(?<=\/)\.volta\//i.exec(binPath)?.index ?? -1;
229
178
  if (voltaIndex !== -1) {
230
179
  const voltaPath = binPath.slice(0, voltaIndex);
231
- const voltaToolsPath = path?.join(voltaPath, "tools");
232
- const voltaImagePath = path?.join(voltaToolsPath, "image");
233
- const voltaUserPath = path?.join(voltaToolsPath, "user");
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");
234
183
  const voltaPlatform = (0, import_fs.readJsonSync)(
235
- path?.join(voltaUserPath, "platform.json"),
184
+ import_node_path.default.join(voltaUserPath, "platform.json"),
236
185
  { throws: false }
237
186
  );
238
187
  const voltaNodeVersion = voltaPlatform?.node?.runtime;
@@ -241,35 +190,35 @@ function resolveBinPathSync(binPath) {
241
190
  if (basename === "npm" || basename === "npx") {
242
191
  if (voltaNpmVersion) {
243
192
  const relCliPath = `bin/${basename}-cli.js`;
244
- voltaBinPath = path?.join(
193
+ voltaBinPath = import_node_path.default.join(
245
194
  voltaImagePath,
246
195
  `npm/${voltaNpmVersion}/${relCliPath}`
247
196
  );
248
- if (voltaNodeVersion && !fs?.existsSync(voltaBinPath)) {
249
- voltaBinPath = path?.join(
197
+ if (voltaNodeVersion && !import_node_fs.default.existsSync(voltaBinPath)) {
198
+ voltaBinPath = import_node_path.default.join(
250
199
  voltaImagePath,
251
200
  `node/${voltaNodeVersion}/lib/node_modules/npm/${relCliPath}`
252
201
  );
253
- if (!fs?.existsSync(voltaBinPath)) {
202
+ if (!import_node_fs.default.existsSync(voltaBinPath)) {
254
203
  voltaBinPath = "";
255
204
  }
256
205
  }
257
206
  }
258
207
  } else {
259
- const voltaUserBinPath = path?.join(voltaUserPath, "bin");
208
+ const voltaUserBinPath = import_node_path.default.join(voltaUserPath, "bin");
260
209
  const binInfo = (0, import_fs.readJsonSync)(
261
- path?.join(voltaUserBinPath, `${basename}.json`),
210
+ import_node_path.default.join(voltaUserBinPath, `${basename}.json`),
262
211
  { throws: false }
263
212
  );
264
213
  const binPackage = binInfo?.package;
265
214
  if (binPackage) {
266
- voltaBinPath = path?.join(
215
+ voltaBinPath = import_node_path.default.join(
267
216
  voltaImagePath,
268
217
  `packages/${binPackage}/bin/${basename}`
269
218
  );
270
- if (!fs?.existsSync(voltaBinPath)) {
219
+ if (!import_node_fs.default.existsSync(voltaBinPath)) {
271
220
  voltaBinPath = `${voltaBinPath}.cmd`;
272
- if (!fs?.existsSync(voltaBinPath)) {
221
+ if (!import_node_fs.default.existsSync(voltaBinPath)) {
273
222
  voltaBinPath = "";
274
223
  }
275
224
  }
@@ -277,7 +226,7 @@ function resolveBinPathSync(binPath) {
277
226
  }
278
227
  if (voltaBinPath) {
279
228
  try {
280
- return (0, import_path.normalizePath)(fs?.realpathSync.native(voltaBinPath));
229
+ return (0, import_normalize.normalizePath)(import_node_fs.default.realpathSync.native(voltaBinPath));
281
230
  } catch {
282
231
  }
283
232
  return voltaBinPath;
@@ -288,13 +237,13 @@ function resolveBinPathSync(binPath) {
288
237
  const isNpmOrNpx = basename === "npm" || basename === "npx";
289
238
  const isPnpmOrYarn = basename === "pnpm" || basename === "yarn";
290
239
  if (hasKnownExt && isNpmOrNpx) {
291
- const quickPath = path?.join(
292
- path?.dirname(binPath),
240
+ const quickPath = import_node_path.default.join(
241
+ import_node_path.default.dirname(binPath),
293
242
  `node_modules/npm/bin/${basename}-cli.js`
294
243
  );
295
- if (fs?.existsSync(quickPath)) {
244
+ if (import_node_fs.default.existsSync(quickPath)) {
296
245
  try {
297
- return fs?.realpathSync.native(quickPath);
246
+ return import_node_fs.default.realpathSync.native(quickPath);
298
247
  } catch {
299
248
  }
300
249
  return quickPath;
@@ -304,8 +253,8 @@ function resolveBinPathSync(binPath) {
304
253
  if (hasKnownExt && // Only parse shell scripts and batch files, not actual executables.
305
254
  // .exe files are already executables and don't need path resolution from wrapper scripts.
306
255
  extLowered !== ".exe" && // Check if file exists before attempting to read it to avoid ENOENT errors.
307
- fs?.existsSync(binPath)) {
308
- const source = fs?.readFileSync(binPath, "utf8");
256
+ import_node_fs.default.existsSync(binPath)) {
257
+ const source = import_node_fs.default.readFileSync(binPath, "utf8");
309
258
  if (isNpmOrNpx) {
310
259
  if (extLowered === ".cmd") {
311
260
  relPath = basename === "npm" ? /(?<="NPM_CLI_JS=%~dp0\\).*(?=")/.exec(source)?.[0] || "" : /(?<="NPX_CLI_JS=%~dp0\\).*(?=")/.exec(source)?.[0] || "";
@@ -352,7 +301,7 @@ function resolveBinPathSync(binPath) {
352
301
  relPath = /(?<="\$basedir\/).*(?=" $args\n)/.exec(source)?.[0] || "";
353
302
  }
354
303
  if (relPath) {
355
- binPath = (0, import_path.normalizePath)(path?.resolve(path?.dirname(binPath), relPath));
304
+ binPath = (0, import_normalize.normalizePath)(import_node_path.default.resolve(import_node_path.default.dirname(binPath), relPath));
356
305
  }
357
306
  }
358
307
  } else {
@@ -364,10 +313,10 @@ function resolveBinPathSync(binPath) {
364
313
  if (binIndex !== -1) {
365
314
  const baseBinPath = binPath.slice(0, binIndex + "/.bin/pnpm".length);
366
315
  try {
367
- const stats = fs?.statSync(baseBinPath);
316
+ const stats = import_node_fs.default.statSync(baseBinPath);
368
317
  if (stats.isFile()) {
369
- binPath = (0, import_path.normalizePath)(baseBinPath);
370
- hasNoExt = !path?.extname(binPath);
318
+ binPath = (0, import_normalize.normalizePath)(baseBinPath);
319
+ hasNoExt = !import_node_path.default.extname(binPath);
371
320
  }
372
321
  } catch {
373
322
  }
@@ -375,8 +324,8 @@ function resolveBinPathSync(binPath) {
375
324
  }
376
325
  if (hasNoExt && (isPnpmOrYarn || isNpmOrNpx) && // For extensionless files (Unix shell scripts), verify existence before reading.
377
326
  // This prevents ENOENT errors when the bin path doesn't exist.
378
- fs?.existsSync(binPath)) {
379
- const source = fs?.readFileSync(binPath, "utf8");
327
+ import_node_fs.default.existsSync(binPath)) {
328
+ const source = import_node_fs.default.readFileSync(binPath, "utf8");
380
329
  let relPath = "";
381
330
  if (isPnpmOrYarn) {
382
331
  relPath = /(?<="\$basedir\/)\.tools\/[^"]+(?="\s+"\$@")/.exec(source)?.[0] || "";
@@ -398,16 +347,62 @@ function resolveBinPathSync(binPath) {
398
347
  relPath = basename === "npm" ? /(?<=NPM_CLI_JS="\$CLI_BASEDIR\/).*(?=")/.exec(source)?.[0] || "" : /(?<=NPX_CLI_JS="\$CLI_BASEDIR\/).*(?=")/.exec(source)?.[0] || "";
399
348
  }
400
349
  if (relPath) {
401
- binPath = (0, import_path.normalizePath)(path?.resolve(path?.dirname(binPath), relPath));
350
+ binPath = (0, import_normalize.normalizePath)(import_node_path.default.resolve(import_node_path.default.dirname(binPath), relPath));
402
351
  }
403
352
  }
404
353
  }
405
354
  try {
406
- const realPath = fs?.realpathSync.native(binPath);
407
- return (0, import_path.normalizePath)(realPath);
355
+ const realPath = import_node_fs.default.realpathSync.native(binPath);
356
+ return (0, import_normalize.normalizePath)(realPath);
357
+ } catch {
358
+ }
359
+ return (0, import_normalize.normalizePath)(binPath);
360
+ }
361
+ async function which(binName, options) {
362
+ if ((0, import_normalize.isPath)(binName)) {
363
+ return binName;
364
+ }
365
+ try {
366
+ const result = await (0, import_which.default)(binName, options);
367
+ return result;
368
+ } catch {
369
+ return null;
370
+ }
371
+ }
372
+ async function whichReal(binName, options) {
373
+ const opts = { nothrow: true, ...options };
374
+ const result = await (0, import_which.default)(binName, opts);
375
+ if (opts?.all) {
376
+ const paths = Array.isArray(result) ? result : typeof result === "string" ? [result] : void 0;
377
+ return paths?.length ? paths.map((p) => /* @__PURE__ */ resolveRealBinSync(p)) : paths;
378
+ }
379
+ if (!result) {
380
+ return void 0;
381
+ }
382
+ return /* @__PURE__ */ resolveRealBinSync(result);
383
+ }
384
+ function whichRealSync(binName, options) {
385
+ const opts = { nothrow: true, ...options };
386
+ const result = whichSync(binName, opts);
387
+ if (opts.all) {
388
+ const paths = Array.isArray(result) ? result : typeof result === "string" ? [result] : void 0;
389
+ return paths?.length ? paths.map((p) => /* @__PURE__ */ resolveRealBinSync(p)) : paths;
390
+ }
391
+ if (!result) {
392
+ return void 0;
393
+ }
394
+ return /* @__PURE__ */ resolveRealBinSync(result);
395
+ }
396
+ function whichSync(binName, options) {
397
+ if ((0, import_normalize.isPath)(binName)) {
398
+ return binName;
399
+ }
400
+ try {
401
+ const result = import_which.default.sync(binName, options);
402
+ return result;
408
403
  } catch {
404
+ return null;
409
405
  }
410
- return (0, import_path.normalizePath)(binPath);
411
406
  }
412
407
  // Annotate the CommonJS export names for ESM import in node:
413
408
  0 && (module.exports = {
@@ -417,9 +412,9 @@ function resolveBinPathSync(binPath) {
417
412
  findRealPnpm,
418
413
  findRealYarn,
419
414
  isShadowBinPath,
420
- resolveBinPathSync,
415
+ resolveRealBinSync,
421
416
  which,
422
- whichBin,
423
- whichBinSync,
417
+ whichReal,
418
+ whichRealSync,
424
419
  whichSync
425
420
  });
package/dist/cacache.d.ts CHANGED
@@ -33,7 +33,7 @@ export interface RemoveOptions {
33
33
  /**
34
34
  * Get the cacache module for cache operations.
35
35
  */
36
- export declare function getCacache(): any;
36
+ export declare function getCacache(): import("./external/cacache").CacacheInstance;
37
37
  /**
38
38
  * Clear entries from the Socket shared cache.
39
39
  *
@@ -71,7 +71,10 @@ export declare function get(key: string, options?: GetOptions | undefined): Prom
71
71
  *
72
72
  * @throws {TypeError} If key contains wildcards (*)
73
73
  */
74
- export declare function put(key: string, data: string | Buffer, options?: PutOptions | undefined): Promise<any>;
74
+ export declare function put(key: string, data: string | Buffer, options?: PutOptions | undefined): Promise<{
75
+ integrity: string;
76
+ size: number;
77
+ }>;
75
78
  /**
76
79
  * Remove an entry from the Socket shared cache by key.
77
80
  *
package/dist/cacache.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
+ var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
6
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
9
  var __export = (target, all) => {
8
10
  for (var name in all)
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
16
18
  }
17
19
  return to;
18
20
  };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
  var cacache_exports = {};
21
31
  __export(cacache_exports, {
@@ -28,9 +38,10 @@ __export(cacache_exports, {
28
38
  withTmp: () => withTmp
29
39
  });
30
40
  module.exports = __toCommonJS(cacache_exports);
31
- var import_paths = require("./paths");
41
+ var import_cacache = __toESM(require("./external/cacache"));
42
+ var import_socket = require("./paths/socket");
32
43
  function getCacache() {
33
- return require("./external/cacache.js");
44
+ return import_cacache.default;
34
45
  }
35
46
  function patternToRegex(pattern) {
36
47
  const escaped = pattern.replaceAll(/[.+?^${}()|[\]\\]/g, "\\$&");
@@ -46,11 +57,11 @@ function matchesPattern(key, pattern) {
46
57
  }
47
58
  async function clear(options) {
48
59
  const opts = { __proto__: null, ...options };
49
- const cacache = getCacache();
50
- const cacheDir = (0, import_paths.getSocketCacacheDir)();
60
+ const cacache2 = getCacache();
61
+ const cacheDir = (0, import_socket.getSocketCacacheDir)();
51
62
  if (!opts.prefix) {
52
63
  try {
53
- await cacache.rm.all(cacheDir);
64
+ await cacache2.rm.all(cacheDir);
54
65
  return;
55
66
  } catch (e) {
56
67
  if (e?.code !== "ENOTEMPTY") {
@@ -62,11 +73,11 @@ async function clear(options) {
62
73
  const hasWildcard = opts.prefix.includes("*");
63
74
  if (!hasWildcard) {
64
75
  let removed2 = 0;
65
- const stream2 = cacache.ls.stream(cacheDir);
76
+ const stream2 = cacache2.ls.stream(cacheDir);
66
77
  for await (const entry of stream2) {
67
78
  if (entry.key.startsWith(opts.prefix)) {
68
79
  try {
69
- await cacache.rm.entry(cacheDir, entry.key);
80
+ await cacache2.rm.entry(cacheDir, entry.key);
70
81
  removed2++;
71
82
  } catch {
72
83
  }
@@ -75,11 +86,11 @@ async function clear(options) {
75
86
  return removed2;
76
87
  }
77
88
  let removed = 0;
78
- const stream = cacache.ls.stream(cacheDir);
89
+ const stream = cacache2.ls.stream(cacheDir);
79
90
  for await (const entry of stream) {
80
91
  if (matchesPattern(entry.key, opts.prefix)) {
81
92
  try {
82
- await cacache.rm.entry(cacheDir, entry.key);
93
+ await cacache2.rm.entry(cacheDir, entry.key);
83
94
  removed++;
84
95
  } catch {
85
96
  }
@@ -93,8 +104,8 @@ async function get(key, options) {
93
104
  'Cache key cannot contain wildcards (*). Wildcards are only supported in clear({ prefix: "pattern*" }).'
94
105
  );
95
106
  }
96
- const cacache = getCacache();
97
- return await cacache.get((0, import_paths.getSocketCacacheDir)(), key, options);
107
+ const cacache2 = getCacache();
108
+ return await cacache2.get((0, import_socket.getSocketCacacheDir)(), key, options);
98
109
  }
99
110
  async function put(key, data, options) {
100
111
  if (key.includes("*")) {
@@ -102,8 +113,8 @@ async function put(key, data, options) {
102
113
  'Cache key cannot contain wildcards (*). Wildcards are only supported in clear({ prefix: "pattern*" }).'
103
114
  );
104
115
  }
105
- const cacache = getCacache();
106
- return await cacache.put((0, import_paths.getSocketCacacheDir)(), key, data, options);
116
+ const cacache2 = getCacache();
117
+ return await cacache2.put((0, import_socket.getSocketCacacheDir)(), key, data, options);
107
118
  }
108
119
  async function remove(key) {
109
120
  if (key.includes("*")) {
@@ -111,8 +122,8 @@ async function remove(key) {
111
122
  'Cache key cannot contain wildcards (*). Use clear({ prefix: "pattern*" }) to remove multiple entries.'
112
123
  );
113
124
  }
114
- const cacache = getCacache();
115
- return await cacache.rm.entry((0, import_paths.getSocketCacacheDir)(), key);
125
+ const cacache2 = getCacache();
126
+ return await cacache2.rm.entry((0, import_socket.getSocketCacacheDir)(), key);
116
127
  }
117
128
  async function safeGet(key, options) {
118
129
  try {
@@ -122,9 +133,9 @@ async function safeGet(key, options) {
122
133
  }
123
134
  }
124
135
  async function withTmp(callback) {
125
- const cacache = getCacache();
126
- return await cacache.tmp.withTmp(
127
- (0, import_paths.getSocketCacacheDir)(),
136
+ const cacache2 = getCacache();
137
+ return await cacache2.tmp.withTmp(
138
+ (0, import_socket.getSocketCacacheDir)(),
128
139
  {},
129
140
  callback
130
141
  );
@@ -114,7 +114,7 @@ function createTtlCache(options) {
114
114
  results.set(originalKey, entry.data);
115
115
  }
116
116
  }
117
- const cacheDir = (await import("./paths")).getSocketCacacheDir();
117
+ const cacheDir = (await import("./paths/socket")).getSocketCacacheDir();
118
118
  const cacacheModule = await import("./cacache");
119
119
  const stream = cacacheModule.getCacache().ls.stream(cacheDir);
120
120
  for await (const cacheEntry of stream) {
@@ -1,7 +1,3 @@
1
- /**
2
- * Package manager agent constants.
3
- * Agent names, lockfile names, registry URLs, and configuration field names.
4
- */
5
1
  // Agent names.
6
2
  export declare const NPM = "npm";
7
3
  export declare const PNPM = "pnpm";