@socketsecurity/lib 5.6.0 → 5.7.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 +64 -1
- package/dist/cache-with-ttl.js +5 -1
- package/dist/dlx/binary.d.ts +20 -0
- package/dist/dlx/binary.js +115 -99
- package/dist/dlx/detect.d.ts +8 -8
- package/dist/dlx/detect.js +18 -18
- package/dist/dlx/manifest.d.ts +32 -31
- package/dist/dlx/manifest.js +114 -112
- package/dist/dlx/package.d.ts +55 -0
- package/dist/dlx/package.js +89 -79
- package/dist/env/ci.js +1 -2
- package/dist/env/rewire.d.ts +33 -22
- package/dist/env/rewire.js +20 -7
- package/dist/env/socket-cli.d.ts +24 -24
- package/dist/env/socket-cli.js +12 -12
- package/dist/env/temp-dir.d.ts +6 -6
- package/dist/env/temp-dir.js +4 -4
- package/dist/env/windows.d.ts +6 -6
- package/dist/env/windows.js +4 -4
- package/dist/github.js +10 -1
- package/dist/packages/specs.js +1 -1
- package/dist/releases/github.d.ts +18 -7
- package/dist/releases/github.js +94 -92
- package/package.json +1 -1
package/dist/env/socket-cli.d.ts
CHANGED
|
@@ -38,6 +38,22 @@ export declare function getSocketCliApiTimeout(): number;
|
|
|
38
38
|
*/
|
|
39
39
|
/*@__NO_SIDE_EFFECTS__*/
|
|
40
40
|
export declare function getSocketCliApiToken(): string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Bootstrap cache directory path.
|
|
43
|
+
* Set by bootstrap wrappers to pass dlx cache location to CLI.
|
|
44
|
+
*
|
|
45
|
+
* @returns Bootstrap cache directory or undefined
|
|
46
|
+
*/
|
|
47
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
48
|
+
export declare function getSocketCliBootstrapCacheDir(): string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Bootstrap package spec (e.g., @socketsecurity/cli@^2.0.11).
|
|
51
|
+
* Set by bootstrap wrappers (SEA/smol/npm) to pass package spec to CLI.
|
|
52
|
+
*
|
|
53
|
+
* @returns Bootstrap package spec or undefined
|
|
54
|
+
*/
|
|
55
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
56
|
+
export declare function getSocketCliBootstrapSpec(): string | undefined;
|
|
41
57
|
/**
|
|
42
58
|
* Socket CLI configuration file path (alternative name).
|
|
43
59
|
*
|
|
@@ -52,6 +68,14 @@ export declare function getSocketCliConfig(): string | undefined;
|
|
|
52
68
|
*/
|
|
53
69
|
/*@__NO_SIDE_EFFECTS__*/
|
|
54
70
|
export declare function getSocketCliFix(): string | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Socket CLI GitHub authentication token.
|
|
73
|
+
* Checks SOCKET_CLI_GITHUB_TOKEN, SOCKET_SECURITY_GITHUB_PAT, then falls back to GITHUB_TOKEN.
|
|
74
|
+
*
|
|
75
|
+
* @returns GitHub token or undefined
|
|
76
|
+
*/
|
|
77
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
78
|
+
export declare function getSocketCliGithubToken(): string | undefined;
|
|
55
79
|
/**
|
|
56
80
|
* Whether to skip Socket CLI API token requirement (alternative name).
|
|
57
81
|
*
|
|
@@ -81,27 +105,3 @@ export declare function getSocketCliOrgSlug(): string | undefined;
|
|
|
81
105
|
*/
|
|
82
106
|
/*@__NO_SIDE_EFFECTS__*/
|
|
83
107
|
export declare function getSocketCliViewAllRisks(): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Socket CLI GitHub authentication token.
|
|
86
|
-
* Checks SOCKET_CLI_GITHUB_TOKEN, SOCKET_SECURITY_GITHUB_PAT, then falls back to GITHUB_TOKEN.
|
|
87
|
-
*
|
|
88
|
-
* @returns GitHub token or undefined
|
|
89
|
-
*/
|
|
90
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
91
|
-
export declare function getSocketCliGithubToken(): string | undefined;
|
|
92
|
-
/**
|
|
93
|
-
* Bootstrap package spec (e.g., @socketsecurity/cli@^2.0.11).
|
|
94
|
-
* Set by bootstrap wrappers (SEA/smol/npm) to pass package spec to CLI.
|
|
95
|
-
*
|
|
96
|
-
* @returns Bootstrap package spec or undefined
|
|
97
|
-
*/
|
|
98
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
99
|
-
export declare function getSocketCliBootstrapSpec(): string | undefined;
|
|
100
|
-
/**
|
|
101
|
-
* Bootstrap cache directory path.
|
|
102
|
-
* Set by bootstrap wrappers to pass dlx cache location to CLI.
|
|
103
|
-
*
|
|
104
|
-
* @returns Bootstrap cache directory or undefined
|
|
105
|
-
*/
|
|
106
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
107
|
-
export declare function getSocketCliBootstrapCacheDir(): string | undefined;
|
package/dist/env/socket-cli.js
CHANGED
|
@@ -58,6 +58,14 @@ function getSocketCliApiToken() {
|
|
|
58
58
|
return (0, import_rewire.getEnvValue)("SOCKET_CLI_API_TOKEN") || (0, import_rewire.getEnvValue)("SOCKET_CLI_API_KEY") || (0, import_rewire.getEnvValue)("SOCKET_SECURITY_API_TOKEN") || (0, import_rewire.getEnvValue)("SOCKET_SECURITY_API_KEY");
|
|
59
59
|
}
|
|
60
60
|
// @__NO_SIDE_EFFECTS__
|
|
61
|
+
function getSocketCliBootstrapCacheDir() {
|
|
62
|
+
return (0, import_rewire.getEnvValue)("SOCKET_CLI_BOOTSTRAP_CACHE_DIR");
|
|
63
|
+
}
|
|
64
|
+
// @__NO_SIDE_EFFECTS__
|
|
65
|
+
function getSocketCliBootstrapSpec() {
|
|
66
|
+
return (0, import_rewire.getEnvValue)("SOCKET_CLI_BOOTSTRAP_SPEC");
|
|
67
|
+
}
|
|
68
|
+
// @__NO_SIDE_EFFECTS__
|
|
61
69
|
function getSocketCliConfig() {
|
|
62
70
|
return (0, import_rewire.getEnvValue)("SOCKET_CLI_CONFIG");
|
|
63
71
|
}
|
|
@@ -66,6 +74,10 @@ function getSocketCliFix() {
|
|
|
66
74
|
return (0, import_rewire.getEnvValue)("SOCKET_CLI_FIX");
|
|
67
75
|
}
|
|
68
76
|
// @__NO_SIDE_EFFECTS__
|
|
77
|
+
function getSocketCliGithubToken() {
|
|
78
|
+
return (0, import_rewire.getEnvValue)("SOCKET_CLI_GITHUB_TOKEN") || (0, import_rewire.getEnvValue)("SOCKET_SECURITY_GITHUB_PAT") || (0, import_rewire.getEnvValue)("GITHUB_TOKEN");
|
|
79
|
+
}
|
|
80
|
+
// @__NO_SIDE_EFFECTS__
|
|
69
81
|
function getSocketCliNoApiToken() {
|
|
70
82
|
return (0, import_helpers.envAsBoolean)((0, import_rewire.getEnvValue)("SOCKET_CLI_NO_API_TOKEN"));
|
|
71
83
|
}
|
|
@@ -81,18 +93,6 @@ function getSocketCliOrgSlug() {
|
|
|
81
93
|
function getSocketCliViewAllRisks() {
|
|
82
94
|
return (0, import_helpers.envAsBoolean)((0, import_rewire.getEnvValue)("SOCKET_CLI_VIEW_ALL_RISKS"));
|
|
83
95
|
}
|
|
84
|
-
// @__NO_SIDE_EFFECTS__
|
|
85
|
-
function getSocketCliGithubToken() {
|
|
86
|
-
return (0, import_rewire.getEnvValue)("SOCKET_CLI_GITHUB_TOKEN") || (0, import_rewire.getEnvValue)("SOCKET_SECURITY_GITHUB_PAT") || (0, import_rewire.getEnvValue)("GITHUB_TOKEN");
|
|
87
|
-
}
|
|
88
|
-
// @__NO_SIDE_EFFECTS__
|
|
89
|
-
function getSocketCliBootstrapSpec() {
|
|
90
|
-
return (0, import_rewire.getEnvValue)("SOCKET_CLI_BOOTSTRAP_SPEC");
|
|
91
|
-
}
|
|
92
|
-
// @__NO_SIDE_EFFECTS__
|
|
93
|
-
function getSocketCliBootstrapCacheDir() {
|
|
94
|
-
return (0, import_rewire.getEnvValue)("SOCKET_CLI_BOOTSTRAP_CACHE_DIR");
|
|
95
|
-
}
|
|
96
96
|
// Annotate the CommonJS export names for ESM import in node:
|
|
97
97
|
0 && (module.exports = {
|
|
98
98
|
getSocketCliAcceptRisks,
|
package/dist/env/temp-dir.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TMPDIR environment variable.
|
|
3
|
-
* Unix/macOS temporary directory path.
|
|
4
|
-
*/
|
|
5
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
6
|
-
export declare function getTmpdir(): string | undefined;
|
|
7
1
|
/**
|
|
8
2
|
* TEMP environment variable.
|
|
9
3
|
* Windows temporary directory path.
|
|
@@ -16,3 +10,9 @@ export declare function getTemp(): string | undefined;
|
|
|
16
10
|
*/
|
|
17
11
|
/*@__NO_SIDE_EFFECTS__*/
|
|
18
12
|
export declare function getTmp(): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* TMPDIR environment variable.
|
|
15
|
+
* Unix/macOS temporary directory path.
|
|
16
|
+
*/
|
|
17
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
18
|
+
export declare function getTmpdir(): string | undefined;
|
package/dist/env/temp-dir.js
CHANGED
|
@@ -26,10 +26,6 @@ __export(temp_dir_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(temp_dir_exports);
|
|
27
27
|
var import_rewire = require("./rewire");
|
|
28
28
|
// @__NO_SIDE_EFFECTS__
|
|
29
|
-
function getTmpdir() {
|
|
30
|
-
return (0, import_rewire.getEnvValue)("TMPDIR");
|
|
31
|
-
}
|
|
32
|
-
// @__NO_SIDE_EFFECTS__
|
|
33
29
|
function getTemp() {
|
|
34
30
|
return (0, import_rewire.getEnvValue)("TEMP");
|
|
35
31
|
}
|
|
@@ -37,6 +33,10 @@ function getTemp() {
|
|
|
37
33
|
function getTmp() {
|
|
38
34
|
return (0, import_rewire.getEnvValue)("TMP");
|
|
39
35
|
}
|
|
36
|
+
// @__NO_SIDE_EFFECTS__
|
|
37
|
+
function getTmpdir() {
|
|
38
|
+
return (0, import_rewire.getEnvValue)("TMPDIR");
|
|
39
|
+
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
41
|
0 && (module.exports = {
|
|
42
42
|
getTemp,
|
package/dist/env/windows.d.ts
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/*@__NO_SIDE_EFFECTS__*/
|
|
6
6
|
export declare function getAppdata(): string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* COMSPEC environment variable.
|
|
9
|
+
* Points to the Windows command processor (typically cmd.exe).
|
|
10
|
+
*/
|
|
11
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
12
|
+
export declare function getComspec(): string | undefined;
|
|
7
13
|
/**
|
|
8
14
|
* LOCALAPPDATA environment variable.
|
|
9
15
|
* Points to the Local Application Data directory on Windows.
|
|
@@ -16,9 +22,3 @@ export declare function getLocalappdata(): string | undefined;
|
|
|
16
22
|
*/
|
|
17
23
|
/*@__NO_SIDE_EFFECTS__*/
|
|
18
24
|
export declare function getUserprofile(): string | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* COMSPEC environment variable.
|
|
21
|
-
* Points to the Windows command processor (typically cmd.exe).
|
|
22
|
-
*/
|
|
23
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
24
|
-
export declare function getComspec(): string | undefined;
|
package/dist/env/windows.js
CHANGED
|
@@ -31,6 +31,10 @@ function getAppdata() {
|
|
|
31
31
|
return (0, import_rewire.getEnvValue)("APPDATA");
|
|
32
32
|
}
|
|
33
33
|
// @__NO_SIDE_EFFECTS__
|
|
34
|
+
function getComspec() {
|
|
35
|
+
return (0, import_rewire.getEnvValue)("COMSPEC");
|
|
36
|
+
}
|
|
37
|
+
// @__NO_SIDE_EFFECTS__
|
|
34
38
|
function getLocalappdata() {
|
|
35
39
|
return (0, import_rewire.getEnvValue)("LOCALAPPDATA");
|
|
36
40
|
}
|
|
@@ -38,10 +42,6 @@ function getLocalappdata() {
|
|
|
38
42
|
function getUserprofile() {
|
|
39
43
|
return (0, import_rewire.getEnvValue)("USERPROFILE");
|
|
40
44
|
}
|
|
41
|
-
// @__NO_SIDE_EFFECTS__
|
|
42
|
-
function getComspec() {
|
|
43
|
-
return (0, import_rewire.getEnvValue)("COMSPEC");
|
|
44
|
-
}
|
|
45
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
46
46
|
0 && (module.exports = {
|
|
47
47
|
getAppdata,
|
package/dist/github.js
CHANGED
|
@@ -83,7 +83,16 @@ async function fetchGitHub(url, options) {
|
|
|
83
83
|
`GitHub API error ${response.status}: ${response.statusText}`
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
|
-
|
|
86
|
+
try {
|
|
87
|
+
return JSON.parse(response.body.toString("utf8"));
|
|
88
|
+
} catch (error) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`Failed to parse GitHub API response: ${error instanceof Error ? error.message : String(error)}
|
|
91
|
+
URL: ${url}
|
|
92
|
+
Response may be malformed or incomplete.`,
|
|
93
|
+
{ cause: error }
|
|
94
|
+
);
|
|
95
|
+
}
|
|
87
96
|
}
|
|
88
97
|
async function resolveRefToSha(owner, repo, ref, options) {
|
|
89
98
|
const opts = {
|
package/dist/packages/specs.js
CHANGED
|
@@ -43,7 +43,7 @@ var import_strings = require("../strings");
|
|
|
43
43
|
function getRepoUrlDetails(repoUrl = "") {
|
|
44
44
|
const userAndRepo = repoUrl.replace(/^.+github.com\//, "").split("/");
|
|
45
45
|
const user = userAndRepo[0] || "";
|
|
46
|
-
const project = userAndRepo.length > 1 ? userAndRepo[1]?.slice(0, -
|
|
46
|
+
const project = userAndRepo.length > 1 ? (userAndRepo[1]?.endsWith(".git") ? userAndRepo[1].slice(0, -4) : userAndRepo[1]) || "" : "";
|
|
47
47
|
return { user, project };
|
|
48
48
|
}
|
|
49
49
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -68,6 +68,24 @@ export declare const SOCKET_BTM_REPO: {
|
|
|
68
68
|
readonly owner: "SocketDev";
|
|
69
69
|
readonly repo: "socket-btm";
|
|
70
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* Create a matcher function for a pattern using picomatch for glob patterns
|
|
73
|
+
* or simple prefix/suffix matching for object patterns.
|
|
74
|
+
*
|
|
75
|
+
* @param pattern - Pattern to match (string glob, prefix/suffix object, or RegExp)
|
|
76
|
+
* @returns Function that tests if a string matches the pattern
|
|
77
|
+
*/
|
|
78
|
+
export declare function createAssetMatcher(pattern: string | {
|
|
79
|
+
prefix: string;
|
|
80
|
+
suffix: string;
|
|
81
|
+
} | RegExp): (input: string) => boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Download a binary from any GitHub repository with version caching.
|
|
84
|
+
*
|
|
85
|
+
* @param config - Download configuration
|
|
86
|
+
* @returns Path to the downloaded binary
|
|
87
|
+
*/
|
|
88
|
+
export declare function downloadGitHubRelease(config: DownloadGitHubReleaseConfig): Promise<string>;
|
|
71
89
|
/**
|
|
72
90
|
* Download a specific release asset.
|
|
73
91
|
* Supports pattern matching for dynamic asset discovery.
|
|
@@ -115,10 +133,3 @@ export declare function getLatestRelease(toolPrefix: string, repoConfig: RepoCon
|
|
|
115
133
|
export declare function getReleaseAssetUrl(tag: string, assetPattern: string | AssetPattern, repoConfig: RepoConfig, options?: {
|
|
116
134
|
quiet?: boolean;
|
|
117
135
|
}): Promise<string | null>;
|
|
118
|
-
/**
|
|
119
|
-
* Download a binary from any GitHub repository with version caching.
|
|
120
|
-
*
|
|
121
|
-
* @param config - Download configuration
|
|
122
|
-
* @returns Path to the downloaded binary
|
|
123
|
-
*/
|
|
124
|
-
export declare function downloadGitHubRelease(config: DownloadGitHubReleaseConfig): Promise<string>;
|
package/dist/releases/github.js
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var github_exports = {};
|
|
31
31
|
__export(github_exports, {
|
|
32
32
|
SOCKET_BTM_REPO: () => SOCKET_BTM_REPO,
|
|
33
|
+
createAssetMatcher: () => createAssetMatcher,
|
|
33
34
|
downloadGitHubRelease: () => downloadGitHubRelease,
|
|
34
35
|
downloadReleaseAsset: () => downloadReleaseAsset,
|
|
35
36
|
getAuthHeaders: () => getAuthHeaders,
|
|
@@ -43,7 +44,6 @@ var import_http_request = require("../http-request.js");
|
|
|
43
44
|
var import_logger = require("../logger.js");
|
|
44
45
|
var import_promises = require("../promises.js");
|
|
45
46
|
var import_spawn = require("../spawn.js");
|
|
46
|
-
const logger = (0, import_logger.getDefaultLogger)();
|
|
47
47
|
const RETRY_CONFIG = Object.freeze({
|
|
48
48
|
__proto__: null,
|
|
49
49
|
// Exponential backoff: delay doubles with each retry (5s, 10s, 20s).
|
|
@@ -53,19 +53,13 @@ const RETRY_CONFIG = Object.freeze({
|
|
|
53
53
|
// Maximum number of retry attempts (excluding initial request).
|
|
54
54
|
retries: 2
|
|
55
55
|
});
|
|
56
|
+
const SOCKET_BTM_REPO = {
|
|
57
|
+
owner: "SocketDev",
|
|
58
|
+
repo: "socket-btm"
|
|
59
|
+
};
|
|
60
|
+
const logger = (0, import_logger.getDefaultLogger)();
|
|
56
61
|
let _fs;
|
|
57
62
|
let _path;
|
|
58
|
-
function createMatcher(pattern) {
|
|
59
|
-
if (typeof pattern === "string") {
|
|
60
|
-
const isMatch = (0, import_picomatch.default)(pattern);
|
|
61
|
-
return (input) => isMatch(input);
|
|
62
|
-
}
|
|
63
|
-
if (pattern instanceof RegExp) {
|
|
64
|
-
return (input) => pattern.test(input);
|
|
65
|
-
}
|
|
66
|
-
const { prefix, suffix } = pattern;
|
|
67
|
-
return (input) => input.startsWith(prefix) && input.endsWith(suffix);
|
|
68
|
-
}
|
|
69
63
|
// @__NO_SIDE_EFFECTS__
|
|
70
64
|
function getFs() {
|
|
71
65
|
if (_fs === void 0) {
|
|
@@ -80,10 +74,91 @@ function getPath() {
|
|
|
80
74
|
}
|
|
81
75
|
return _path;
|
|
82
76
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
function createAssetMatcher(pattern) {
|
|
78
|
+
if (typeof pattern === "string") {
|
|
79
|
+
const isMatch = (0, import_picomatch.default)(pattern);
|
|
80
|
+
return (input) => isMatch(input);
|
|
81
|
+
}
|
|
82
|
+
if (pattern instanceof RegExp) {
|
|
83
|
+
return (input) => pattern.test(input);
|
|
84
|
+
}
|
|
85
|
+
const { prefix, suffix } = pattern;
|
|
86
|
+
return (input) => input.startsWith(prefix) && input.endsWith(suffix);
|
|
87
|
+
}
|
|
88
|
+
async function downloadGitHubRelease(config) {
|
|
89
|
+
const {
|
|
90
|
+
assetName,
|
|
91
|
+
binaryName,
|
|
92
|
+
cwd = process.cwd(),
|
|
93
|
+
downloadDir = "build/downloaded",
|
|
94
|
+
owner,
|
|
95
|
+
platformArch,
|
|
96
|
+
quiet = false,
|
|
97
|
+
removeMacOSQuarantine = true,
|
|
98
|
+
repo,
|
|
99
|
+
tag: explicitTag,
|
|
100
|
+
toolName,
|
|
101
|
+
toolPrefix
|
|
102
|
+
} = config;
|
|
103
|
+
let tag;
|
|
104
|
+
if (explicitTag) {
|
|
105
|
+
tag = explicitTag;
|
|
106
|
+
} else if (toolPrefix) {
|
|
107
|
+
const latestTag = await getLatestRelease(
|
|
108
|
+
toolPrefix,
|
|
109
|
+
{ owner, repo },
|
|
110
|
+
{ quiet }
|
|
111
|
+
);
|
|
112
|
+
if (!latestTag) {
|
|
113
|
+
throw new Error(`No ${toolPrefix} release found in ${owner}/${repo}`);
|
|
114
|
+
}
|
|
115
|
+
tag = latestTag;
|
|
116
|
+
} else {
|
|
117
|
+
throw new Error("Either toolPrefix or tag must be provided");
|
|
118
|
+
}
|
|
119
|
+
const path = /* @__PURE__ */ getPath();
|
|
120
|
+
const resolvedDownloadDir = path.isAbsolute(downloadDir) ? downloadDir : path.join(cwd, downloadDir);
|
|
121
|
+
const binaryDir = path.join(resolvedDownloadDir, toolName, platformArch);
|
|
122
|
+
const binaryPath = path.join(binaryDir, binaryName);
|
|
123
|
+
const versionPath = path.join(binaryDir, ".version");
|
|
124
|
+
const fs = /* @__PURE__ */ getFs();
|
|
125
|
+
if (fs.existsSync(versionPath) && fs.existsSync(binaryPath)) {
|
|
126
|
+
const cachedVersion = (await fs.promises.readFile(versionPath, "utf8")).trim();
|
|
127
|
+
if (cachedVersion === tag && fs.existsSync(binaryPath)) {
|
|
128
|
+
if (!quiet) {
|
|
129
|
+
logger.info(`Using cached ${toolName} (${platformArch}): ${binaryPath}`);
|
|
130
|
+
}
|
|
131
|
+
return binaryPath;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!quiet) {
|
|
135
|
+
logger.info(`Downloading ${toolName} for ${platformArch}...`);
|
|
136
|
+
}
|
|
137
|
+
await downloadReleaseAsset(
|
|
138
|
+
tag,
|
|
139
|
+
assetName,
|
|
140
|
+
binaryPath,
|
|
141
|
+
{ owner, repo },
|
|
142
|
+
{ quiet }
|
|
143
|
+
);
|
|
144
|
+
const isWindows = binaryName.endsWith(".exe");
|
|
145
|
+
if (!isWindows) {
|
|
146
|
+
fs.chmodSync(binaryPath, 493);
|
|
147
|
+
if (removeMacOSQuarantine && process.platform === "darwin" && platformArch.startsWith("darwin")) {
|
|
148
|
+
try {
|
|
149
|
+
await (0, import_spawn.spawn)("xattr", ["-d", "com.apple.quarantine", binaryPath], {
|
|
150
|
+
stdio: "ignore"
|
|
151
|
+
});
|
|
152
|
+
} catch {
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
await fs.promises.writeFile(versionPath, tag, "utf8");
|
|
157
|
+
if (!quiet) {
|
|
158
|
+
logger.info(`Downloaded ${toolName} to ${binaryPath}`);
|
|
159
|
+
}
|
|
160
|
+
return binaryPath;
|
|
161
|
+
}
|
|
87
162
|
async function downloadReleaseAsset(tag, assetPattern, outputPath, repoConfig, options = {}) {
|
|
88
163
|
const { owner, repo } = repoConfig;
|
|
89
164
|
const { quiet = false } = options;
|
|
@@ -120,7 +195,7 @@ function getAuthHeaders() {
|
|
|
120
195
|
async function getLatestRelease(toolPrefix, repoConfig, options = {}) {
|
|
121
196
|
const { assetPattern, quiet = false } = options;
|
|
122
197
|
const { owner, repo } = repoConfig;
|
|
123
|
-
const isMatch = assetPattern ?
|
|
198
|
+
const isMatch = assetPattern ? createAssetMatcher(assetPattern) : void 0;
|
|
124
199
|
return await (0, import_promises.pRetry)(
|
|
125
200
|
async () => {
|
|
126
201
|
const response = await (0, import_http_request.httpRequest)(
|
|
@@ -188,7 +263,7 @@ async function getLatestRelease(toolPrefix, repoConfig, options = {}) {
|
|
|
188
263
|
async function getReleaseAssetUrl(tag, assetPattern, repoConfig, options = {}) {
|
|
189
264
|
const { owner, repo } = repoConfig;
|
|
190
265
|
const { quiet = false } = options;
|
|
191
|
-
const isMatch = typeof assetPattern === "string" && !assetPattern.includes("*") && !assetPattern.includes("{") ? (input) => input === assetPattern :
|
|
266
|
+
const isMatch = typeof assetPattern === "string" && !assetPattern.includes("*") && !assetPattern.includes("{") ? (input) => input === assetPattern : createAssetMatcher(assetPattern);
|
|
192
267
|
return await (0, import_promises.pRetry)(
|
|
193
268
|
async () => {
|
|
194
269
|
const response = await (0, import_http_request.httpRequest)(
|
|
@@ -229,83 +304,10 @@ async function getReleaseAssetUrl(tag, assetPattern, repoConfig, options = {}) {
|
|
|
229
304
|
}
|
|
230
305
|
);
|
|
231
306
|
}
|
|
232
|
-
async function downloadGitHubRelease(config) {
|
|
233
|
-
const {
|
|
234
|
-
assetName,
|
|
235
|
-
binaryName,
|
|
236
|
-
cwd = process.cwd(),
|
|
237
|
-
downloadDir = "build/downloaded",
|
|
238
|
-
owner,
|
|
239
|
-
platformArch,
|
|
240
|
-
quiet = false,
|
|
241
|
-
removeMacOSQuarantine = true,
|
|
242
|
-
repo,
|
|
243
|
-
tag: explicitTag,
|
|
244
|
-
toolName,
|
|
245
|
-
toolPrefix
|
|
246
|
-
} = config;
|
|
247
|
-
let tag;
|
|
248
|
-
if (explicitTag) {
|
|
249
|
-
tag = explicitTag;
|
|
250
|
-
} else if (toolPrefix) {
|
|
251
|
-
const latestTag = await getLatestRelease(
|
|
252
|
-
toolPrefix,
|
|
253
|
-
{ owner, repo },
|
|
254
|
-
{ quiet }
|
|
255
|
-
);
|
|
256
|
-
if (!latestTag) {
|
|
257
|
-
throw new Error(`No ${toolPrefix} release found in ${owner}/${repo}`);
|
|
258
|
-
}
|
|
259
|
-
tag = latestTag;
|
|
260
|
-
} else {
|
|
261
|
-
throw new Error("Either toolPrefix or tag must be provided");
|
|
262
|
-
}
|
|
263
|
-
const path = /* @__PURE__ */ getPath();
|
|
264
|
-
const resolvedDownloadDir = path.isAbsolute(downloadDir) ? downloadDir : path.join(cwd, downloadDir);
|
|
265
|
-
const binaryDir = path.join(resolvedDownloadDir, toolName, platformArch);
|
|
266
|
-
const binaryPath = path.join(binaryDir, binaryName);
|
|
267
|
-
const versionPath = path.join(binaryDir, ".version");
|
|
268
|
-
const fs = /* @__PURE__ */ getFs();
|
|
269
|
-
if (fs.existsSync(versionPath) && fs.existsSync(binaryPath)) {
|
|
270
|
-
const cachedVersion = (await fs.promises.readFile(versionPath, "utf8")).trim();
|
|
271
|
-
if (cachedVersion === tag) {
|
|
272
|
-
if (!quiet) {
|
|
273
|
-
logger.info(`Using cached ${toolName} (${platformArch}): ${binaryPath}`);
|
|
274
|
-
}
|
|
275
|
-
return binaryPath;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
if (!quiet) {
|
|
279
|
-
logger.info(`Downloading ${toolName} for ${platformArch}...`);
|
|
280
|
-
}
|
|
281
|
-
await downloadReleaseAsset(
|
|
282
|
-
tag,
|
|
283
|
-
assetName,
|
|
284
|
-
binaryPath,
|
|
285
|
-
{ owner, repo },
|
|
286
|
-
{ quiet }
|
|
287
|
-
);
|
|
288
|
-
const isWindows = binaryName.endsWith(".exe");
|
|
289
|
-
if (!isWindows) {
|
|
290
|
-
fs.chmodSync(binaryPath, 493);
|
|
291
|
-
if (removeMacOSQuarantine && process.platform === "darwin" && platformArch.startsWith("darwin")) {
|
|
292
|
-
try {
|
|
293
|
-
await (0, import_spawn.spawn)("xattr", ["-d", "com.apple.quarantine", binaryPath], {
|
|
294
|
-
stdio: "ignore"
|
|
295
|
-
});
|
|
296
|
-
} catch {
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
await fs.promises.writeFile(versionPath, tag, "utf8");
|
|
301
|
-
if (!quiet) {
|
|
302
|
-
logger.info(`Downloaded ${toolName} to ${binaryPath}`);
|
|
303
|
-
}
|
|
304
|
-
return binaryPath;
|
|
305
|
-
}
|
|
306
307
|
// Annotate the CommonJS export names for ESM import in node:
|
|
307
308
|
0 && (module.exports = {
|
|
308
309
|
SOCKET_BTM_REPO,
|
|
310
|
+
createAssetMatcher,
|
|
309
311
|
downloadGitHubRelease,
|
|
310
312
|
downloadReleaseAsset,
|
|
311
313
|
getAuthHeaders,
|