@socketsecurity/lib 4.3.0 → 5.0.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 +89 -0
- package/README.md +1 -1
- package/dist/constants/node.js +1 -1
- package/dist/{package-default-node-range.js → constants/package-default-node-range.js} +1 -1
- package/dist/constants/packages.js +3 -3
- package/dist/{dlx-binary.d.ts → dlx/binary.d.ts} +2 -2
- package/dist/{dlx-binary.js → dlx/binary.js} +17 -17
- package/dist/dlx/cache.d.ts +25 -0
- package/dist/dlx/cache.js +32 -0
- package/dist/dlx/dir.d.ts +24 -0
- package/dist/dlx/dir.js +79 -0
- package/dist/{dlx-manifest.js → dlx/manifest.js} +7 -7
- package/dist/{dlx-package.d.ts → dlx/package.d.ts} +2 -2
- package/dist/{dlx-package.js → dlx/package.js} +16 -16
- package/dist/dlx/packages.d.ts +24 -0
- package/dist/dlx/packages.js +125 -0
- package/dist/dlx/paths.d.ts +31 -0
- package/dist/dlx/paths.js +75 -0
- package/dist/fs.d.ts +103 -55
- package/dist/fs.js +149 -41
- package/dist/json/edit.d.ts +16 -0
- package/dist/json/edit.js +217 -0
- package/dist/json/format.d.ts +140 -0
- package/dist/json/format.js +121 -0
- package/dist/json/parse.d.ts +76 -0
- package/dist/{json.js → json/parse.js} +4 -4
- package/dist/json/types.d.ts +229 -0
- package/dist/json/types.js +17 -0
- package/dist/objects.d.ts +61 -61
- package/dist/objects.js +30 -30
- package/dist/packages/{editable.js → edit.js} +18 -32
- package/dist/packages/operations.js +3 -3
- package/dist/packages.d.ts +2 -2
- package/dist/packages.js +5 -5
- package/dist/promises.d.ts +19 -19
- package/dist/promises.js +14 -14
- package/dist/sorts.d.ts +10 -10
- package/dist/sorts.js +19 -19
- package/dist/strings.d.ts +63 -63
- package/dist/strings.js +18 -18
- package/dist/suppress-warnings.js +4 -0
- package/package.json +59 -35
- package/dist/dlx.d.ts +0 -104
- package/dist/dlx.js +0 -220
- package/dist/json.d.ts +0 -196
- /package/dist/{lifecycle-script-names.d.ts → constants/lifecycle-script-names.d.ts} +0 -0
- /package/dist/{lifecycle-script-names.js → constants/lifecycle-script-names.js} +0 -0
- /package/dist/{maintained-node-versions.d.ts → constants/maintained-node-versions.d.ts} +0 -0
- /package/dist/{maintained-node-versions.js → constants/maintained-node-versions.js} +0 -0
- /package/dist/{package-default-node-range.d.ts → constants/package-default-node-range.d.ts} +0 -0
- /package/dist/{package-default-socket-categories.d.ts → constants/package-default-socket-categories.d.ts} +0 -0
- /package/dist/{package-default-socket-categories.js → constants/package-default-socket-categories.js} +0 -0
- /package/dist/{dlx-manifest.d.ts → dlx/manifest.d.ts} +0 -0
- /package/dist/packages/{editable.d.ts → edit.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,95 @@ 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.0.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.0.0) - 2025-12-04
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **json/edit**: New `EditableJson` base class for generic JSON file manipulation with formatting preservation
|
|
13
|
+
- Extracted from `EditablePackageJson` to enable code reuse via composition pattern
|
|
14
|
+
- Supports reading, modifying, and writing JSON files while preserving formatting
|
|
15
|
+
- Export: `@socketsecurity/lib/json/edit`
|
|
16
|
+
|
|
17
|
+
- **json/format**: New JSON formatting utilities for consistent JSON manipulation
|
|
18
|
+
- Functions for analyzing and preserving JSON formatting patterns
|
|
19
|
+
- Export: `@socketsecurity/lib/json/format`
|
|
20
|
+
|
|
21
|
+
- **json/parse**: New JSON parsing utilities
|
|
22
|
+
- `isJsonPrimitive()`: Check if value is a JSON primitive type
|
|
23
|
+
- `jsonParse()`: Parse JSON with error handling
|
|
24
|
+
- Export: `@socketsecurity/lib/json/parse`
|
|
25
|
+
|
|
26
|
+
- **json/types**: New JSON type definitions and interfaces
|
|
27
|
+
- Export: `@socketsecurity/lib/json/types`
|
|
28
|
+
|
|
29
|
+
- **dlx/cache**: New DLX cache utilities
|
|
30
|
+
- `generateCacheKey()`: Generate cache keys for DLX packages
|
|
31
|
+
- Export: `@socketsecurity/lib/dlx/cache`
|
|
32
|
+
|
|
33
|
+
- **dlx/dir**: New DLX directory management utilities
|
|
34
|
+
- `clearDlx()`, `clearDlxSync()`: Clear DLX directory
|
|
35
|
+
- `dlxDirExists()`, `dlxDirExistsAsync()`: Check if DLX directory exists
|
|
36
|
+
- `ensureDlxDir()`, `ensureDlxDirSync()`: Ensure DLX directory exists
|
|
37
|
+
- Export: `@socketsecurity/lib/dlx/dir`
|
|
38
|
+
|
|
39
|
+
- **dlx/packages**: New DLX package management utilities
|
|
40
|
+
- `isDlxPackageInstalled()`, `isDlxPackageInstalledAsync()`: Check if package is installed
|
|
41
|
+
- `listDlxPackages()`, `listDlxPackagesAsync()`: List installed packages
|
|
42
|
+
- `removeDlxPackage()`, `removeDlxPackageSync()`: Remove installed packages
|
|
43
|
+
- Export: `@socketsecurity/lib/dlx/packages`
|
|
44
|
+
|
|
45
|
+
- **dlx/paths**: New DLX path utilities
|
|
46
|
+
- `getDlxPackageDir()`: Get package directory path
|
|
47
|
+
- `getDlxInstalledPackageDir()`: Get installed package directory path
|
|
48
|
+
- `getDlxPackageJsonPath()`: Get package.json path
|
|
49
|
+
- `getDlxPackageNodeModulesDir()`: Get node_modules directory path
|
|
50
|
+
- `isInSocketDlx()`: Check if path is in DLX directory
|
|
51
|
+
- Export: `@socketsecurity/lib/dlx/paths`
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
|
|
55
|
+
- **BREAKING**: Reorganized module paths for better structure and discoverability
|
|
56
|
+
- `@socketsecurity/lib/json/editable` → `@socketsecurity/lib/json/edit`
|
|
57
|
+
- `@socketsecurity/lib/packages/editable` → `@socketsecurity/lib/packages/edit`
|
|
58
|
+
- `@socketsecurity/lib/maintained-node-versions` → `@socketsecurity/lib/constants/maintained-node-versions`
|
|
59
|
+
- `@socketsecurity/lib/package-default-node-range` → `@socketsecurity/lib/constants/package-default-node-range`
|
|
60
|
+
- `@socketsecurity/lib/package-default-socket-categories` → `@socketsecurity/lib/constants/package-default-socket-categories`
|
|
61
|
+
- `@socketsecurity/lib/lifecycle-script-names` → `@socketsecurity/lib/constants/lifecycle-script-names`
|
|
62
|
+
- `@socketsecurity/lib/dlx` → Split into `@socketsecurity/lib/dlx/cache`, `@socketsecurity/lib/dlx/dir`, `@socketsecurity/lib/dlx/packages`, `@socketsecurity/lib/dlx/paths`
|
|
63
|
+
- `@socketsecurity/lib/dlx-binary` → `@socketsecurity/lib/dlx/binary`
|
|
64
|
+
- `@socketsecurity/lib/dlx-manifest` → `@socketsecurity/lib/dlx/manifest`
|
|
65
|
+
- `@socketsecurity/lib/dlx-package` → `@socketsecurity/lib/dlx/package`
|
|
66
|
+
|
|
67
|
+
- **json**: Reorganized JSON utilities into modular submodules (json/edit, json/format, json/parse, json/types)
|
|
68
|
+
- Removed barrel index file in favor of direct submodule imports
|
|
69
|
+
- Better separation of concerns and tree-shaking
|
|
70
|
+
|
|
71
|
+
- **dlx**: Split monolithic DLX module into focused submodules (cache, dir, packages, paths)
|
|
72
|
+
- Improved modularity and maintainability
|
|
73
|
+
- Better code organization and discoverability
|
|
74
|
+
|
|
75
|
+
## [4.4.0](https://github.com/SocketDev/socket-lib/releases/tag/v4.4.0) - 2025-11-25
|
|
76
|
+
|
|
77
|
+
### Added
|
|
78
|
+
|
|
79
|
+
- **fs**: Exported `normalizeEncoding()` function for robust encoding string normalization
|
|
80
|
+
- Handles case-insensitive encoding names (e.g., 'UTF-8', 'utf8', 'UTF8')
|
|
81
|
+
- Supports encoding aliases (e.g., 'binary' → 'latin1', 'ucs-2' → 'utf16le')
|
|
82
|
+
- Fast-path optimization for common encodings
|
|
83
|
+
- Defaults to 'utf8' for invalid or null encodings
|
|
84
|
+
- Export: `@socketsecurity/lib/fs`
|
|
85
|
+
|
|
86
|
+
### Fixed
|
|
87
|
+
|
|
88
|
+
- **fs**: `safeReadFile()` and `safeReadFileSync()` type signatures and encoding handling
|
|
89
|
+
- Corrected type overloads: `encoding: null` → `Buffer | undefined`, no encoding → `string | undefined` (UTF-8 default)
|
|
90
|
+
- Fixed implementation to properly handle `encoding: null` for Buffer returns
|
|
91
|
+
|
|
92
|
+
- **suppress-warnings**: `withSuppressedWarnings()` now properly restores warning state
|
|
93
|
+
- Fixed state restoration to only remove warning types that were added by the function
|
|
94
|
+
- Prevents accidental removal of warnings that were already suppressed
|
|
95
|
+
- Ensures correct cleanup behavior when warning types are nested or reused
|
|
96
|
+
|
|
8
97
|
## [4.3.0](https://github.com/SocketDev/socket-lib/releases/tag/v4.3.0) - 2025-11-20
|
|
9
98
|
|
|
10
99
|
### Added
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://socket.dev/npm/package/@socketsecurity/lib)
|
|
4
4
|
[](https://github.com/SocketDev/socket-lib/actions/workflows/ci.yml)
|
|
5
|
-

|
|
6
6
|
|
|
7
7
|
[](https://twitter.com/SocketSecurity)
|
|
8
8
|
[](https://bsky.app/profile/socket.dev)
|
package/dist/constants/node.js
CHANGED
|
@@ -41,7 +41,7 @@ __export(node_exports, {
|
|
|
41
41
|
supportsProcessSend: () => supportsProcessSend
|
|
42
42
|
});
|
|
43
43
|
module.exports = __toCommonJS(node_exports);
|
|
44
|
-
var import_maintained_node_versions = require("
|
|
44
|
+
var import_maintained_node_versions = require("./maintained-node-versions");
|
|
45
45
|
const NODE_VERSION = process.version;
|
|
46
46
|
function getNodeVersion() {
|
|
47
47
|
return NODE_VERSION;
|
|
@@ -33,7 +33,7 @@ __export(package_default_node_range_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(package_default_node_range_exports);
|
|
35
35
|
var import_maintained_node_versions = require("./maintained-node-versions");
|
|
36
|
-
var semver = __toESM(require("
|
|
36
|
+
var semver = __toESM(require("../external/semver.js"));
|
|
37
37
|
const packageDefaultNodeRange = `>=${semver.parse(import_maintained_node_versions.maintainedNodeVersions.last).major}`;
|
|
38
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
39
|
0 && (module.exports = {
|
|
@@ -43,9 +43,9 @@ __export(packages_exports, {
|
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(packages_exports);
|
|
45
45
|
var import_npm = require("../env/npm");
|
|
46
|
-
var import_lifecycle_script_names = require("
|
|
47
|
-
var import_package_default_node_range = require("
|
|
48
|
-
var import_package_default_socket_categories = require("
|
|
46
|
+
var import_lifecycle_script_names = require("./lifecycle-script-names");
|
|
47
|
+
var import_package_default_node_range = require("./package-default-node-range");
|
|
48
|
+
var import_package_default_socket_categories = require("./package-default-socket-categories");
|
|
49
49
|
var import_package_extensions = require("../package-extensions");
|
|
50
50
|
var import_pacote = __toESM(require("../external/pacote"));
|
|
51
51
|
var import_normalize = require("../paths/normalize");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SpawnExtra, SpawnOptions } from '
|
|
2
|
-
import { spawn } from '
|
|
1
|
+
import type { SpawnExtra, SpawnOptions } from '../spawn';
|
|
2
|
+
import { spawn } from '../spawn';
|
|
3
3
|
export interface DlxBinaryOptions {
|
|
4
4
|
/**
|
|
5
5
|
* URL to download the binary from.
|
|
@@ -27,8 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
mod
|
|
28
28
|
));
|
|
29
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var
|
|
31
|
-
__export(
|
|
30
|
+
var binary_exports = {};
|
|
31
|
+
__export(binary_exports, {
|
|
32
32
|
cleanDlxCache: () => cleanDlxCache,
|
|
33
33
|
dlxBinary: () => dlxBinary,
|
|
34
34
|
downloadBinary: () => downloadBinary,
|
|
@@ -36,21 +36,21 @@ __export(dlx_binary_exports, {
|
|
|
36
36
|
getDlxCachePath: () => getDlxCachePath,
|
|
37
37
|
listDlxCache: () => listDlxCache
|
|
38
38
|
});
|
|
39
|
-
module.exports = __toCommonJS(
|
|
39
|
+
module.exports = __toCommonJS(binary_exports);
|
|
40
40
|
var import_crypto = require("crypto");
|
|
41
41
|
var import_os = __toESM(require("os"));
|
|
42
42
|
var import_path = __toESM(require("path"));
|
|
43
|
-
var import_platform = require("
|
|
44
|
-
var import_time = require("
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var import_http_request = require("
|
|
48
|
-
var import_fs = require("
|
|
49
|
-
var import_objects = require("
|
|
50
|
-
var import_normalize = require("
|
|
51
|
-
var import_socket = require("
|
|
52
|
-
var import_process_lock = require("
|
|
53
|
-
var import_spawn = require("
|
|
43
|
+
var import_platform = require("../constants/platform");
|
|
44
|
+
var import_time = require("../constants/time");
|
|
45
|
+
var import_cache = require("./cache");
|
|
46
|
+
var import_manifest = require("./manifest");
|
|
47
|
+
var import_http_request = require("../http-request");
|
|
48
|
+
var import_fs = require("../fs");
|
|
49
|
+
var import_objects = require("../objects");
|
|
50
|
+
var import_normalize = require("../paths/normalize");
|
|
51
|
+
var import_socket = require("../paths/socket");
|
|
52
|
+
var import_process_lock = require("../process-lock");
|
|
53
|
+
var import_spawn = require("../spawn");
|
|
54
54
|
let _fs;
|
|
55
55
|
// @__NO_SIDE_EFFECTS__
|
|
56
56
|
function getFs() {
|
|
@@ -152,7 +152,7 @@ async function writeMetadata(cacheEntryPath, cacheKey, url, binaryName, checksum
|
|
|
152
152
|
await fs.promises.writeFile(metaPath, JSON.stringify(metadata, null, 2));
|
|
153
153
|
try {
|
|
154
154
|
const spec = `${url}:${binaryName}`;
|
|
155
|
-
await
|
|
155
|
+
await import_manifest.dlxManifest.setBinaryEntry(spec, cacheKey, {
|
|
156
156
|
checksum,
|
|
157
157
|
checksum_algorithm: "sha256",
|
|
158
158
|
platform: import_os.default.platform(),
|
|
@@ -219,7 +219,7 @@ async function dlxBinary(args, options, spawnExtra) {
|
|
|
219
219
|
const cacheDir = getDlxCachePath();
|
|
220
220
|
const binaryName = name || `binary-${process.platform}-${import_os.default.arch()}`;
|
|
221
221
|
const spec = `${url}:${binaryName}`;
|
|
222
|
-
const cacheKey = (0,
|
|
222
|
+
const cacheKey = (0, import_cache.generateCacheKey)(spec);
|
|
223
223
|
const cacheEntryDir = import_path.default.join(cacheDir, cacheKey);
|
|
224
224
|
const binaryPath = (0, import_normalize.normalizePath)(import_path.default.join(cacheEntryDir, binaryName));
|
|
225
225
|
const fs = /* @__PURE__ */ getFs();
|
|
@@ -302,7 +302,7 @@ async function downloadBinary(options) {
|
|
|
302
302
|
const cacheDir = getDlxCachePath();
|
|
303
303
|
const binaryName = name || `binary-${process.platform}-${import_os.default.arch()}`;
|
|
304
304
|
const spec = `${url}:${binaryName}`;
|
|
305
|
-
const cacheKey = (0,
|
|
305
|
+
const cacheKey = (0, import_cache.generateCacheKey)(spec);
|
|
306
306
|
const cacheEntryDir = import_path.default.join(cacheDir, cacheKey);
|
|
307
307
|
const binaryPath = (0, import_normalize.normalizePath)(import_path.default.join(cacheEntryDir, binaryName));
|
|
308
308
|
const fs = /* @__PURE__ */ getFs();
|
|
@@ -0,0 +1,25 @@
|
|
|
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;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 cache_exports = {};
|
|
21
|
+
__export(cache_exports, {
|
|
22
|
+
generateCacheKey: () => generateCacheKey
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(cache_exports);
|
|
25
|
+
var import_node_crypto = require("node:crypto");
|
|
26
|
+
function generateCacheKey(spec) {
|
|
27
|
+
return (0, import_node_crypto.createHash)("sha512").update(spec).digest("hex").substring(0, 16);
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
generateCacheKey
|
|
32
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clear all DLX package installations.
|
|
3
|
+
*/
|
|
4
|
+
export declare function clearDlx(): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Clear all DLX package installations synchronously.
|
|
7
|
+
*/
|
|
8
|
+
export declare function clearDlxSync(): void;
|
|
9
|
+
/**
|
|
10
|
+
* Check if the DLX directory exists.
|
|
11
|
+
*/
|
|
12
|
+
export declare function dlxDirExists(): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Check if the DLX directory exists asynchronously.
|
|
15
|
+
*/
|
|
16
|
+
export declare function dlxDirExistsAsync(): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Ensure the DLX directory exists, creating it if necessary.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ensureDlxDir(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Ensure the DLX directory exists synchronously, creating it if necessary.
|
|
23
|
+
*/
|
|
24
|
+
export declare function ensureDlxDirSync(): void;
|
package/dist/dlx/dir.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
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 dir_exports = {};
|
|
21
|
+
__export(dir_exports, {
|
|
22
|
+
clearDlx: () => clearDlx,
|
|
23
|
+
clearDlxSync: () => clearDlxSync,
|
|
24
|
+
dlxDirExists: () => dlxDirExists,
|
|
25
|
+
dlxDirExistsAsync: () => dlxDirExistsAsync,
|
|
26
|
+
ensureDlxDir: () => ensureDlxDir,
|
|
27
|
+
ensureDlxDirSync: () => ensureDlxDirSync
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(dir_exports);
|
|
30
|
+
var import_fs = require("../fs");
|
|
31
|
+
var import_socket = require("../paths/socket");
|
|
32
|
+
var import_promises = require("../promises");
|
|
33
|
+
var import_packages = require("./packages");
|
|
34
|
+
let _fs;
|
|
35
|
+
// @__NO_SIDE_EFFECTS__
|
|
36
|
+
function getFs() {
|
|
37
|
+
if (_fs === void 0) {
|
|
38
|
+
_fs = require("node:fs");
|
|
39
|
+
}
|
|
40
|
+
return _fs;
|
|
41
|
+
}
|
|
42
|
+
async function clearDlx() {
|
|
43
|
+
const packages = await (0, import_packages.listDlxPackagesAsync)();
|
|
44
|
+
await (0, import_promises.pEach)(packages, (pkg) => (0, import_packages.removeDlxPackage)(pkg));
|
|
45
|
+
}
|
|
46
|
+
function clearDlxSync() {
|
|
47
|
+
const packages = (0, import_packages.listDlxPackages)();
|
|
48
|
+
for (const pkg of packages) {
|
|
49
|
+
(0, import_packages.removeDlxPackageSync)(pkg);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function dlxDirExists() {
|
|
53
|
+
const fs = /* @__PURE__ */ getFs();
|
|
54
|
+
return fs.existsSync((0, import_socket.getSocketDlxDir)());
|
|
55
|
+
}
|
|
56
|
+
async function dlxDirExistsAsync() {
|
|
57
|
+
const fs = /* @__PURE__ */ getFs();
|
|
58
|
+
try {
|
|
59
|
+
await fs.promises.access((0, import_socket.getSocketDlxDir)());
|
|
60
|
+
return true;
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function ensureDlxDir() {
|
|
66
|
+
await (0, import_fs.safeMkdir)((0, import_socket.getSocketDlxDir)());
|
|
67
|
+
}
|
|
68
|
+
function ensureDlxDirSync() {
|
|
69
|
+
(0, import_fs.safeMkdirSync)((0, import_socket.getSocketDlxDir)());
|
|
70
|
+
}
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
clearDlx,
|
|
74
|
+
clearDlxSync,
|
|
75
|
+
dlxDirExists,
|
|
76
|
+
dlxDirExistsAsync,
|
|
77
|
+
ensureDlxDir,
|
|
78
|
+
ensureDlxDirSync
|
|
79
|
+
});
|
|
@@ -27,20 +27,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
mod
|
|
28
28
|
));
|
|
29
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var
|
|
31
|
-
__export(
|
|
30
|
+
var manifest_exports = {};
|
|
31
|
+
__export(manifest_exports, {
|
|
32
32
|
DlxManifest: () => DlxManifest,
|
|
33
33
|
dlxManifest: () => dlxManifest,
|
|
34
34
|
isBinaryEntry: () => isBinaryEntry,
|
|
35
35
|
isPackageEntry: () => isPackageEntry
|
|
36
36
|
});
|
|
37
|
-
module.exports = __toCommonJS(
|
|
37
|
+
module.exports = __toCommonJS(manifest_exports);
|
|
38
38
|
var import_fs = require("fs");
|
|
39
39
|
var import_path = __toESM(require("path"));
|
|
40
|
-
var import_fs2 = require("
|
|
41
|
-
var import_logger = require("
|
|
42
|
-
var import_socket = require("
|
|
43
|
-
var import_process_lock = require("
|
|
40
|
+
var import_fs2 = require("../fs");
|
|
41
|
+
var import_logger = require("../logger");
|
|
42
|
+
var import_socket = require("../paths/socket");
|
|
43
|
+
var import_process_lock = require("../process-lock");
|
|
44
44
|
const logger = (0, import_logger.getDefaultLogger)();
|
|
45
45
|
const MANIFEST_FILE_NAME = ".dlx-manifest.json";
|
|
46
46
|
function isPackageEntry(entry) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SpawnExtra, SpawnOptions } from '
|
|
2
|
-
import { spawn } from '
|
|
1
|
+
import type { SpawnExtra, SpawnOptions } from '../spawn';
|
|
2
|
+
import { spawn } from '../spawn';
|
|
3
3
|
export interface DownloadPackageResult {
|
|
4
4
|
/** Path to the installed package directory. */
|
|
5
5
|
packageDir: string;
|
|
@@ -27,27 +27,27 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
mod
|
|
28
28
|
));
|
|
29
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var
|
|
31
|
-
__export(
|
|
30
|
+
var package_exports = {};
|
|
31
|
+
__export(package_exports, {
|
|
32
32
|
dlxPackage: () => dlxPackage,
|
|
33
33
|
downloadPackage: () => downloadPackage,
|
|
34
34
|
executePackage: () => executePackage
|
|
35
35
|
});
|
|
36
|
-
module.exports = __toCommonJS(
|
|
36
|
+
module.exports = __toCommonJS(package_exports);
|
|
37
37
|
var import_node_fs = __toESM(require("node:fs"));
|
|
38
38
|
var import_path = __toESM(require("path"));
|
|
39
|
-
var import_platform = require("
|
|
40
|
-
var import_packages = require("
|
|
41
|
-
var
|
|
42
|
-
var import_arborist = __toESM(require("
|
|
43
|
-
var import_libnpmexec = __toESM(require("
|
|
44
|
-
var import_npm_package_arg = __toESM(require("
|
|
45
|
-
var import_pacote = __toESM(require("
|
|
46
|
-
var import_fs = require("
|
|
47
|
-
var import_normalize = require("
|
|
48
|
-
var import_socket = require("
|
|
49
|
-
var import_process_lock = require("
|
|
50
|
-
var import_spawn = require("
|
|
39
|
+
var import_platform = require("../constants/platform");
|
|
40
|
+
var import_packages = require("../constants/packages");
|
|
41
|
+
var import_cache = require("./cache");
|
|
42
|
+
var import_arborist = __toESM(require("../external/@npmcli/arborist"));
|
|
43
|
+
var import_libnpmexec = __toESM(require("../external/libnpmexec"));
|
|
44
|
+
var import_npm_package_arg = __toESM(require("../external/npm-package-arg"));
|
|
45
|
+
var import_pacote = __toESM(require("../external/pacote"));
|
|
46
|
+
var import_fs = require("../fs");
|
|
47
|
+
var import_normalize = require("../paths/normalize");
|
|
48
|
+
var import_socket = require("../paths/socket");
|
|
49
|
+
var import_process_lock = require("../process-lock");
|
|
50
|
+
var import_spawn = require("../spawn");
|
|
51
51
|
const rangeOperatorsRegExp = /[~^><=xX* ]|\|\|/;
|
|
52
52
|
function parsePackageSpec(spec) {
|
|
53
53
|
try {
|
|
@@ -69,7 +69,7 @@ function parsePackageSpec(spec) {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
async function ensurePackageInstalled(packageName, packageSpec, force) {
|
|
72
|
-
const cacheKey = (0,
|
|
72
|
+
const cacheKey = (0, import_cache.generateCacheKey)(packageSpec);
|
|
73
73
|
const packageDir = (0, import_normalize.normalizePath)(import_path.default.join((0, import_socket.getSocketDlxDir)(), cacheKey));
|
|
74
74
|
const installedDir = (0, import_normalize.normalizePath)(
|
|
75
75
|
import_path.default.join(packageDir, "node_modules", packageName)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a package is installed in DLX.
|
|
3
|
+
*/
|
|
4
|
+
export declare function isDlxPackageInstalled(packageName: string): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Check if a package is installed in DLX asynchronously.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isDlxPackageInstalledAsync(packageName: string): Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* List all packages installed in DLX.
|
|
11
|
+
*/
|
|
12
|
+
export declare function listDlxPackages(): string[];
|
|
13
|
+
/**
|
|
14
|
+
* List all packages installed in DLX asynchronously.
|
|
15
|
+
*/
|
|
16
|
+
export declare function listDlxPackagesAsync(): Promise<string[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Remove a DLX package installation.
|
|
19
|
+
*/
|
|
20
|
+
export declare function removeDlxPackage(packageName: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Remove a DLX package installation synchronously.
|
|
23
|
+
*/
|
|
24
|
+
export declare function removeDlxPackageSync(packageName: string): void;
|
|
@@ -0,0 +1,125 @@
|
|
|
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 packages_exports = {};
|
|
21
|
+
__export(packages_exports, {
|
|
22
|
+
isDlxPackageInstalled: () => isDlxPackageInstalled,
|
|
23
|
+
isDlxPackageInstalledAsync: () => isDlxPackageInstalledAsync,
|
|
24
|
+
listDlxPackages: () => listDlxPackages,
|
|
25
|
+
listDlxPackagesAsync: () => listDlxPackagesAsync,
|
|
26
|
+
removeDlxPackage: () => removeDlxPackage,
|
|
27
|
+
removeDlxPackageSync: () => removeDlxPackageSync
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(packages_exports);
|
|
30
|
+
var import_fs = require("../fs");
|
|
31
|
+
var import_socket = require("../paths/socket");
|
|
32
|
+
var import_paths = require("./paths");
|
|
33
|
+
let _fs;
|
|
34
|
+
// @__NO_SIDE_EFFECTS__
|
|
35
|
+
function getFs() {
|
|
36
|
+
if (_fs === void 0) {
|
|
37
|
+
_fs = require("node:fs");
|
|
38
|
+
}
|
|
39
|
+
return _fs;
|
|
40
|
+
}
|
|
41
|
+
function isDlxPackageInstalled(packageName) {
|
|
42
|
+
const fs = /* @__PURE__ */ getFs();
|
|
43
|
+
return fs.existsSync((0, import_paths.getDlxInstalledPackageDir)(packageName));
|
|
44
|
+
}
|
|
45
|
+
async function isDlxPackageInstalledAsync(packageName) {
|
|
46
|
+
const fs = /* @__PURE__ */ getFs();
|
|
47
|
+
try {
|
|
48
|
+
await fs.promises.access((0, import_paths.getDlxInstalledPackageDir)(packageName));
|
|
49
|
+
return true;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function listDlxPackages() {
|
|
55
|
+
try {
|
|
56
|
+
return (0, import_fs.readDirNamesSync)((0, import_socket.getSocketDlxDir)(), { sort: true });
|
|
57
|
+
} catch {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function listDlxPackagesAsync() {
|
|
62
|
+
const fs = /* @__PURE__ */ getFs();
|
|
63
|
+
try {
|
|
64
|
+
const entries = await fs.promises.readdir((0, import_socket.getSocketDlxDir)(), {
|
|
65
|
+
withFileTypes: true
|
|
66
|
+
});
|
|
67
|
+
return entries.filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
68
|
+
} catch {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function removeDlxPackage(packageName) {
|
|
73
|
+
const packageDir = (0, import_paths.getDlxPackageDir)(packageName);
|
|
74
|
+
try {
|
|
75
|
+
await (0, import_fs.safeDelete)(packageDir, { recursive: true, force: true });
|
|
76
|
+
} catch (e) {
|
|
77
|
+
throw new Error(`Failed to remove DLX package "${packageName}"`, {
|
|
78
|
+
cause: e
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function removeDlxPackageSync(packageName) {
|
|
83
|
+
const fs = /* @__PURE__ */ getFs();
|
|
84
|
+
const packageDir = (0, import_paths.getDlxPackageDir)(packageName);
|
|
85
|
+
try {
|
|
86
|
+
fs.rmSync(packageDir, { recursive: true, force: true });
|
|
87
|
+
} catch (e) {
|
|
88
|
+
const code = e.code;
|
|
89
|
+
if (code === "EACCES" || code === "EPERM") {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`Permission denied removing DLX package "${packageName}"
|
|
92
|
+
Directory: ${packageDir}
|
|
93
|
+
To resolve:
|
|
94
|
+
1. Check file/directory permissions
|
|
95
|
+
2. Close any programs using files in this directory
|
|
96
|
+
3. Try running with elevated privileges if necessary
|
|
97
|
+
4. Manually remove: rm -rf "${packageDir}"`,
|
|
98
|
+
{ cause: e }
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
if (code === "EROFS") {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`Cannot remove DLX package "${packageName}" from read-only filesystem
|
|
104
|
+
Directory: ${packageDir}
|
|
105
|
+
The filesystem is mounted read-only.`,
|
|
106
|
+
{ cause: e }
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
throw new Error(
|
|
110
|
+
`Failed to remove DLX package "${packageName}"
|
|
111
|
+
Directory: ${packageDir}
|
|
112
|
+
Check permissions and ensure no programs are using this directory.`,
|
|
113
|
+
{ cause: e }
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
isDlxPackageInstalled,
|
|
120
|
+
isDlxPackageInstalledAsync,
|
|
121
|
+
listDlxPackages,
|
|
122
|
+
listDlxPackagesAsync,
|
|
123
|
+
removeDlxPackage,
|
|
124
|
+
removeDlxPackageSync
|
|
125
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the installed package directory within DLX node_modules.
|
|
3
|
+
*/
|
|
4
|
+
export declare function getDlxInstalledPackageDir(packageName: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Get the DLX installation directory for a specific package.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getDlxPackageDir(packageName: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Get the package.json path for a DLX installed package.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getDlxPackageJsonPath(packageName: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Get the node_modules directory for a DLX package installation.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getDlxPackageNodeModulesDir(packageName: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Check if a file path is within the Socket DLX directory.
|
|
19
|
+
* This is useful for determining if a binary or file is managed by Socket's DLX system.
|
|
20
|
+
*
|
|
21
|
+
* @param filePath - Absolute or relative path to check
|
|
22
|
+
* @returns true if the path is within ~/.socket/_dlx/, false otherwise
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* isInSocketDlx('/home/user/.socket/_dlx/abc123/bin/socket') // true
|
|
27
|
+
* isInSocketDlx('/usr/local/bin/socket') // false
|
|
28
|
+
* isInSocketDlx(process.argv[0]) // Check if current binary is in DLX
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function isInSocketDlx(filePath: string): boolean;
|