@socketsecurity/lib 4.4.0 → 5.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 (47) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/README.md +1 -1
  3. package/dist/constants/node.js +1 -1
  4. package/dist/{package-default-node-range.js → constants/package-default-node-range.js} +1 -1
  5. package/dist/constants/packages.js +3 -3
  6. package/dist/{dlx-binary.d.ts → dlx/binary.d.ts} +2 -2
  7. package/dist/{dlx-binary.js → dlx/binary.js} +17 -17
  8. package/dist/dlx/cache.d.ts +25 -0
  9. package/dist/dlx/cache.js +32 -0
  10. package/dist/dlx/dir.d.ts +24 -0
  11. package/dist/dlx/dir.js +79 -0
  12. package/dist/{dlx-manifest.js → dlx/manifest.js} +7 -7
  13. package/dist/{dlx-package.d.ts → dlx/package.d.ts} +2 -2
  14. package/dist/{dlx-package.js → dlx/package.js} +16 -16
  15. package/dist/dlx/packages.d.ts +24 -0
  16. package/dist/dlx/packages.js +125 -0
  17. package/dist/dlx/paths.d.ts +31 -0
  18. package/dist/dlx/paths.js +75 -0
  19. package/dist/fs.d.ts +34 -22
  20. package/dist/fs.js +3 -3
  21. package/dist/http-request.d.ts +46 -0
  22. package/dist/http-request.js +18 -1
  23. package/dist/json/edit.d.ts +16 -0
  24. package/dist/json/edit.js +248 -0
  25. package/dist/json/format.d.ts +140 -0
  26. package/dist/json/format.js +121 -0
  27. package/dist/json/parse.d.ts +76 -0
  28. package/dist/{json.js → json/parse.js} +4 -4
  29. package/dist/json/types.d.ts +229 -0
  30. package/dist/json/types.js +17 -0
  31. package/dist/packages/{editable.js → edit.js} +18 -32
  32. package/dist/packages/operations.js +3 -3
  33. package/dist/packages.d.ts +2 -2
  34. package/dist/packages.js +5 -5
  35. package/package.json +62 -37
  36. package/dist/dlx.d.ts +0 -104
  37. package/dist/dlx.js +0 -220
  38. package/dist/json.d.ts +0 -196
  39. /package/dist/{lifecycle-script-names.d.ts → constants/lifecycle-script-names.d.ts} +0 -0
  40. /package/dist/{lifecycle-script-names.js → constants/lifecycle-script-names.js} +0 -0
  41. /package/dist/{maintained-node-versions.d.ts → constants/maintained-node-versions.d.ts} +0 -0
  42. /package/dist/{maintained-node-versions.js → constants/maintained-node-versions.js} +0 -0
  43. /package/dist/{package-default-node-range.d.ts → constants/package-default-node-range.d.ts} +0 -0
  44. /package/dist/{package-default-socket-categories.d.ts → constants/package-default-socket-categories.d.ts} +0 -0
  45. /package/dist/{package-default-socket-categories.js → constants/package-default-socket-categories.js} +0 -0
  46. /package/dist/{dlx-manifest.d.ts → dlx/manifest.d.ts} +0 -0
  47. /package/dist/packages/{editable.d.ts → edit.d.ts} +0 -0
@@ -55,7 +55,7 @@ var import_objects = require("../objects");
55
55
  var import_normalize = require("./normalize");
56
56
  var import_packages2 = require("../paths/packages");
57
57
  var import_specs = require("./specs");
58
- var import_editable = require("./editable");
58
+ var import_edit = require("./edit");
59
59
  const abortSignal = (0, import_process.getAbortSignal)();
60
60
  const packageExtensions = (0, import_packages.getPackageExtensions)();
61
61
  const packumentCache = (0, import_packages.getPackumentCache)();
@@ -161,7 +161,7 @@ async function readPackageJson(filepath, options) {
161
161
  });
162
162
  if (pkgJson) {
163
163
  if (editable) {
164
- return await (0, import_editable.toEditablePackageJson)(pkgJson, {
164
+ return await (0, import_edit.toEditablePackageJson)(pkgJson, {
165
165
  path: filepath,
166
166
  normalize,
167
167
  ...normalizeOptions
@@ -180,7 +180,7 @@ function readPackageJsonSync(filepath, options) {
180
180
  const pkgJson = (0, import_fs.readJsonSync)((0, import_packages2.resolvePackageJsonPath)(filepath), { throws });
181
181
  if (pkgJson) {
182
182
  if (editable) {
183
- return (0, import_editable.toEditablePackageJsonSync)(pkgJson, {
183
+ return (0, import_edit.toEditablePackageJsonSync)(pkgJson, {
184
184
  path: filepath,
185
185
  normalize,
186
186
  ...normalizeOptions
@@ -3,7 +3,7 @@
3
3
  * Provides npm package analysis, dependency resolution, and registry operations.
4
4
  */
5
5
  import type { CategoryString } from './types';
6
- import { getEditablePackageJsonClass, pkgJsonToEditable, toEditablePackageJson, toEditablePackageJsonSync } from './packages/editable';
6
+ import { getEditablePackageJsonClass, pkgJsonToEditable, toEditablePackageJson, toEditablePackageJsonSync } from './packages/edit';
7
7
  import { findTypesForSubpath, getExportFilePaths, getSubpaths, isConditionalExports, isSubpathExports, resolvePackageJsonEntryExports } from './packages/exports';
8
8
  import { isolatePackage } from './packages/isolation';
9
9
  import { collectIncompatibleLicenses, collectLicenseWarnings, createAstNode, createBinaryOperationNode, createLicenseNode, parseSpdxExp, resolvePackageLicenses, visitLicenses } from './packages/licenses';
@@ -19,7 +19,7 @@ type PackageExports = {
19
19
  [path: string]: unknown;
20
20
  };
21
21
  // Re-export the EditablePackageJson instance type for convenient access
22
- export type EditablePackageJson = import('./packages/editable').EditablePackageJsonInstance;
22
+ export type EditablePackageJson = import('./packages/edit').EditablePackageJsonInstance;
23
23
  /**
24
24
  * Extended PackageJson type based on NPMCliPackageJson.Content with Socket-specific additions.
25
25
  * @extends NPMCliPackageJson.Content (from @npmcli/package-json)
package/dist/packages.js CHANGED
@@ -31,7 +31,7 @@ __export(packages_exports, {
31
31
  fetchPackageProvenance: () => import_provenance.fetchPackageProvenance,
32
32
  findPackageExtensions: () => import_operations.findPackageExtensions,
33
33
  findTypesForSubpath: () => import_exports.findTypesForSubpath,
34
- getEditablePackageJsonClass: () => import_editable.getEditablePackageJsonClass,
34
+ getEditablePackageJsonClass: () => import_edit.getEditablePackageJsonClass,
35
35
  getExportFilePaths: () => import_exports.getExportFilePaths,
36
36
  getProvenanceDetails: () => import_provenance.getProvenanceDetails,
37
37
  getReleaseTag: () => import_operations.getReleaseTag,
@@ -50,7 +50,7 @@ __export(packages_exports, {
50
50
  normalizePackageJson: () => import_normalize.normalizePackageJson,
51
51
  packPackage: () => import_operations.packPackage,
52
52
  parseSpdxExp: () => import_licenses.parseSpdxExp,
53
- pkgJsonToEditable: () => import_editable.pkgJsonToEditable,
53
+ pkgJsonToEditable: () => import_edit.pkgJsonToEditable,
54
54
  readPackageJson: () => import_operations.readPackageJson,
55
55
  readPackageJsonSync: () => import_operations.readPackageJsonSync,
56
56
  resolveEscapedScope: () => import_normalize.resolveEscapedScope,
@@ -62,13 +62,13 @@ __export(packages_exports, {
62
62
  resolvePackageLicenses: () => import_licenses.resolvePackageLicenses,
63
63
  resolvePackageName: () => import_operations.resolvePackageName,
64
64
  resolveRegistryPackageName: () => import_operations.resolveRegistryPackageName,
65
- toEditablePackageJson: () => import_editable.toEditablePackageJson,
66
- toEditablePackageJsonSync: () => import_editable.toEditablePackageJsonSync,
65
+ toEditablePackageJson: () => import_edit.toEditablePackageJson,
66
+ toEditablePackageJsonSync: () => import_edit.toEditablePackageJsonSync,
67
67
  unescapeScope: () => import_normalize.unescapeScope,
68
68
  visitLicenses: () => import_licenses.visitLicenses
69
69
  });
70
70
  module.exports = __toCommonJS(packages_exports);
71
- var import_editable = require("./packages/editable");
71
+ var import_edit = require("./packages/edit");
72
72
  var import_exports = require("./packages/exports");
73
73
  var import_isolation = require("./packages/isolation");
74
74
  var import_licenses = require("./packages/licenses");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@socketsecurity/lib",
3
- "version": "4.4.0",
4
- "packageManager": "pnpm@10.22.0",
3
+ "version": "5.0.1",
4
+ "packageManager": "pnpm@10.25.0",
5
5
  "license": "MIT",
6
6
  "description": "Core utilities and infrastructure for Socket.dev security tools",
7
7
  "keywords": [
@@ -151,10 +151,26 @@
151
151
  "types": "./dist/constants/licenses.d.ts",
152
152
  "default": "./dist/constants/licenses.js"
153
153
  },
154
+ "./constants/lifecycle-script-names": {
155
+ "types": "./dist/constants/lifecycle-script-names.d.ts",
156
+ "default": "./dist/constants/lifecycle-script-names.js"
157
+ },
158
+ "./constants/maintained-node-versions": {
159
+ "types": "./dist/constants/maintained-node-versions.d.ts",
160
+ "default": "./dist/constants/maintained-node-versions.js"
161
+ },
154
162
  "./constants/node": {
155
163
  "types": "./dist/constants/node.d.ts",
156
164
  "default": "./dist/constants/node.js"
157
165
  },
166
+ "./constants/package-default-node-range": {
167
+ "types": "./dist/constants/package-default-node-range.d.ts",
168
+ "default": "./dist/constants/package-default-node-range.js"
169
+ },
170
+ "./constants/package-default-socket-categories": {
171
+ "types": "./dist/constants/package-default-socket-categories.d.ts",
172
+ "default": "./dist/constants/package-default-socket-categories.js"
173
+ },
158
174
  "./constants/packages": {
159
175
  "types": "./dist/constants/packages.d.ts",
160
176
  "default": "./dist/constants/packages.js"
@@ -203,21 +219,33 @@
203
219
  "types": "./dist/debug.d.ts",
204
220
  "default": "./dist/debug.js"
205
221
  },
206
- "./dlx": {
207
- "types": "./dist/dlx.d.ts",
208
- "default": "./dist/dlx.js"
222
+ "./dlx/binary": {
223
+ "types": "./dist/dlx/binary.d.ts",
224
+ "default": "./dist/dlx/binary.js"
225
+ },
226
+ "./dlx/cache": {
227
+ "types": "./dist/dlx/cache.d.ts",
228
+ "default": "./dist/dlx/cache.js"
229
+ },
230
+ "./dlx/dir": {
231
+ "types": "./dist/dlx/dir.d.ts",
232
+ "default": "./dist/dlx/dir.js"
209
233
  },
210
- "./dlx-binary": {
211
- "types": "./dist/dlx-binary.d.ts",
212
- "default": "./dist/dlx-binary.js"
234
+ "./dlx/manifest": {
235
+ "types": "./dist/dlx/manifest.d.ts",
236
+ "default": "./dist/dlx/manifest.js"
213
237
  },
214
- "./dlx-manifest": {
215
- "types": "./dist/dlx-manifest.d.ts",
216
- "default": "./dist/dlx-manifest.js"
238
+ "./dlx/package": {
239
+ "types": "./dist/dlx/package.d.ts",
240
+ "default": "./dist/dlx/package.js"
217
241
  },
218
- "./dlx-package": {
219
- "types": "./dist/dlx-package.d.ts",
220
- "default": "./dist/dlx-package.js"
242
+ "./dlx/packages": {
243
+ "types": "./dist/dlx/packages.d.ts",
244
+ "default": "./dist/dlx/packages.js"
245
+ },
246
+ "./dlx/paths": {
247
+ "types": "./dist/dlx/paths.d.ts",
248
+ "default": "./dist/dlx/paths.js"
221
249
  },
222
250
  "./effects/pulse-frames": {
223
251
  "types": "./dist/effects/pulse-frames.d.ts",
@@ -355,13 +383,21 @@
355
383
  "types": "./dist/ipc.d.ts",
356
384
  "default": "./dist/ipc.js"
357
385
  },
358
- "./json": {
359
- "types": "./dist/json.d.ts",
360
- "default": "./dist/json.js"
386
+ "./json/edit": {
387
+ "types": "./dist/json/edit.d.ts",
388
+ "default": "./dist/json/edit.js"
389
+ },
390
+ "./json/format": {
391
+ "types": "./dist/json/format.d.ts",
392
+ "default": "./dist/json/format.js"
393
+ },
394
+ "./json/parse": {
395
+ "types": "./dist/json/parse.d.ts",
396
+ "default": "./dist/json/parse.js"
361
397
  },
362
- "./lifecycle-script-names": {
363
- "types": "./dist/lifecycle-script-names.d.ts",
364
- "default": "./dist/lifecycle-script-names.js"
398
+ "./json/types": {
399
+ "types": "./dist/json/types.d.ts",
400
+ "default": "./dist/json/types.js"
365
401
  },
366
402
  "./links": {
367
403
  "types": "./dist/links/index.d.ts",
@@ -375,10 +411,6 @@
375
411
  "types": "./dist/logger.d.ts",
376
412
  "default": "./dist/logger.js"
377
413
  },
378
- "./maintained-node-versions": {
379
- "types": "./dist/maintained-node-versions.d.ts",
380
- "default": "./dist/maintained-node-versions.js"
381
- },
382
414
  "./memoization": {
383
415
  "types": "./dist/memoization.d.ts",
384
416
  "default": "./dist/memoization.js"
@@ -387,14 +419,6 @@
387
419
  "types": "./dist/objects.d.ts",
388
420
  "default": "./dist/objects.js"
389
421
  },
390
- "./package-default-node-range": {
391
- "types": "./dist/package-default-node-range.d.ts",
392
- "default": "./dist/package-default-node-range.js"
393
- },
394
- "./package-default-socket-categories": {
395
- "types": "./dist/package-default-socket-categories.d.ts",
396
- "default": "./dist/package-default-socket-categories.js"
397
- },
398
422
  "./package-extensions": {
399
423
  "types": "./dist/package-extensions.d.ts",
400
424
  "default": "./dist/package-extensions.js"
@@ -403,9 +427,9 @@
403
427
  "types": "./dist/packages.d.ts",
404
428
  "default": "./dist/packages.js"
405
429
  },
406
- "./packages/editable": {
407
- "types": "./dist/packages/editable.d.ts",
408
- "default": "./dist/packages/editable.js"
430
+ "./packages/edit": {
431
+ "types": "./dist/packages/edit.d.ts",
432
+ "default": "./dist/packages/edit.js"
409
433
  },
410
434
  "./packages/exports": {
411
435
  "types": "./dist/packages/exports.d.ts",
@@ -653,7 +677,7 @@
653
677
  ],
654
678
  "engines": {
655
679
  "node": ">=22",
656
- "pnpm": ">=10.22.0"
680
+ "pnpm": ">=10.25.0"
657
681
  },
658
682
  "sideEffects": false,
659
683
  "scripts": {
@@ -718,6 +742,7 @@
718
742
  "lint-staged": "15.2.11",
719
743
  "magic-string": "0.30.17",
720
744
  "make-fetch-happen": "15.0.2",
745
+ "nock": "14.0.10",
721
746
  "normalize-package-data": "8.0.0",
722
747
  "npm-package-arg": "13.0.0",
723
748
  "pacote": "21.0.1",
@@ -726,7 +751,7 @@
726
751
  "spdx-correct": "3.2.0",
727
752
  "spdx-expression-parse": "4.0.0",
728
753
  "streaming-iterables": "8.0.1",
729
- "taze": "19.6.0",
754
+ "taze": "19.9.2",
730
755
  "trash": "10.0.0",
731
756
  "type-coverage": "2.29.7",
732
757
  "typescript": "5.9.2",
package/dist/dlx.d.ts DELETED
@@ -1,104 +0,0 @@
1
- /**
2
- * Generate a cache directory name using npm/npx approach.
3
- * Uses first 16 characters of SHA-512 hash (like npm/npx).
4
- *
5
- * Rationale for SHA-512 truncated (vs full SHA-256):
6
- * - Matches npm/npx ecosystem behavior
7
- * - Shorter paths for Windows MAX_PATH compatibility (260 chars)
8
- * - 16 hex chars = 64 bits = acceptable collision risk for local cache
9
- * - Collision probability ~1 in 18 quintillion with 1000 entries
10
- *
11
- * Input strategy (aligned with npx):
12
- * - npx uses package spec strings (e.g., '@scope/pkg@1.0.0', 'prettier@3.0.0')
13
- * - Caller provides complete spec string with version for accurate cache keying
14
- * - For package installs: Use PURL-style spec with version
15
- * Examples: 'npm:prettier@3.0.0', 'pypi:requests@2.31.0', 'gem:rails@7.0.0'
16
- * Note: Socket uses shorthand format without 'pkg:' prefix
17
- * (handled by @socketregistry/packageurl-js)
18
- * - For binary downloads: Use URL:name for uniqueness
19
- *
20
- * Reference: npm/cli v11.6.2 libnpmexec/lib/index.js#L233-L244
21
- * https://github.com/npm/cli/blob/v11.6.2/workspaces/libnpmexec/lib/index.js#L233-L244
22
- * Implementation: packages.map().sort().join('\n') → SHA-512 → slice(0,16)
23
- * npx hashes the package spec (name@version), not just name
24
- */
25
- export declare function generateCacheKey(spec: string): string;
26
- /**
27
- * Clear all DLX package installations.
28
- */
29
- export declare function clearDlx(): Promise<void>;
30
- /**
31
- * Clear all DLX package installations synchronously.
32
- */
33
- export declare function clearDlxSync(): void;
34
- /**
35
- * Check if the DLX directory exists.
36
- */
37
- export declare function dlxDirExists(): boolean;
38
- /**
39
- * Check if the DLX directory exists asynchronously.
40
- */
41
- export declare function dlxDirExistsAsync(): Promise<boolean>;
42
- /**
43
- * Ensure the DLX directory exists, creating it if necessary.
44
- */
45
- export declare function ensureDlxDir(): Promise<void>;
46
- /**
47
- * Ensure the DLX directory exists synchronously, creating it if necessary.
48
- */
49
- export declare function ensureDlxDirSync(): void;
50
- /**
51
- * Get the installed package directory within DLX node_modules.
52
- */
53
- export declare function getDlxInstalledPackageDir(packageName: string): string;
54
- /**
55
- * Get the DLX installation directory for a specific package.
56
- */
57
- export declare function getDlxPackageDir(packageName: string): string;
58
- /**
59
- * Get the package.json path for a DLX installed package.
60
- */
61
- export declare function getDlxPackageJsonPath(packageName: string): string;
62
- /**
63
- * Get the node_modules directory for a DLX package installation.
64
- */
65
- export declare function getDlxPackageNodeModulesDir(packageName: string): string;
66
- /**
67
- * Check if a file path is within the Socket DLX directory.
68
- * This is useful for determining if a binary or file is managed by Socket's DLX system.
69
- *
70
- * @param filePath - Absolute or relative path to check
71
- * @returns true if the path is within ~/.socket/_dlx/, false otherwise
72
- *
73
- * @example
74
- * ```typescript
75
- * isInSocketDlx('/home/user/.socket/_dlx/abc123/bin/socket') // true
76
- * isInSocketDlx('/usr/local/bin/socket') // false
77
- * isInSocketDlx(process.argv[0]) // Check if current binary is in DLX
78
- * ```
79
- */
80
- export declare function isInSocketDlx(filePath: string): boolean;
81
- /**
82
- * Check if a package is installed in DLX.
83
- */
84
- export declare function isDlxPackageInstalled(packageName: string): boolean;
85
- /**
86
- * Check if a package is installed in DLX asynchronously.
87
- */
88
- export declare function isDlxPackageInstalledAsync(packageName: string): Promise<boolean>;
89
- /**
90
- * List all packages installed in DLX.
91
- */
92
- export declare function listDlxPackages(): string[];
93
- /**
94
- * List all packages installed in DLX asynchronously.
95
- */
96
- export declare function listDlxPackagesAsync(): Promise<string[]>;
97
- /**
98
- * Remove a DLX package installation.
99
- */
100
- export declare function removeDlxPackage(packageName: string): Promise<void>;
101
- /**
102
- * Remove a DLX package installation synchronously.
103
- */
104
- export declare function removeDlxPackageSync(packageName: string): void;
package/dist/dlx.js DELETED
@@ -1,220 +0,0 @@
1
- "use strict";
2
- /* Socket Lib - Built with esbuild */
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var dlx_exports = {};
21
- __export(dlx_exports, {
22
- clearDlx: () => clearDlx,
23
- clearDlxSync: () => clearDlxSync,
24
- dlxDirExists: () => dlxDirExists,
25
- dlxDirExistsAsync: () => dlxDirExistsAsync,
26
- ensureDlxDir: () => ensureDlxDir,
27
- ensureDlxDirSync: () => ensureDlxDirSync,
28
- generateCacheKey: () => generateCacheKey,
29
- getDlxInstalledPackageDir: () => getDlxInstalledPackageDir,
30
- getDlxPackageDir: () => getDlxPackageDir,
31
- getDlxPackageJsonPath: () => getDlxPackageJsonPath,
32
- getDlxPackageNodeModulesDir: () => getDlxPackageNodeModulesDir,
33
- isDlxPackageInstalled: () => isDlxPackageInstalled,
34
- isDlxPackageInstalledAsync: () => isDlxPackageInstalledAsync,
35
- isInSocketDlx: () => isInSocketDlx,
36
- listDlxPackages: () => listDlxPackages,
37
- listDlxPackagesAsync: () => listDlxPackagesAsync,
38
- removeDlxPackage: () => removeDlxPackage,
39
- removeDlxPackageSync: () => removeDlxPackageSync
40
- });
41
- module.exports = __toCommonJS(dlx_exports);
42
- var import_crypto = require("crypto");
43
- var import_fs = require("./fs");
44
- var import_normalize = require("./paths/normalize");
45
- var import_socket = require("./paths/socket");
46
- var import_promises = require("./promises");
47
- let _fs;
48
- // @__NO_SIDE_EFFECTS__
49
- function getFs() {
50
- if (_fs === void 0) {
51
- _fs = require("node:fs");
52
- }
53
- return _fs;
54
- }
55
- function generateCacheKey(spec) {
56
- return (0, import_crypto.createHash)("sha512").update(spec).digest("hex").substring(0, 16);
57
- }
58
- let _path;
59
- // @__NO_SIDE_EFFECTS__
60
- function getPath() {
61
- if (_path === void 0) {
62
- _path = require("node:path");
63
- }
64
- return _path;
65
- }
66
- async function clearDlx() {
67
- const packages = await listDlxPackagesAsync();
68
- await (0, import_promises.pEach)(packages, (pkg) => removeDlxPackage(pkg));
69
- }
70
- function clearDlxSync() {
71
- const packages = listDlxPackages();
72
- for (const pkg of packages) {
73
- removeDlxPackageSync(pkg);
74
- }
75
- }
76
- function dlxDirExists() {
77
- const fs = /* @__PURE__ */ getFs();
78
- return fs.existsSync((0, import_socket.getSocketDlxDir)());
79
- }
80
- async function dlxDirExistsAsync() {
81
- const fs = /* @__PURE__ */ getFs();
82
- try {
83
- await fs.promises.access((0, import_socket.getSocketDlxDir)());
84
- return true;
85
- } catch {
86
- return false;
87
- }
88
- }
89
- async function ensureDlxDir() {
90
- await (0, import_fs.safeMkdir)((0, import_socket.getSocketDlxDir)());
91
- }
92
- function ensureDlxDirSync() {
93
- (0, import_fs.safeMkdirSync)((0, import_socket.getSocketDlxDir)());
94
- }
95
- function getDlxInstalledPackageDir(packageName) {
96
- const path = /* @__PURE__ */ getPath();
97
- return (0, import_normalize.normalizePath)(
98
- path.join(getDlxPackageNodeModulesDir(packageName), packageName)
99
- );
100
- }
101
- function getDlxPackageDir(packageName) {
102
- const path = /* @__PURE__ */ getPath();
103
- return (0, import_normalize.normalizePath)(path.join((0, import_socket.getSocketDlxDir)(), packageName));
104
- }
105
- function getDlxPackageJsonPath(packageName) {
106
- const path = /* @__PURE__ */ getPath();
107
- return (0, import_normalize.normalizePath)(
108
- path.join(getDlxInstalledPackageDir(packageName), "package.json")
109
- );
110
- }
111
- function getDlxPackageNodeModulesDir(packageName) {
112
- const path = /* @__PURE__ */ getPath();
113
- return (0, import_normalize.normalizePath)(path.join(getDlxPackageDir(packageName), "node_modules"));
114
- }
115
- function isInSocketDlx(filePath) {
116
- if (!filePath) {
117
- return false;
118
- }
119
- const path = /* @__PURE__ */ getPath();
120
- const dlxDir = (0, import_socket.getSocketDlxDir)();
121
- const absolutePath = (0, import_normalize.normalizePath)(path.resolve(filePath));
122
- return absolutePath.startsWith(`${dlxDir}/`);
123
- }
124
- function isDlxPackageInstalled(packageName) {
125
- const fs = /* @__PURE__ */ getFs();
126
- return fs.existsSync(getDlxInstalledPackageDir(packageName));
127
- }
128
- async function isDlxPackageInstalledAsync(packageName) {
129
- const fs = /* @__PURE__ */ getFs();
130
- try {
131
- await fs.promises.access(getDlxInstalledPackageDir(packageName));
132
- return true;
133
- } catch {
134
- return false;
135
- }
136
- }
137
- function listDlxPackages() {
138
- try {
139
- return (0, import_fs.readDirNamesSync)((0, import_socket.getSocketDlxDir)(), { sort: true });
140
- } catch {
141
- return [];
142
- }
143
- }
144
- async function listDlxPackagesAsync() {
145
- const fs = /* @__PURE__ */ getFs();
146
- try {
147
- const entries = await fs.promises.readdir((0, import_socket.getSocketDlxDir)(), {
148
- withFileTypes: true
149
- });
150
- return entries.filter((e) => e.isDirectory()).map((e) => e.name).sort();
151
- } catch {
152
- return [];
153
- }
154
- }
155
- async function removeDlxPackage(packageName) {
156
- const packageDir = getDlxPackageDir(packageName);
157
- try {
158
- await (0, import_fs.safeDelete)(packageDir, { recursive: true, force: true });
159
- } catch (e) {
160
- throw new Error(`Failed to remove DLX package "${packageName}"`, {
161
- cause: e
162
- });
163
- }
164
- }
165
- function removeDlxPackageSync(packageName) {
166
- const fs = /* @__PURE__ */ getFs();
167
- const packageDir = getDlxPackageDir(packageName);
168
- try {
169
- fs.rmSync(packageDir, { recursive: true, force: true });
170
- } catch (e) {
171
- const code = e.code;
172
- if (code === "EACCES" || code === "EPERM") {
173
- throw new Error(
174
- `Permission denied removing DLX package "${packageName}"
175
- Directory: ${packageDir}
176
- To resolve:
177
- 1. Check file/directory permissions
178
- 2. Close any programs using files in this directory
179
- 3. Try running with elevated privileges if necessary
180
- 4. Manually remove: rm -rf "${packageDir}"`,
181
- { cause: e }
182
- );
183
- }
184
- if (code === "EROFS") {
185
- throw new Error(
186
- `Cannot remove DLX package "${packageName}" from read-only filesystem
187
- Directory: ${packageDir}
188
- The filesystem is mounted read-only.`,
189
- { cause: e }
190
- );
191
- }
192
- throw new Error(
193
- `Failed to remove DLX package "${packageName}"
194
- Directory: ${packageDir}
195
- Check permissions and ensure no programs are using this directory.`,
196
- { cause: e }
197
- );
198
- }
199
- }
200
- // Annotate the CommonJS export names for ESM import in node:
201
- 0 && (module.exports = {
202
- clearDlx,
203
- clearDlxSync,
204
- dlxDirExists,
205
- dlxDirExistsAsync,
206
- ensureDlxDir,
207
- ensureDlxDirSync,
208
- generateCacheKey,
209
- getDlxInstalledPackageDir,
210
- getDlxPackageDir,
211
- getDlxPackageJsonPath,
212
- getDlxPackageNodeModulesDir,
213
- isDlxPackageInstalled,
214
- isDlxPackageInstalledAsync,
215
- isInSocketDlx,
216
- listDlxPackages,
217
- listDlxPackagesAsync,
218
- removeDlxPackage,
219
- removeDlxPackageSync
220
- });