@socketsecurity/lib 5.3.0 → 5.4.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.
- package/CHANGELOG.md +22 -0
- package/dist/cover/code.js +12 -4
- package/dist/dlx/cache.js +10 -2
- package/dist/dlx/manifest.js +45 -41
- package/dist/env/rewire.js +10 -2
- package/dist/external/@inquirer/checkbox.js +4 -2528
- package/dist/external/@inquirer/confirm.js +4 -2371
- package/dist/external/@inquirer/input.js +4 -2395
- package/dist/external/@inquirer/password.js +4 -2503
- package/dist/external/@inquirer/search.js +4 -2500
- package/dist/external/@inquirer/select.js +4 -2617
- package/dist/external/@npmcli/package-json.js +11 -7
- package/dist/external/debug.js +670 -15
- package/dist/external/del.js +4 -7139
- package/dist/external/external-pack.js +4795 -0
- package/dist/external/fast-glob.js +4 -5776
- package/dist/external/has-flag.js +6 -0
- package/dist/external/libnpmexec.js +2 -2
- package/dist/external/normalize-package-data.js +2 -2
- package/dist/external/npm-pack.js +1698 -3337
- package/dist/external/npm-package-arg.js +2 -2
- package/dist/external/pico-pack.js +7162 -0
- package/dist/external/picomatch.js +4 -1523
- package/dist/external/semver.js +2 -2
- package/dist/external/signal-exit.js +5 -0
- package/dist/external/spdx-correct.js +4 -1384
- package/dist/external/spdx-expression-parse.js +4 -1047
- package/dist/external/spdx-pack.js +1640 -0
- package/dist/external/supports-color.js +8 -0
- package/dist/external/validate-npm-package-name.js +4 -104
- package/dist/external/yoctocolors-cjs.js +5 -92
- package/dist/http-request.js +10 -2
- package/dist/ipc.js +53 -29
- package/dist/packages/isolation.js +45 -23
- package/dist/packages/licenses.js +10 -2
- package/dist/paths/socket.d.ts +2 -2
- package/dist/paths/socket.js +27 -21
- package/dist/process-lock.js +23 -14
- package/dist/releases/github.d.ts +67 -41
- package/dist/releases/github.js +142 -100
- package/dist/releases/socket-btm.d.ts +40 -33
- package/dist/releases/socket-btm.js +45 -5
- package/dist/spawn.js +10 -3
- package/dist/stdio/mask.d.ts +6 -21
- package/dist/stdio/mask.js +18 -14
- package/dist/themes/context.js +10 -2
- package/package.json +16 -3
- package/dist/external/npm-core.js +0 -6588
package/dist/releases/github.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 github_exports = {};
|
|
21
31
|
__export(github_exports, {
|
|
@@ -27,26 +37,13 @@ __export(github_exports, {
|
|
|
27
37
|
getReleaseAssetUrl: () => getReleaseAssetUrl
|
|
28
38
|
});
|
|
29
39
|
module.exports = __toCommonJS(github_exports);
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var import_fs2 = require("../fs.js");
|
|
40
|
+
var import_picomatch = __toESM(require("../external/picomatch.js"));
|
|
41
|
+
var import_fs = require("../fs.js");
|
|
33
42
|
var import_http_request = require("../http-request.js");
|
|
34
43
|
var import_logger = require("../logger.js");
|
|
35
|
-
var
|
|
44
|
+
var import_promises = require("../promises.js");
|
|
36
45
|
var import_spawn = require("../spawn.js");
|
|
37
46
|
const logger = (0, import_logger.getDefaultLogger)();
|
|
38
|
-
let _path;
|
|
39
|
-
// @__NO_SIDE_EFFECTS__
|
|
40
|
-
function getPath() {
|
|
41
|
-
if (_path === void 0) {
|
|
42
|
-
_path = require("path");
|
|
43
|
-
}
|
|
44
|
-
return _path;
|
|
45
|
-
}
|
|
46
|
-
const SOCKET_BTM_REPO = {
|
|
47
|
-
owner: "SocketDev",
|
|
48
|
-
repo: "socket-btm"
|
|
49
|
-
};
|
|
50
47
|
const RETRY_CONFIG = Object.freeze({
|
|
51
48
|
__proto__: null,
|
|
52
49
|
// Exponential backoff: delay doubles with each retry (5s, 10s, 20s).
|
|
@@ -56,93 +53,52 @@ const RETRY_CONFIG = Object.freeze({
|
|
|
56
53
|
// Maximum number of retry attempts (excluding initial request).
|
|
57
54
|
retries: 2
|
|
58
55
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
owner,
|
|
66
|
-
platformArch,
|
|
67
|
-
quiet = false,
|
|
68
|
-
removeMacOSQuarantine = true,
|
|
69
|
-
repo,
|
|
70
|
-
tag: explicitTag,
|
|
71
|
-
toolName,
|
|
72
|
-
toolPrefix
|
|
73
|
-
} = config;
|
|
74
|
-
let tag;
|
|
75
|
-
if (explicitTag) {
|
|
76
|
-
tag = explicitTag;
|
|
77
|
-
} else if (toolPrefix) {
|
|
78
|
-
const latestTag = await getLatestRelease(
|
|
79
|
-
toolPrefix,
|
|
80
|
-
{ owner, repo },
|
|
81
|
-
{ quiet }
|
|
82
|
-
);
|
|
83
|
-
if (!latestTag) {
|
|
84
|
-
throw new Error(`No ${toolPrefix} release found in ${owner}/${repo}`);
|
|
85
|
-
}
|
|
86
|
-
tag = latestTag;
|
|
87
|
-
} else {
|
|
88
|
-
throw new Error("Either toolPrefix or tag must be provided");
|
|
89
|
-
}
|
|
90
|
-
const path = /* @__PURE__ */ getPath();
|
|
91
|
-
const resolvedDownloadDir = path.isAbsolute(downloadDir) ? downloadDir : path.join(cwd, downloadDir);
|
|
92
|
-
const binaryDir = path.join(resolvedDownloadDir, toolName, platformArch);
|
|
93
|
-
const binaryPath = path.join(binaryDir, binaryName);
|
|
94
|
-
const versionPath = path.join(binaryDir, ".version");
|
|
95
|
-
if ((0, import_fs.existsSync)(versionPath) && (0, import_fs.existsSync)(binaryPath)) {
|
|
96
|
-
const cachedVersion = (await (0, import_promises.readFile)(versionPath, "utf8")).trim();
|
|
97
|
-
if (cachedVersion === tag) {
|
|
98
|
-
if (!quiet) {
|
|
99
|
-
logger.info(`Using cached ${toolName} (${platformArch}): ${binaryPath}`);
|
|
100
|
-
}
|
|
101
|
-
return binaryPath;
|
|
102
|
-
}
|
|
56
|
+
let _fs;
|
|
57
|
+
let _path;
|
|
58
|
+
function createMatcher(pattern) {
|
|
59
|
+
if (typeof pattern === "string") {
|
|
60
|
+
const isMatch = (0, import_picomatch.default)(pattern);
|
|
61
|
+
return (input) => isMatch(input);
|
|
103
62
|
}
|
|
104
|
-
if (
|
|
105
|
-
|
|
63
|
+
if (pattern instanceof RegExp) {
|
|
64
|
+
return (input) => pattern.test(input);
|
|
106
65
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const isWindows = binaryName.endsWith(".exe");
|
|
115
|
-
if (!isWindows) {
|
|
116
|
-
(0, import_fs.chmodSync)(binaryPath, 493);
|
|
117
|
-
if (removeMacOSQuarantine && process.platform === "darwin" && platformArch.startsWith("darwin")) {
|
|
118
|
-
try {
|
|
119
|
-
await (0, import_spawn.spawn)("xattr", ["-d", "com.apple.quarantine", binaryPath], {
|
|
120
|
-
stdio: "ignore"
|
|
121
|
-
});
|
|
122
|
-
} catch {
|
|
123
|
-
}
|
|
124
|
-
}
|
|
66
|
+
const { prefix, suffix } = pattern;
|
|
67
|
+
return (input) => input.startsWith(prefix) && input.endsWith(suffix);
|
|
68
|
+
}
|
|
69
|
+
// @__NO_SIDE_EFFECTS__
|
|
70
|
+
function getFs() {
|
|
71
|
+
if (_fs === void 0) {
|
|
72
|
+
_fs = require("fs");
|
|
125
73
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
74
|
+
return _fs;
|
|
75
|
+
}
|
|
76
|
+
// @__NO_SIDE_EFFECTS__
|
|
77
|
+
function getPath() {
|
|
78
|
+
if (_path === void 0) {
|
|
79
|
+
_path = require("path");
|
|
129
80
|
}
|
|
130
|
-
return
|
|
81
|
+
return _path;
|
|
131
82
|
}
|
|
132
|
-
|
|
83
|
+
const SOCKET_BTM_REPO = {
|
|
84
|
+
owner: "SocketDev",
|
|
85
|
+
repo: "socket-btm"
|
|
86
|
+
};
|
|
87
|
+
async function downloadReleaseAsset(tag, assetPattern, outputPath, repoConfig, options = {}) {
|
|
133
88
|
const { owner, repo } = repoConfig;
|
|
134
89
|
const { quiet = false } = options;
|
|
135
90
|
const downloadUrl = await getReleaseAssetUrl(
|
|
136
91
|
tag,
|
|
137
|
-
|
|
92
|
+
assetPattern,
|
|
138
93
|
{ owner, repo },
|
|
139
94
|
{ quiet }
|
|
140
95
|
);
|
|
141
96
|
if (!downloadUrl) {
|
|
142
|
-
|
|
97
|
+
const patternDesc = typeof assetPattern === "string" ? assetPattern : "matching pattern";
|
|
98
|
+
throw new Error(`Asset ${patternDesc} not found in release ${tag}`);
|
|
143
99
|
}
|
|
144
100
|
const path = /* @__PURE__ */ getPath();
|
|
145
|
-
await (0,
|
|
101
|
+
await (0, import_fs.safeMkdir)(path.dirname(outputPath));
|
|
146
102
|
await (0, import_http_request.httpDownload)(downloadUrl, outputPath, {
|
|
147
103
|
logger: quiet ? void 0 : logger,
|
|
148
104
|
progressInterval: 10,
|
|
@@ -162,9 +118,10 @@ function getAuthHeaders() {
|
|
|
162
118
|
return headers;
|
|
163
119
|
}
|
|
164
120
|
async function getLatestRelease(toolPrefix, repoConfig, options = {}) {
|
|
121
|
+
const { assetPattern, quiet = false } = options;
|
|
165
122
|
const { owner, repo } = repoConfig;
|
|
166
|
-
const
|
|
167
|
-
return await (0,
|
|
123
|
+
const isMatch = assetPattern ? createMatcher(assetPattern) : void 0;
|
|
124
|
+
return await (0, import_promises.pRetry)(
|
|
168
125
|
async () => {
|
|
169
126
|
const response = await (0, import_http_request.httpRequest)(
|
|
170
127
|
`https://api.github.com/repos/${owner}/${repo}/releases?per_page=100`,
|
|
@@ -177,13 +134,22 @@ async function getLatestRelease(toolPrefix, repoConfig, options = {}) {
|
|
|
177
134
|
}
|
|
178
135
|
const releases = JSON.parse(response.body.toString("utf8"));
|
|
179
136
|
for (const release of releases) {
|
|
180
|
-
const { tag_name: tag } = release;
|
|
181
|
-
if (tag.startsWith(toolPrefix)) {
|
|
182
|
-
|
|
183
|
-
|
|
137
|
+
const { assets, tag_name: tag } = release;
|
|
138
|
+
if (!tag.startsWith(toolPrefix)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (isMatch) {
|
|
142
|
+
const hasMatchingAsset = assets.some(
|
|
143
|
+
(a) => isMatch(a.name)
|
|
144
|
+
);
|
|
145
|
+
if (!hasMatchingAsset) {
|
|
146
|
+
continue;
|
|
184
147
|
}
|
|
185
|
-
return tag;
|
|
186
148
|
}
|
|
149
|
+
if (!quiet) {
|
|
150
|
+
logger.info(`Found release: ${tag}`);
|
|
151
|
+
}
|
|
152
|
+
return tag;
|
|
187
153
|
}
|
|
188
154
|
if (!quiet) {
|
|
189
155
|
logger.info(`No ${toolPrefix} release found in latest 100 releases`);
|
|
@@ -206,10 +172,11 @@ async function getLatestRelease(toolPrefix, repoConfig, options = {}) {
|
|
|
206
172
|
}
|
|
207
173
|
);
|
|
208
174
|
}
|
|
209
|
-
async function getReleaseAssetUrl(tag,
|
|
175
|
+
async function getReleaseAssetUrl(tag, assetPattern, repoConfig, options = {}) {
|
|
210
176
|
const { owner, repo } = repoConfig;
|
|
211
177
|
const { quiet = false } = options;
|
|
212
|
-
|
|
178
|
+
const isMatch = typeof assetPattern === "string" && !assetPattern.includes("*") && !assetPattern.includes("{") ? (input) => input === assetPattern : createMatcher(assetPattern);
|
|
179
|
+
return await (0, import_promises.pRetry)(
|
|
213
180
|
async () => {
|
|
214
181
|
const response = await (0, import_http_request.httpRequest)(
|
|
215
182
|
`https://api.github.com/repos/${owner}/${repo}/releases/tags/${tag}`,
|
|
@@ -222,13 +189,14 @@ async function getReleaseAssetUrl(tag, assetName, repoConfig, options = {}) {
|
|
|
222
189
|
}
|
|
223
190
|
const release = JSON.parse(response.body.toString("utf8"));
|
|
224
191
|
const asset = release.assets.find(
|
|
225
|
-
(a) => a.name
|
|
192
|
+
(a) => isMatch(a.name)
|
|
226
193
|
);
|
|
227
194
|
if (!asset) {
|
|
228
|
-
|
|
195
|
+
const patternDesc = typeof assetPattern === "string" ? assetPattern : "matching pattern";
|
|
196
|
+
throw new Error(`Asset ${patternDesc} not found in release ${tag}`);
|
|
229
197
|
}
|
|
230
198
|
if (!quiet) {
|
|
231
|
-
logger.info(`Found asset: ${
|
|
199
|
+
logger.info(`Found asset: ${asset.name}`);
|
|
232
200
|
}
|
|
233
201
|
return asset.browser_download_url;
|
|
234
202
|
},
|
|
@@ -248,6 +216,80 @@ async function getReleaseAssetUrl(tag, assetName, repoConfig, options = {}) {
|
|
|
248
216
|
}
|
|
249
217
|
);
|
|
250
218
|
}
|
|
219
|
+
async function downloadGitHubRelease(config) {
|
|
220
|
+
const {
|
|
221
|
+
assetName,
|
|
222
|
+
binaryName,
|
|
223
|
+
cwd = process.cwd(),
|
|
224
|
+
downloadDir = "build/downloaded",
|
|
225
|
+
owner,
|
|
226
|
+
platformArch,
|
|
227
|
+
quiet = false,
|
|
228
|
+
removeMacOSQuarantine = true,
|
|
229
|
+
repo,
|
|
230
|
+
tag: explicitTag,
|
|
231
|
+
toolName,
|
|
232
|
+
toolPrefix
|
|
233
|
+
} = config;
|
|
234
|
+
let tag;
|
|
235
|
+
if (explicitTag) {
|
|
236
|
+
tag = explicitTag;
|
|
237
|
+
} else if (toolPrefix) {
|
|
238
|
+
const latestTag = await getLatestRelease(
|
|
239
|
+
toolPrefix,
|
|
240
|
+
{ owner, repo },
|
|
241
|
+
{ quiet }
|
|
242
|
+
);
|
|
243
|
+
if (!latestTag) {
|
|
244
|
+
throw new Error(`No ${toolPrefix} release found in ${owner}/${repo}`);
|
|
245
|
+
}
|
|
246
|
+
tag = latestTag;
|
|
247
|
+
} else {
|
|
248
|
+
throw new Error("Either toolPrefix or tag must be provided");
|
|
249
|
+
}
|
|
250
|
+
const path = /* @__PURE__ */ getPath();
|
|
251
|
+
const resolvedDownloadDir = path.isAbsolute(downloadDir) ? downloadDir : path.join(cwd, downloadDir);
|
|
252
|
+
const binaryDir = path.join(resolvedDownloadDir, toolName, platformArch);
|
|
253
|
+
const binaryPath = path.join(binaryDir, binaryName);
|
|
254
|
+
const versionPath = path.join(binaryDir, ".version");
|
|
255
|
+
const fs = /* @__PURE__ */ getFs();
|
|
256
|
+
if (fs.existsSync(versionPath) && fs.existsSync(binaryPath)) {
|
|
257
|
+
const cachedVersion = (await fs.promises.readFile(versionPath, "utf8")).trim();
|
|
258
|
+
if (cachedVersion === tag) {
|
|
259
|
+
if (!quiet) {
|
|
260
|
+
logger.info(`Using cached ${toolName} (${platformArch}): ${binaryPath}`);
|
|
261
|
+
}
|
|
262
|
+
return binaryPath;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (!quiet) {
|
|
266
|
+
logger.info(`Downloading ${toolName} for ${platformArch}...`);
|
|
267
|
+
}
|
|
268
|
+
await downloadReleaseAsset(
|
|
269
|
+
tag,
|
|
270
|
+
assetName,
|
|
271
|
+
binaryPath,
|
|
272
|
+
{ owner, repo },
|
|
273
|
+
{ quiet }
|
|
274
|
+
);
|
|
275
|
+
const isWindows = binaryName.endsWith(".exe");
|
|
276
|
+
if (!isWindows) {
|
|
277
|
+
fs.chmodSync(binaryPath, 493);
|
|
278
|
+
if (removeMacOSQuarantine && process.platform === "darwin" && platformArch.startsWith("darwin")) {
|
|
279
|
+
try {
|
|
280
|
+
await (0, import_spawn.spawn)("xattr", ["-d", "com.apple.quarantine", binaryPath], {
|
|
281
|
+
stdio: "ignore"
|
|
282
|
+
});
|
|
283
|
+
} catch {
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
await fs.promises.writeFile(versionPath, tag, "utf8");
|
|
288
|
+
if (!quiet) {
|
|
289
|
+
logger.info(`Downloaded ${toolName} to ${binaryPath}`);
|
|
290
|
+
}
|
|
291
|
+
return binaryPath;
|
|
292
|
+
}
|
|
251
293
|
// Annotate the CommonJS export names for ESM import in node:
|
|
252
294
|
0 && (module.exports = {
|
|
253
295
|
SOCKET_BTM_REPO,
|
|
@@ -1,57 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Socket-btm release download utilities.
|
|
3
|
+
*/
|
|
1
4
|
import { type Arch, type Libc, type Platform } from '../constants/platform.js';
|
|
5
|
+
import { type AssetPattern } from './github.js';
|
|
2
6
|
export type { Arch, Libc, Platform };
|
|
3
7
|
/**
|
|
4
|
-
* Configuration for downloading socket-btm
|
|
8
|
+
* Configuration for downloading socket-btm generic assets.
|
|
5
9
|
*/
|
|
6
|
-
export interface
|
|
10
|
+
export interface SocketBtmAssetConfig {
|
|
11
|
+
/** Asset name or pattern on GitHub. */
|
|
12
|
+
asset: string | AssetPattern;
|
|
13
|
+
/** @internal Discriminator fields */
|
|
14
|
+
bin?: never;
|
|
7
15
|
/** Working directory (defaults to process.cwd()). */
|
|
8
16
|
cwd?: string;
|
|
9
17
|
/** Download destination directory. @default 'build/downloaded' */
|
|
10
18
|
downloadDir?: string;
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
/** Target platform (defaults to current platform). */
|
|
16
|
-
targetPlatform?: Platform;
|
|
17
|
-
/** Target architecture (defaults to current arch). */
|
|
18
|
-
targetArch?: Arch;
|
|
19
|
-
/** Linux libc variant. Auto-detected if not specified. */
|
|
20
|
-
libc?: Libc;
|
|
21
|
-
/** Specific release tag to download. */
|
|
22
|
-
tag?: string;
|
|
19
|
+
/** @internal Discriminator fields */
|
|
20
|
+
libc?: never;
|
|
21
|
+
/** Output filename. @default resolved asset name */
|
|
22
|
+
output?: string;
|
|
23
23
|
/** Suppress log messages. @default false */
|
|
24
24
|
quiet?: boolean;
|
|
25
|
-
/** Remove macOS quarantine attribute after download. @default
|
|
25
|
+
/** Remove macOS quarantine attribute after download. @default false */
|
|
26
26
|
removeMacOSQuarantine?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
|
|
27
|
+
/** Specific release tag to download. */
|
|
28
|
+
tag?: string;
|
|
29
|
+
/** @internal Discriminator fields */
|
|
30
|
+
targetArch?: never;
|
|
31
|
+
/** @internal Discriminator fields */
|
|
32
|
+
targetPlatform?: never;
|
|
33
|
+
/** Tool/package name for directory structure and release matching. */
|
|
34
|
+
tool: string;
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
31
|
-
* Configuration for downloading socket-btm
|
|
37
|
+
* Configuration for downloading socket-btm binary releases.
|
|
32
38
|
*/
|
|
33
|
-
export interface
|
|
39
|
+
export interface SocketBtmBinaryConfig {
|
|
40
|
+
/** @internal Discriminator field */
|
|
41
|
+
asset?: never;
|
|
42
|
+
/** Binary/executable name (without extension). @default tool */
|
|
43
|
+
bin?: string;
|
|
34
44
|
/** Working directory (defaults to process.cwd()). */
|
|
35
45
|
cwd?: string;
|
|
36
46
|
/** Download destination directory. @default 'build/downloaded' */
|
|
37
47
|
downloadDir?: string;
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
/** Asset name pattern on GitHub. */
|
|
41
|
-
asset: string;
|
|
42
|
-
/** Output filename. @default asset */
|
|
43
|
-
output?: string;
|
|
44
|
-
/** Specific release tag to download. */
|
|
45
|
-
tag?: string;
|
|
48
|
+
/** Linux libc variant. Auto-detected if not specified. */
|
|
49
|
+
libc?: Libc;
|
|
46
50
|
/** Suppress log messages. @default false */
|
|
47
51
|
quiet?: boolean;
|
|
48
|
-
/** Remove macOS quarantine attribute after download. @default
|
|
52
|
+
/** Remove macOS quarantine attribute after download. @default true */
|
|
49
53
|
removeMacOSQuarantine?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
targetArch?:
|
|
54
|
-
|
|
54
|
+
/** Specific release tag to download. */
|
|
55
|
+
tag?: string;
|
|
56
|
+
/** Target architecture (defaults to current arch). */
|
|
57
|
+
targetArch?: Arch;
|
|
58
|
+
/** Target platform (defaults to current platform). */
|
|
59
|
+
targetPlatform?: Platform;
|
|
60
|
+
/** Tool/package name for directory structure and release matching. */
|
|
61
|
+
tool: string;
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
57
64
|
* Configuration for downloading socket-btm releases (binary or asset).
|
|
@@ -26,18 +26,27 @@ __export(socket_btm_exports, {
|
|
|
26
26
|
getPlatformArch: () => getPlatformArch
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(socket_btm_exports);
|
|
29
|
-
var import_fs = require("fs");
|
|
30
29
|
var import_platform = require("../constants/platform.js");
|
|
31
30
|
var import_github = require("./github.js");
|
|
32
31
|
const ARCH_MAP = {
|
|
32
|
+
__proto__: null,
|
|
33
33
|
arm64: "arm64",
|
|
34
34
|
x64: "x64"
|
|
35
35
|
};
|
|
36
|
+
let _fs;
|
|
37
|
+
// @__NO_SIDE_EFFECTS__
|
|
38
|
+
function getFs() {
|
|
39
|
+
if (_fs === void 0) {
|
|
40
|
+
_fs = require("fs");
|
|
41
|
+
}
|
|
42
|
+
return _fs;
|
|
43
|
+
}
|
|
36
44
|
function detectLibc() {
|
|
37
45
|
if ((0, import_platform.getPlatform)() !== "linux") {
|
|
38
46
|
return void 0;
|
|
39
47
|
}
|
|
40
48
|
try {
|
|
49
|
+
const fs = /* @__PURE__ */ getFs();
|
|
41
50
|
const muslPaths = [
|
|
42
51
|
"/lib/ld-musl-x86_64.so.1",
|
|
43
52
|
"/lib/ld-musl-aarch64.so.1",
|
|
@@ -45,7 +54,7 @@ function detectLibc() {
|
|
|
45
54
|
"/usr/lib/ld-musl-aarch64.so.1"
|
|
46
55
|
];
|
|
47
56
|
for (const path of muslPaths) {
|
|
48
|
-
if (
|
|
57
|
+
if (fs.existsSync(path)) {
|
|
49
58
|
return "musl";
|
|
50
59
|
}
|
|
51
60
|
}
|
|
@@ -64,7 +73,38 @@ async function downloadSocketBtmRelease(config) {
|
|
|
64
73
|
output,
|
|
65
74
|
removeMacOSQuarantine = false
|
|
66
75
|
} = config;
|
|
67
|
-
|
|
76
|
+
let resolvedAsset;
|
|
77
|
+
let resolvedTag = tag;
|
|
78
|
+
const isExactMatch = typeof asset === "string" && !asset.includes("*");
|
|
79
|
+
if (isExactMatch) {
|
|
80
|
+
resolvedAsset = asset;
|
|
81
|
+
} else {
|
|
82
|
+
if (tag) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
"Cannot use asset pattern with explicit tag. Either provide exact asset name or omit tag."
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
resolvedTag = await (0, import_github.getLatestRelease)(toolPrefix, import_github.SOCKET_BTM_REPO, {
|
|
88
|
+
assetPattern: asset,
|
|
89
|
+
quiet
|
|
90
|
+
});
|
|
91
|
+
if (!resolvedTag) {
|
|
92
|
+
throw new Error(`No ${tool} release with matching asset pattern found`);
|
|
93
|
+
}
|
|
94
|
+
const assetUrl = await (0, import_github.getReleaseAssetUrl)(
|
|
95
|
+
resolvedTag,
|
|
96
|
+
asset,
|
|
97
|
+
import_github.SOCKET_BTM_REPO,
|
|
98
|
+
{
|
|
99
|
+
quiet
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
if (!assetUrl) {
|
|
103
|
+
throw new Error(`No matching asset found in release ${resolvedTag}`);
|
|
104
|
+
}
|
|
105
|
+
resolvedAsset = assetUrl.split("/").pop() || asset.toString();
|
|
106
|
+
}
|
|
107
|
+
const outputName = output || resolvedAsset;
|
|
68
108
|
const platformArch = "assets";
|
|
69
109
|
downloadConfig = {
|
|
70
110
|
owner: import_github.SOCKET_BTM_REPO.owner,
|
|
@@ -74,9 +114,9 @@ async function downloadSocketBtmRelease(config) {
|
|
|
74
114
|
toolName: tool,
|
|
75
115
|
platformArch,
|
|
76
116
|
binaryName: outputName,
|
|
77
|
-
assetName:
|
|
117
|
+
assetName: resolvedAsset,
|
|
78
118
|
toolPrefix,
|
|
79
|
-
tag,
|
|
119
|
+
tag: resolvedTag,
|
|
80
120
|
quiet,
|
|
81
121
|
removeMacOSQuarantine
|
|
82
122
|
};
|
package/dist/spawn.js
CHANGED
|
@@ -37,13 +37,20 @@ __export(spawn_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(spawn_exports);
|
|
38
38
|
var import_process = require("./constants/process");
|
|
39
39
|
var import_promise_spawn = __toESM(require("./external/@npmcli/promise-spawn"));
|
|
40
|
-
var import_node_path = __toESM(require("node:path"));
|
|
41
40
|
var import_arrays = require("./arrays");
|
|
42
41
|
var import_bin = require("./bin");
|
|
43
42
|
var import_normalize = require("./paths/normalize");
|
|
44
43
|
var import_objects = require("./objects");
|
|
45
44
|
var import_spinner = require("./spinner");
|
|
46
45
|
var import_strings = require("./strings");
|
|
46
|
+
let _path;
|
|
47
|
+
// @__NO_SIDE_EFFECTS__
|
|
48
|
+
function getPath() {
|
|
49
|
+
if (_path === void 0) {
|
|
50
|
+
_path = require("path");
|
|
51
|
+
}
|
|
52
|
+
return _path;
|
|
53
|
+
}
|
|
47
54
|
const abortSignal = (0, import_process.getAbortSignal)();
|
|
48
55
|
const spinner = (0, import_spinner.getDefaultSpinner)();
|
|
49
56
|
const windowsScriptExtRegExp = /\.(?:cmd|bat|ps1)$/i;
|
|
@@ -102,7 +109,7 @@ function spawn(cmd, args, options, extra) {
|
|
|
102
109
|
}
|
|
103
110
|
const WIN32 = process.platform === "win32";
|
|
104
111
|
if (WIN32 && shell && windowsScriptExtRegExp.test(actualCmd)) {
|
|
105
|
-
actualCmd =
|
|
112
|
+
actualCmd = (/* @__PURE__ */ getPath()).basename(actualCmd, (/* @__PURE__ */ getPath()).extname(actualCmd));
|
|
106
113
|
}
|
|
107
114
|
const wasSpinning = !!spinnerInstance?.isSpinning;
|
|
108
115
|
const shouldStopSpinner = wasSpinning && !/* @__PURE__ */ isStdioType(stdio, "ignore") && !/* @__PURE__ */ isStdioType(stdio, "pipe");
|
|
@@ -181,7 +188,7 @@ function spawnSync(cmd, args, options) {
|
|
|
181
188
|
const shell = (0, import_objects.getOwn)(options, "shell");
|
|
182
189
|
const WIN32 = process.platform === "win32";
|
|
183
190
|
if (WIN32 && shell && windowsScriptExtRegExp.test(actualCmd)) {
|
|
184
|
-
actualCmd =
|
|
191
|
+
actualCmd = (/* @__PURE__ */ getPath()).basename(actualCmd, (/* @__PURE__ */ getPath()).extname(actualCmd));
|
|
185
192
|
}
|
|
186
193
|
const { stripAnsi: shouldStripAnsi = true, ...rawSpawnOptions } = {
|
|
187
194
|
__proto__: null,
|
package/dist/stdio/mask.d.ts
CHANGED
|
@@ -1,24 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Interactive output masking utilities for CLI tools.
|
|
3
|
-
* Provides output control with keyboard toggling (ctrl+o).
|
|
4
|
-
*
|
|
5
|
-
* ANSI Escape Sequences Used:
|
|
6
|
-
* - '\r': Carriage return - moves cursor to beginning of current line.
|
|
7
|
-
* - '\x1b[K' or '\x1b[0K': CSI K (erase line) - clear from cursor to end of line.
|
|
8
|
-
* - '\x1b[2K': CSI 2K - erase entire line.
|
|
9
|
-
* - '\x1b[1A': CSI A - move cursor up 1 line.
|
|
10
|
-
*
|
|
11
|
-
* Terminal Control:
|
|
12
|
-
* - Raw mode (setRawMode(true)): Captures keypresses immediately without buffering.
|
|
13
|
-
* - TTY detection: Ensures terminal manipulation only occurs in interactive terminals.
|
|
14
|
-
*
|
|
15
|
-
* Key Features:
|
|
16
|
-
* - Output buffering: Stores up to 1000 lines when masked to prevent memory issues.
|
|
17
|
-
* - Graceful cleanup: Always restores terminal to normal mode on exit/error.
|
|
18
|
-
* - Visual feedback: Uses spinner to indicate process is running when output is masked.
|
|
19
|
-
*/
|
|
20
1
|
import type { ChildProcess, SpawnOptions } from 'child_process';
|
|
21
|
-
import readline from 'readline';
|
|
22
2
|
export interface OutputMaskOptions {
|
|
23
3
|
/**
|
|
24
4
|
* Current working directory for spawned process.
|
|
@@ -120,7 +100,11 @@ export declare function createOutputMask(options?: OutputMaskOptions): OutputMas
|
|
|
120
100
|
* - ctrl+c: Cancel the running process.
|
|
121
101
|
* The handler manipulates terminal state using ANSI escape sequences.
|
|
122
102
|
*/
|
|
123
|
-
|
|
103
|
+
type ReadlineKey = {
|
|
104
|
+
ctrl?: boolean;
|
|
105
|
+
name?: string;
|
|
106
|
+
};
|
|
107
|
+
export declare function createKeyboardHandler(mask: OutputMask, child: ChildProcess, options?: OutputMaskOptions): (_str: string, key: ReadlineKey) => void;
|
|
124
108
|
/**
|
|
125
109
|
* Attach output masking to a child process.
|
|
126
110
|
* Returns a promise that resolves with the exit code.
|
|
@@ -138,3 +122,4 @@ export declare function attachOutputMask(child: ChildProcess, options?: OutputMa
|
|
|
138
122
|
* stdin is inherited, stdout and stderr are piped for masking control.
|
|
139
123
|
*/
|
|
140
124
|
export declare function runWithMask(command: string, args?: string[], options?: OutputMaskOptions & SpawnOptions): Promise<number>;
|
|
125
|
+
export {};
|
package/dist/stdio/mask.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* Socket Lib - Built with esbuild */
|
|
3
|
-
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
7
|
var __export = (target, all) => {
|
|
10
8
|
for (var name in all)
|
|
@@ -18,14 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
16
|
}
|
|
19
17
|
return to;
|
|
20
18
|
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
20
|
var mask_exports = {};
|
|
31
21
|
__export(mask_exports, {
|
|
@@ -35,11 +25,25 @@ __export(mask_exports, {
|
|
|
35
25
|
runWithMask: () => runWithMask
|
|
36
26
|
});
|
|
37
27
|
module.exports = __toCommonJS(mask_exports);
|
|
38
|
-
var import_child_process = require("child_process");
|
|
39
|
-
var import_readline = __toESM(require("readline"));
|
|
40
28
|
var import_spinner = require("../spinner.js");
|
|
41
29
|
var import_clear = require("./clear.js");
|
|
42
30
|
var import_stdout = require("./stdout.js");
|
|
31
|
+
let _child_process;
|
|
32
|
+
// @__NO_SIDE_EFFECTS__
|
|
33
|
+
function getChildProcess() {
|
|
34
|
+
if (_child_process === void 0) {
|
|
35
|
+
_child_process = require("child_process");
|
|
36
|
+
}
|
|
37
|
+
return _child_process;
|
|
38
|
+
}
|
|
39
|
+
let _readline;
|
|
40
|
+
// @__NO_SIDE_EFFECTS__
|
|
41
|
+
function getReadline() {
|
|
42
|
+
if (_readline === void 0) {
|
|
43
|
+
_readline = require("readline");
|
|
44
|
+
}
|
|
45
|
+
return _readline;
|
|
46
|
+
}
|
|
43
47
|
const spinner = (0, import_spinner.getDefaultSpinner)();
|
|
44
48
|
function createOutputMask(options = {}) {
|
|
45
49
|
const { showOutput = false } = options;
|
|
@@ -101,7 +105,7 @@ function attachOutputMask(child, options = {}) {
|
|
|
101
105
|
);
|
|
102
106
|
}
|
|
103
107
|
if (process.stdin.isTTY) {
|
|
104
|
-
|
|
108
|
+
(/* @__PURE__ */ getReadline()).emitKeypressEvents(process.stdin);
|
|
105
109
|
process.stdin.setRawMode(true);
|
|
106
110
|
const keypressHandler = createKeyboardHandler(mask, child, options);
|
|
107
111
|
process.stdin.on("keypress", keypressHandler);
|
|
@@ -194,7 +198,7 @@ async function runWithMask(command, args = [], options = {}) {
|
|
|
194
198
|
toggleText = "to see output",
|
|
195
199
|
...spawnOptions
|
|
196
200
|
} = options;
|
|
197
|
-
const child = (
|
|
201
|
+
const child = (/* @__PURE__ */ getChildProcess()).spawn(command, args, {
|
|
198
202
|
stdio: ["inherit", "pipe", "pipe"],
|
|
199
203
|
...spawnOptions
|
|
200
204
|
});
|