@socketsecurity/lib 5.2.1 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,156 +1,53 @@
1
- /**
2
- * Platform type for socket-btm binaries.
3
- */
4
- export type Platform = 'darwin' | 'linux' | 'win32';
5
- /**
6
- * Architecture type for socket-btm binaries.
7
- */
8
- export type Arch = 'arm64' | 'x64';
9
- /**
10
- * Linux libc variant.
11
- */
12
- export type Libc = 'musl' | 'glibc';
1
+ import { type Arch, type Libc, type Platform } from '../constants/platform.js';
2
+ export type { Arch, Libc, Platform };
13
3
  /**
14
4
  * Configuration for downloading socket-btm binary releases.
15
5
  */
16
6
  export interface SocketBtmBinaryConfig {
17
- /**
18
- * Working directory (defaults to process.cwd()).
19
- */
7
+ /** Working directory (defaults to process.cwd()). */
20
8
  cwd?: string;
21
- /**
22
- * Download destination directory.
23
- * Can be absolute or relative to cwd.
24
- * @default 'build/downloaded' (relative to cwd)
25
- *
26
- * Inspired by: gh release download --dir
27
- */
9
+ /** Download destination directory. @default 'build/downloaded' */
28
10
  downloadDir?: string;
29
- /**
30
- * Tool/package name for directory structure and release matching.
31
- * Similar to: brew install <formula>, cargo install <crate>
32
- *
33
- * Examples: 'node-smol', 'binject', 'binflate'
34
- *
35
- * Used for:
36
- * - Directory path: {downloadDir}/{tool}/{platformArch}/
37
- * - Finding release: Searches for tags starting with '{tool}-'
38
- */
11
+ /** Tool/package name for directory structure and release matching. */
39
12
  tool: string;
40
- /**
41
- * Binary/executable name (without extension).
42
- * Similar to: brew formula→binary mapping (postgresql→psql, imagemagick→magick)
43
- *
44
- * Examples: 'node', 'binject', 'psql', 'magick'
45
- *
46
- * Used to construct:
47
- * - Asset pattern: {bin}-{platform}-{arch}[-musl][.exe]
48
- * - Output filename: {bin} or {bin}.exe
49
- *
50
- * Presence of this field indicates binary download (vs asset download).
51
- *
52
- * @default tool (e.g., 'binject'→'binject', but 'node-smol'→'node-smol')
53
- */
13
+ /** Binary/executable name (without extension). @default tool */
54
14
  bin?: string;
55
- /**
56
- * Target platform (defaults to current platform).
57
- */
15
+ /** Target platform (defaults to current platform). */
58
16
  targetPlatform?: Platform;
59
- /**
60
- * Target architecture (defaults to current arch).
61
- */
17
+ /** Target architecture (defaults to current arch). */
62
18
  targetArch?: Arch;
63
- /**
64
- * Linux libc variant (musl or glibc).
65
- * Defaults to musl for Linux for broader compatibility.
66
- * Ignored for non-Linux platforms.
67
- */
19
+ /** Linux libc variant. Auto-detected if not specified. */
68
20
  libc?: Libc;
69
- /**
70
- * Specific release tag to download.
71
- * Inspired by: gh release download <tag>
72
- *
73
- * If not provided, downloads the latest release matching '{tool}-*' pattern.
74
- *
75
- * Examples: 'node-smol-20260105-c47753c', 'binject-20260106-1df5745'
76
- */
21
+ /** Specific release tag to download. */
77
22
  tag?: string;
78
- /**
79
- * Suppress log messages.
80
- * @default false
81
- */
23
+ /** Suppress log messages. @default false */
82
24
  quiet?: boolean;
83
- /**
84
- * Remove macOS quarantine attribute after download.
85
- * Only applies when downloading on macOS for macOS binaries.
86
- * @default true
87
- */
25
+ /** Remove macOS quarantine attribute after download. @default true */
88
26
  removeMacOSQuarantine?: boolean;
89
- // Discriminator: presence of 'asset' means this is NOT a binary config
27
+ /** @internal Discriminator field */
90
28
  asset?: never;
91
29
  }
92
30
  /**
93
31
  * Configuration for downloading socket-btm generic assets.
94
32
  */
95
33
  export interface SocketBtmAssetConfig {
96
- /**
97
- * Working directory (defaults to process.cwd()).
98
- */
34
+ /** Working directory (defaults to process.cwd()). */
99
35
  cwd?: string;
100
- /**
101
- * Download destination directory.
102
- * Can be absolute or relative to cwd.
103
- * @default 'build/downloaded' (relative to cwd)
104
- *
105
- * Inspired by: gh release download --dir
106
- */
36
+ /** Download destination directory. @default 'build/downloaded' */
107
37
  downloadDir?: string;
108
- /**
109
- * Tool/package name for directory structure and release matching.
110
- *
111
- * Examples: 'yoga-layout', 'onnxruntime', 'models'
112
- *
113
- * Used for:
114
- * - Directory path: {downloadDir}/{tool}/assets/
115
- * - Finding release: Searches for tags starting with '{tool}-'
116
- */
38
+ /** Tool/package name for directory structure and release matching. */
117
39
  tool: string;
118
- /**
119
- * Asset name pattern on GitHub.
120
- * Inspired by: gh release download --pattern
121
- *
122
- * Examples: 'yoga-sync.mjs', 'ort-wasm-simd.wasm', '*.onnx'
123
- *
124
- * Presence of this field indicates asset download (vs binary download).
125
- */
40
+ /** Asset name pattern on GitHub. */
126
41
  asset: string;
127
- /**
128
- * Output filename (e.g., 'yoga-sync.mjs').
129
- * Inspired by: gh release download --output
130
- *
131
- * @default asset (uses the asset name as-is)
132
- */
42
+ /** Output filename. @default asset */
133
43
  output?: string;
134
- /**
135
- * Specific release tag to download.
136
- * Inspired by: gh release download <tag>
137
- *
138
- * If not provided, downloads the latest release matching '{tool}-*' pattern.
139
- *
140
- * Examples: 'yoga-layout-v20260106-a39285c', 'onnxruntime-v20260106-a39285c'
141
- */
44
+ /** Specific release tag to download. */
142
45
  tag?: string;
143
- /**
144
- * Suppress log messages.
145
- * @default false
146
- */
46
+ /** Suppress log messages. @default false */
147
47
  quiet?: boolean;
148
- /**
149
- * Remove macOS quarantine attribute after download.
150
- * @default false (not needed for non-executable assets)
151
- */
48
+ /** Remove macOS quarantine attribute after download. @default false */
152
49
  removeMacOSQuarantine?: boolean;
153
- // Discriminators: mutually exclusive with binary-specific fields
50
+ /** @internal Discriminator fields */
154
51
  bin?: never;
155
52
  targetPlatform?: never;
156
53
  targetArch?: never;
@@ -161,61 +58,43 @@ export interface SocketBtmAssetConfig {
161
58
  */
162
59
  export type SocketBtmReleaseConfig = SocketBtmBinaryConfig | SocketBtmAssetConfig;
163
60
  /**
164
- * Download a release from socket-btm.
61
+ * Detect the libc variant (musl or glibc) on Linux systems.
62
+ * Returns undefined for non-Linux platforms.
165
63
  *
166
- * Generic function for downloading any socket-btm binary or asset.
167
- * Handles both platform-specific binaries and generic assets.
64
+ * @returns 'musl', 'glibc', or undefined (for non-Linux)
65
+ */
66
+ export declare function detectLibc(): Libc | undefined;
67
+ /**
68
+ * Download a release from socket-btm.
168
69
  *
169
70
  * @param config - Download configuration
170
71
  * @returns Path to the downloaded file
72
+ */
73
+ export declare function downloadSocketBtmRelease(config: SocketBtmReleaseConfig): Promise<string>;
74
+ /**
75
+ * Get asset name for a socket-btm binary.
171
76
  *
172
- * @example
173
- * ```ts
174
- * // Binary: node-smol (like: brew install nodejs → node)
175
- * const nodePath = await downloadSocketBtmRelease({
176
- * tool: 'node-smol',
177
- * bin: 'node'
178
- * })
179
- *
180
- * // Binary: binject (like: cargo install binject → binject)
181
- * const binjectPath = await downloadSocketBtmRelease({
182
- * tool: 'binject'
183
- * })
184
- *
185
- * // Binary: cross-platform
186
- * const binflatePath = await downloadSocketBtmRelease({
187
- * tool: 'binflate',
188
- * targetPlatform: 'linux',
189
- * targetArch: 'x64',
190
- * libc: 'musl'
191
- * })
192
- *
193
- * // Asset: WASM file
194
- * const yogaPath = await downloadSocketBtmRelease({
195
- * tool: 'yoga-layout',
196
- * asset: 'yoga-sync.mjs'
197
- * })
198
- *
199
- * // Asset: with custom output name
200
- * const ortPath = await downloadSocketBtmRelease({
201
- * tool: 'onnxruntime',
202
- * asset: 'ort-wasm-simd.wasm',
203
- * output: 'ort.wasm'
204
- * })
77
+ * @param binaryBaseName - Binary basename (e.g., 'binject', 'node')
78
+ * @param platform - Target platform
79
+ * @param arch - Target architecture
80
+ * @param libc - Linux libc variant (optional)
81
+ * @returns Asset name (e.g., 'binject-darwin-arm64', 'node-linux-x64-musl')
82
+ */
83
+ export declare function getBinaryAssetName(binaryBaseName: string, platform: Platform, arch: Arch, libc?: Libc | undefined): string;
84
+ /**
85
+ * Get binary filename for output.
205
86
  *
206
- * // Custom paths (like: gh release download --dir)
207
- * await downloadSocketBtmRelease({
208
- * tool: 'node-smol',
209
- * bin: 'node',
210
- * cwd: '/path/to/project',
211
- * downloadDir: 'build/cache'
212
- * })
87
+ * @param binaryBaseName - Binary basename (e.g., 'node', 'binject')
88
+ * @param platform - Target platform
89
+ * @returns Binary filename (e.g., 'node', 'node.exe')
90
+ */
91
+ export declare function getBinaryName(binaryBaseName: string, platform: Platform): string;
92
+ /**
93
+ * Get platform-arch identifier for directory structure.
213
94
  *
214
- * // Specific version (like: gh release download <tag>)
215
- * await downloadSocketBtmRelease({
216
- * tool: 'binject',
217
- * tag: 'binject-20260106-1df5745'
218
- * })
219
- * ```
95
+ * @param platform - Target platform
96
+ * @param arch - Target architecture
97
+ * @param libc - Linux libc variant (optional)
98
+ * @returns Platform-arch identifier (e.g., 'darwin-arm64', 'linux-x64-musl')
220
99
  */
221
- export declare function downloadSocketBtmRelease(config: SocketBtmReleaseConfig): Promise<string>;
100
+ export declare function getPlatformArch(platform: Platform, arch: Arch, libc?: Libc | undefined): string;
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
- var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
7
  var __export = (target, all) => {
10
8
  for (var name in all)
@@ -18,54 +16,43 @@ var __copyProps = (to, from, except, desc) => {
18
16
  }
19
17
  return to;
20
18
  };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
20
  var socket_btm_exports = {};
31
21
  __export(socket_btm_exports, {
32
- downloadSocketBtmRelease: () => downloadSocketBtmRelease
22
+ detectLibc: () => detectLibc,
23
+ downloadSocketBtmRelease: () => downloadSocketBtmRelease,
24
+ getBinaryAssetName: () => getBinaryAssetName,
25
+ getBinaryName: () => getBinaryName,
26
+ getPlatformArch: () => getPlatformArch
33
27
  });
34
28
  module.exports = __toCommonJS(socket_btm_exports);
35
- var import_node_os = __toESM(require("node:os"));
29
+ var import_fs = require("fs");
30
+ var import_platform = require("../constants/platform.js");
36
31
  var import_github = require("./github.js");
37
32
  const ARCH_MAP = {
38
33
  arm64: "arm64",
39
34
  x64: "x64"
40
35
  };
41
- function getBinaryAssetName(binaryBaseName, platform, arch, libc) {
42
- const mappedArch = ARCH_MAP[arch];
43
- if (!mappedArch) {
44
- throw new Error(`Unsupported architecture: ${arch}`);
36
+ function detectLibc() {
37
+ if ((0, import_platform.getPlatform)() !== "linux") {
38
+ return void 0;
45
39
  }
46
- const muslSuffix = platform === "linux" && libc === "musl" ? "-musl" : "";
47
- const ext = platform === "win32" ? ".exe" : "";
48
- if (platform === "darwin") {
49
- return `${binaryBaseName}-darwin-${mappedArch}${ext}`;
40
+ try {
41
+ const muslPaths = [
42
+ "/lib/ld-musl-x86_64.so.1",
43
+ "/lib/ld-musl-aarch64.so.1",
44
+ "/usr/lib/ld-musl-x86_64.so.1",
45
+ "/usr/lib/ld-musl-aarch64.so.1"
46
+ ];
47
+ for (const path of muslPaths) {
48
+ if ((0, import_fs.existsSync)(path)) {
49
+ return "musl";
50
+ }
51
+ }
52
+ return "glibc";
53
+ } catch {
54
+ return "glibc";
50
55
  }
51
- if (platform === "linux") {
52
- return `${binaryBaseName}-linux-${mappedArch}${muslSuffix}${ext}`;
53
- }
54
- if (platform === "win32") {
55
- return `${binaryBaseName}-win-${mappedArch}${ext}`;
56
- }
57
- throw new Error(`Unsupported platform: ${platform}`);
58
- }
59
- function getPlatformArch(platform, arch, libc) {
60
- const mappedArch = ARCH_MAP[arch];
61
- if (!mappedArch) {
62
- throw new Error(`Unsupported architecture: ${arch}`);
63
- }
64
- const muslSuffix = platform === "linux" && libc === "musl" ? "-musl" : "";
65
- return `${platform}-${mappedArch}${muslSuffix}`;
66
- }
67
- function getBinaryName(binaryBaseName, platform) {
68
- return platform === "win32" ? `${binaryBaseName}.exe` : binaryBaseName;
69
56
  }
70
57
  async function downloadSocketBtmRelease(config) {
71
58
  const { cwd, downloadDir, quiet = false, tag, tool } = config;
@@ -96,18 +83,20 @@ async function downloadSocketBtmRelease(config) {
96
83
  } else {
97
84
  const {
98
85
  bin,
99
- libc,
86
+ libc = detectLibc(),
100
87
  removeMacOSQuarantine = true,
101
- targetArch,
102
- targetPlatform
88
+ targetArch = (0, import_platform.getArch)(),
89
+ targetPlatform = (0, import_platform.getPlatform)()
103
90
  } = config;
104
91
  const baseName = bin || tool;
105
- const platform = targetPlatform || import_node_os.default.platform();
106
- const arch = targetArch || import_node_os.default.arch();
107
- const libcType = libc || (platform === "linux" ? "musl" : void 0);
108
- const assetName = getBinaryAssetName(baseName, platform, arch, libcType);
109
- const platformArch = getPlatformArch(platform, arch, libcType);
110
- const binaryName = getBinaryName(baseName, platform);
92
+ const assetName = getBinaryAssetName(
93
+ baseName,
94
+ targetPlatform,
95
+ targetArch,
96
+ libc
97
+ );
98
+ const platformArch = getPlatformArch(targetPlatform, targetArch, libc);
99
+ const binaryName = getBinaryName(baseName, targetPlatform);
111
100
  downloadConfig = {
112
101
  owner: import_github.SOCKET_BTM_REPO.owner,
113
102
  repo: import_github.SOCKET_BTM_REPO.repo,
@@ -125,7 +114,40 @@ async function downloadSocketBtmRelease(config) {
125
114
  }
126
115
  return await (0, import_github.downloadGitHubRelease)(downloadConfig);
127
116
  }
117
+ function getBinaryAssetName(binaryBaseName, platform, arch, libc) {
118
+ const mappedArch = ARCH_MAP[arch];
119
+ if (!mappedArch) {
120
+ throw new Error(`Unsupported architecture: ${arch}`);
121
+ }
122
+ const muslSuffix = platform === "linux" && libc === "musl" ? "-musl" : "";
123
+ const ext = platform === "win32" ? ".exe" : "";
124
+ if (platform === "darwin") {
125
+ return `${binaryBaseName}-darwin-${mappedArch}${ext}`;
126
+ }
127
+ if (platform === "linux") {
128
+ return `${binaryBaseName}-linux-${mappedArch}${muslSuffix}${ext}`;
129
+ }
130
+ if (platform === "win32") {
131
+ return `${binaryBaseName}-win-${mappedArch}${ext}`;
132
+ }
133
+ throw new Error(`Unsupported platform: ${platform}`);
134
+ }
135
+ function getBinaryName(binaryBaseName, platform) {
136
+ return platform === "win32" ? `${binaryBaseName}.exe` : binaryBaseName;
137
+ }
138
+ function getPlatformArch(platform, arch, libc) {
139
+ const mappedArch = ARCH_MAP[arch];
140
+ if (!mappedArch) {
141
+ throw new Error(`Unsupported architecture: ${arch}`);
142
+ }
143
+ const muslSuffix = platform === "linux" && libc === "musl" ? "-musl" : "";
144
+ return `${platform}-${mappedArch}${muslSuffix}`;
145
+ }
128
146
  // Annotate the CommonJS export names for ESM import in node:
129
147
  0 && (module.exports = {
130
- downloadSocketBtmRelease
148
+ detectLibc,
149
+ downloadSocketBtmRelease,
150
+ getBinaryAssetName,
151
+ getBinaryName,
152
+ getPlatformArch
131
153
  });
@@ -35,7 +35,7 @@ let _events;
35
35
  // @__NO_SIDE_EFFECTS__
36
36
  function getEvents() {
37
37
  if (_events === void 0) {
38
- _events = require("node:events");
38
+ _events = require("events");
39
39
  }
40
40
  return _events;
41
41
  }
package/dist/spawn.js CHANGED
@@ -51,7 +51,7 @@ let _child_process;
51
51
  // @__NO_SIDE_EFFECTS__
52
52
  function getChildProcess() {
53
53
  if (_child_process === void 0) {
54
- _child_process = require("node:child_process");
54
+ _child_process = require("child_process");
55
55
  }
56
56
  return _child_process;
57
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socketsecurity/lib",
3
- "version": "5.2.1",
3
+ "version": "5.3.0",
4
4
  "packageManager": "pnpm@10.27.0",
5
5
  "license": "MIT",
6
6
  "description": "Core utilities and infrastructure for Socket.dev security tools",
@@ -722,7 +722,7 @@
722
722
  "@socketregistry/is-unicode-supported": "1.0.5",
723
723
  "@socketregistry/packageurl-js": "1.3.5",
724
724
  "@socketregistry/yocto-spinner": "1.0.25",
725
- "@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.2.0",
725
+ "@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.2.1",
726
726
  "@types/node": "24.9.2",
727
727
  "@typescript/native-preview": "7.0.0-dev.20250920.1",
728
728
  "@vitest/coverage-v8": "4.0.3",