@socketsecurity/lib 5.25.1 → 5.26.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 +344 -1184
- package/README.md +1 -1
- package/dist/abort.js +7 -6
- package/dist/agent.js +16 -15
- package/dist/ansi.js +3 -2
- package/dist/archives.js +18 -17
- package/dist/argv/flags.js +29 -28
- package/dist/argv/parse.js +4 -3
- package/dist/arrays.js +3 -2
- package/dist/bin.js +12 -11
- package/dist/cacache.js +16 -11
- package/dist/cache-with-ttl.js +26 -21
- package/dist/colors.js +2 -1
- package/dist/constants/licenses.js +2 -1
- package/dist/constants/lifecycle-script-names.js +2 -1
- package/dist/constants/maintained-node-versions.js +2 -1
- package/dist/constants/node.js +4 -3
- package/dist/constants/package-default-socket-categories.js +2 -1
- package/dist/constants/packages.js +4 -3
- package/dist/constants/socket.js +1 -1
- package/dist/cover/code.js +9 -8
- package/dist/cover/formatters.js +12 -11
- package/dist/cover/type.js +5 -4
- package/dist/crypto.d.ts +36 -0
- package/dist/{effects/ultra.js → crypto.js} +33 -37
- package/dist/debug.js +12 -15
- package/dist/dlx/arborist.js +10 -9
- package/dist/dlx/binary.js +27 -24
- package/dist/dlx/cache.js +2 -10
- package/dist/dlx/detect.js +6 -5
- package/dist/dlx/integrity.js +13 -11
- package/dist/dlx/lockfile.js +7 -6
- package/dist/dlx/manifest.js +6 -5
- package/dist/dlx/package.js +17 -16
- package/dist/dlx/packages.js +6 -5
- package/dist/dlx/paths.d.ts +1 -1
- package/dist/dlx/paths.js +2 -1
- package/dist/effects/pulse-frames.js +4 -3
- package/dist/effects/shimmer-keyframes.d.ts +62 -0
- package/dist/effects/shimmer-keyframes.js +55 -0
- package/dist/effects/shimmer-terminal.d.ts +66 -0
- package/dist/effects/shimmer-terminal.js +57 -0
- package/dist/effects/shimmer.d.ts +293 -0
- package/dist/effects/shimmer.js +180 -0
- package/dist/env/rewire.js +4 -3
- package/dist/env.js +5 -4
- package/dist/errors.js +1 -1
- package/dist/external/@npmcli/package-json/lib/read-package.js +10 -10
- package/dist/external/@npmcli/package-json.js +372 -372
- package/dist/external/@npmcli/promise-spawn.js +24 -24
- package/dist/external/@socketregistry/packageurl-js.js +19 -18
- package/dist/external/@socketregistry/yocto-spinner.js +4 -3
- package/dist/external/@yarnpkg/extensions.js +2 -1
- package/dist/external/adm-zip.js +70 -70
- package/dist/external/debug.js +22 -22
- package/dist/external/external-pack.js +45 -45
- package/dist/external/fast-sort.js +5 -5
- package/dist/external/libnpmexec.js +4 -3
- package/dist/external/npm-pack.js +369 -369
- package/dist/external/p-map.js +9 -9
- package/dist/external/pico-pack.js +190 -190
- package/dist/external/pony-cause.js +2 -1
- package/dist/external/spdx-pack.js +11 -10
- package/dist/external/tar-fs.js +58 -58
- package/dist/external/which.js +13 -13
- package/dist/external/yargs-parser.js +71 -71
- package/dist/fs.js +19 -23
- package/dist/git.js +14 -13
- package/dist/github.d.ts +34 -0
- package/dist/github.js +248 -23
- package/dist/globs.d.ts +20 -0
- package/dist/globs.js +134 -25
- package/dist/http-request.d.ts +4 -3
- package/dist/http-request.js +39 -32
- package/dist/ipc-cli.js +2 -1
- package/dist/ipc.js +5 -4
- package/dist/json/edit.js +4 -3
- package/dist/json/format.js +3 -2
- package/dist/json/parse.js +7 -6
- package/dist/links.js +2 -1
- package/dist/logger.js +21 -14
- package/dist/memoization.js +16 -15
- package/dist/objects.js +2 -2
- package/dist/packages/edit.js +8 -7
- package/dist/packages/exports.js +17 -16
- package/dist/packages/isolation.js +20 -13
- package/dist/packages/licenses.js +6 -3
- package/dist/packages/manifest.js +2 -1
- package/dist/packages/normalize.js +8 -4
- package/dist/packages/operations.js +5 -4
- package/dist/packages/provenance.js +7 -6
- package/dist/packages/specs.js +2 -1
- package/dist/packages/validation.js +2 -1
- package/dist/paths/normalize.js +32 -40
- package/dist/paths/packages.js +2 -1
- package/dist/paths/rewire.js +3 -2
- package/dist/performance.js +19 -18
- package/dist/primordials.d.ts +9 -0
- package/dist/primordials.js +17 -0
- package/dist/process-lock.js +14 -13
- package/dist/promise-queue.js +17 -9
- package/dist/promises.d.ts +29 -6
- package/dist/promises.js +19 -15
- package/dist/regexps.js +9 -8
- package/dist/releases/github-api.d.ts +56 -0
- package/dist/releases/github-api.js +275 -0
- package/dist/releases/github-archives.d.ts +60 -0
- package/dist/releases/github-archives.js +136 -0
- package/dist/releases/github-assets.d.ts +21 -0
- package/dist/releases/github-assets.js +52 -0
- package/dist/releases/github-auth.d.ts +16 -0
- package/dist/releases/github-auth.js +51 -0
- package/dist/releases/github-downloads.d.ts +42 -0
- package/dist/releases/github-downloads.js +155 -0
- package/dist/releases/github-types.d.ts +66 -0
- package/dist/{effects/types.js → releases/github-types.js} +2 -2
- package/dist/releases/socket-btm.d.ts +1 -1
- package/dist/releases/socket-btm.js +17 -17
- package/dist/schema/parse.js +2 -1
- package/dist/schema/validate.js +6 -5
- package/dist/shadow.js +2 -1
- package/dist/signal-exit.js +2 -2
- package/dist/spawn.js +45 -35
- package/dist/spinner.d.ts +13 -6
- package/dist/spinner.js +75 -57
- package/dist/ssri.js +8 -7
- package/dist/stdio/footer.js +13 -12
- package/dist/stdio/header.js +5 -4
- package/dist/stdio/progress.js +13 -12
- package/dist/strings.js +19 -18
- package/dist/suppress-warnings.js +2 -2
- package/dist/tables.js +16 -13
- package/dist/temporary-executor.js +2 -1
- package/dist/themes/context.js +2 -1
- package/dist/themes/types.d.ts +1 -1
- package/dist/themes/utils.d.ts +8 -3
- package/dist/themes/utils.js +29 -5
- package/dist/url.js +4 -3
- package/package.json +44 -20
- package/dist/effects/text-shimmer.d.ts +0 -58
- package/dist/effects/text-shimmer.js +0 -192
- package/dist/effects/types.d.ts +0 -47
- package/dist/effects/ultra.d.ts +0 -22
- package/dist/releases/github.d.ts +0 -234
- package/dist/releases/github.js +0 -417
- package/dist/themes/index.d.ts +0 -49
- package/dist/themes/index.js +0 -60
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Socket Lib - Built with esbuild */
|
|
3
|
+
"use strict";
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var github_api_exports = {};
|
|
22
|
+
__export(github_api_exports, {
|
|
23
|
+
getLatestRelease: () => getLatestRelease,
|
|
24
|
+
getReleaseAssetUrl: () => getReleaseAssetUrl
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(github_api_exports);
|
|
27
|
+
var import_http_request = require("../http-request");
|
|
28
|
+
var import_primordials = require("../primordials");
|
|
29
|
+
var import_promises = require("../promises");
|
|
30
|
+
var import_github_assets = require("./github-assets");
|
|
31
|
+
var import_github_auth = require("./github-auth");
|
|
32
|
+
const RETRY_CONFIG = (0, import_primordials.ObjectFreeze)({
|
|
33
|
+
__proto__: null,
|
|
34
|
+
// Exponential backoff: delay doubles with each retry (5s, 10s, 20s).
|
|
35
|
+
backoffFactor: 2,
|
|
36
|
+
// Initial delay before first retry.
|
|
37
|
+
baseDelayMs: 5e3,
|
|
38
|
+
// Maximum number of retry attempts (excluding initial request).
|
|
39
|
+
retries: 2
|
|
40
|
+
});
|
|
41
|
+
async function fetchReleasesViaRest(owner, repo) {
|
|
42
|
+
const response = await (0, import_http_request.httpRequest)(
|
|
43
|
+
`https://api.github.com/repos/${owner}/${repo}/releases?per_page=100`,
|
|
44
|
+
{ headers: (0, import_github_auth.getAuthHeaders)() }
|
|
45
|
+
);
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
throw new import_primordials.ErrorCtor(
|
|
48
|
+
`Failed to fetch ${owner}/${repo} releases: ${response.status}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
const text = response.body.toString("utf8");
|
|
52
|
+
if (text.length === 0) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
let parsed;
|
|
56
|
+
try {
|
|
57
|
+
parsed = (0, import_primordials.JSONParse)(text);
|
|
58
|
+
} catch (cause) {
|
|
59
|
+
throw new import_primordials.ErrorCtor(`Failed to parse ${owner}/${repo} releases response`, {
|
|
60
|
+
cause
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return (0, import_primordials.ArrayIsArray)(parsed) ? parsed : [];
|
|
64
|
+
}
|
|
65
|
+
async function fetchReleasesViaGraphQL(owner, repo) {
|
|
66
|
+
const response = await (0, import_http_request.httpRequest)("https://api.github.com/graphql", {
|
|
67
|
+
body: (0, import_primordials.JSONStringify)({
|
|
68
|
+
query: `query($owner: String!, $repo: String!) {
|
|
69
|
+
repository(owner: $owner, name: $repo) {
|
|
70
|
+
releases(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
|
|
71
|
+
nodes {
|
|
72
|
+
tagName
|
|
73
|
+
publishedAt
|
|
74
|
+
releaseAssets(first: 100) { nodes { name } }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}`,
|
|
79
|
+
variables: { owner, repo }
|
|
80
|
+
}),
|
|
81
|
+
headers: { ...(0, import_github_auth.getAuthHeaders)(), "Content-Type": "application/json" },
|
|
82
|
+
method: "POST"
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
throw new import_primordials.ErrorCtor(
|
|
86
|
+
`Failed to fetch ${owner}/${repo} releases (GraphQL): ${response.status}`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
let parsed;
|
|
90
|
+
try {
|
|
91
|
+
parsed = (0, import_primordials.JSONParse)(response.body.toString("utf8"));
|
|
92
|
+
} catch (cause) {
|
|
93
|
+
throw new import_primordials.ErrorCtor(
|
|
94
|
+
`Failed to parse GitHub GraphQL response for ${owner}/${repo} releases`,
|
|
95
|
+
{ cause }
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
if (parsed.errors?.length) {
|
|
99
|
+
throw new import_primordials.ErrorCtor(
|
|
100
|
+
`GraphQL repository.releases(${owner}/${repo}) returned errors: ${parsed.errors.map((e) => e.message).join("; ")}`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return (parsed.data?.repository?.releases?.nodes ?? []).map((n) => ({
|
|
104
|
+
tag_name: n.tagName,
|
|
105
|
+
published_at: n.publishedAt,
|
|
106
|
+
assets: n.releaseAssets?.nodes ?? []
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
async function fetchReleaseAssetsViaGraphQL(owner, repo, tag) {
|
|
110
|
+
const response = await (0, import_http_request.httpRequest)("https://api.github.com/graphql", {
|
|
111
|
+
body: (0, import_primordials.JSONStringify)({
|
|
112
|
+
query: `query($owner: String!, $repo: String!, $tag: String!) {
|
|
113
|
+
repository(owner: $owner, name: $repo) {
|
|
114
|
+
release(tagName: $tag) {
|
|
115
|
+
tagName
|
|
116
|
+
releaseAssets(first: 100) { nodes { name downloadUrl } }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}`,
|
|
120
|
+
variables: { owner, repo, tag }
|
|
121
|
+
}),
|
|
122
|
+
headers: { ...(0, import_github_auth.getAuthHeaders)(), "Content-Type": "application/json" },
|
|
123
|
+
method: "POST"
|
|
124
|
+
});
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
throw new import_primordials.ErrorCtor(
|
|
127
|
+
`Failed to fetch ${owner}/${repo} release ${tag} (GraphQL): ${response.status} ${response.statusText}`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
if (response.body.byteLength === 0) {
|
|
131
|
+
throw new import_primordials.ErrorCtor(
|
|
132
|
+
`Failed to fetch ${owner}/${repo} release ${tag}: GraphQL returned empty body`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
let parsed;
|
|
136
|
+
try {
|
|
137
|
+
parsed = (0, import_primordials.JSONParse)(response.body.toString("utf8"));
|
|
138
|
+
} catch (cause) {
|
|
139
|
+
throw new import_primordials.ErrorCtor(
|
|
140
|
+
`Failed to parse ${owner}/${repo} release ${tag} response (GraphQL)`,
|
|
141
|
+
{ cause }
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
if (parsed.errors?.length) {
|
|
145
|
+
throw new import_primordials.ErrorCtor(
|
|
146
|
+
`GraphQL repository.release(${owner}/${repo}, ${tag}) returned errors: ${parsed.errors.map((e) => e.message).join("; ")}`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
const release = parsed.data?.repository?.release;
|
|
150
|
+
if (!release) {
|
|
151
|
+
return void 0;
|
|
152
|
+
}
|
|
153
|
+
return (release.releaseAssets?.nodes ?? []).map((n) => ({
|
|
154
|
+
browser_download_url: n.downloadUrl,
|
|
155
|
+
name: n.name
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
async function getLatestRelease(toolPrefix, repoConfig, options = {}) {
|
|
159
|
+
const { assetPattern, nothrow = false } = options;
|
|
160
|
+
const { owner, repo } = repoConfig;
|
|
161
|
+
const isMatch = assetPattern ? (0, import_github_assets.createAssetMatcher)(assetPattern) : void 0;
|
|
162
|
+
return await (0, import_promises.pRetry)(async () => {
|
|
163
|
+
let releases = await fetchReleasesViaRest(owner, repo);
|
|
164
|
+
if (releases.length === 0) {
|
|
165
|
+
let graphqlReleases;
|
|
166
|
+
try {
|
|
167
|
+
graphqlReleases = await fetchReleasesViaGraphQL(owner, repo);
|
|
168
|
+
} catch (cause) {
|
|
169
|
+
if (nothrow) {
|
|
170
|
+
return void 0;
|
|
171
|
+
}
|
|
172
|
+
throw new import_primordials.ErrorCtor(
|
|
173
|
+
`Failed to list ${owner}/${repo} releases: both REST and GraphQL backends degraded`,
|
|
174
|
+
{ cause }
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
if (graphqlReleases.length > 0) {
|
|
178
|
+
releases = graphqlReleases;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const matchingReleases = releases.filter((release) => {
|
|
182
|
+
const { assets, tag_name: tag } = release;
|
|
183
|
+
if (!(0, import_primordials.StringPrototypeStartsWith)(tag, toolPrefix)) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
if (!assets || assets.length === 0) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
if (isMatch) {
|
|
190
|
+
const hasMatchingAsset = assets.some(
|
|
191
|
+
(a) => isMatch(a.name)
|
|
192
|
+
);
|
|
193
|
+
if (!hasMatchingAsset) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
198
|
+
});
|
|
199
|
+
if (matchingReleases.length === 0) {
|
|
200
|
+
return void 0;
|
|
201
|
+
}
|
|
202
|
+
matchingReleases.sort(
|
|
203
|
+
(a, b) => (0, import_primordials.DateParse)(b.published_at) - (0, import_primordials.DateParse)(a.published_at)
|
|
204
|
+
);
|
|
205
|
+
const latestRelease = matchingReleases[0];
|
|
206
|
+
return latestRelease.tag_name;
|
|
207
|
+
}, RETRY_CONFIG) ?? void 0;
|
|
208
|
+
}
|
|
209
|
+
async function getReleaseAssetUrl(tag, assetPattern, repoConfig, options = {}) {
|
|
210
|
+
const { nothrow = false } = options;
|
|
211
|
+
const { owner, repo } = repoConfig;
|
|
212
|
+
const isMatch = typeof assetPattern === "string" && !assetPattern.includes("*") && !assetPattern.includes("{") ? (input) => input === assetPattern : (0, import_github_assets.createAssetMatcher)(assetPattern);
|
|
213
|
+
return await (0, import_promises.pRetry)(async () => {
|
|
214
|
+
const response = await (0, import_http_request.httpRequest)(
|
|
215
|
+
`https://api.github.com/repos/${owner}/${repo}/releases/tags/${tag}`,
|
|
216
|
+
{
|
|
217
|
+
headers: (0, import_github_auth.getAuthHeaders)()
|
|
218
|
+
}
|
|
219
|
+
);
|
|
220
|
+
if (!response.ok) {
|
|
221
|
+
throw new import_primordials.ErrorCtor(
|
|
222
|
+
`Failed to fetch ${owner}/${repo} release ${tag}: ${response.status}`
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
let assets;
|
|
226
|
+
if (response.body.byteLength === 0) {
|
|
227
|
+
let fallbackAssets;
|
|
228
|
+
try {
|
|
229
|
+
fallbackAssets = await fetchReleaseAssetsViaGraphQL(owner, repo, tag);
|
|
230
|
+
} catch (cause) {
|
|
231
|
+
if (nothrow) {
|
|
232
|
+
return void 0;
|
|
233
|
+
}
|
|
234
|
+
throw new import_primordials.ErrorCtor(
|
|
235
|
+
`Failed to fetch ${owner}/${repo} release ${tag}: both REST and GraphQL backends degraded`,
|
|
236
|
+
{ cause }
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
if (fallbackAssets === void 0) {
|
|
240
|
+
if (nothrow) {
|
|
241
|
+
return void 0;
|
|
242
|
+
}
|
|
243
|
+
throw new import_primordials.ErrorCtor(`Release ${tag} not found in ${owner}/${repo}`);
|
|
244
|
+
}
|
|
245
|
+
assets = fallbackAssets;
|
|
246
|
+
} else {
|
|
247
|
+
let release;
|
|
248
|
+
try {
|
|
249
|
+
release = (0, import_primordials.JSONParse)(response.body.toString("utf8"));
|
|
250
|
+
} catch (cause) {
|
|
251
|
+
throw new import_primordials.ErrorCtor(
|
|
252
|
+
`Failed to parse ${owner}/${repo} release ${tag} response`,
|
|
253
|
+
{ cause }
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
if (!(0, import_primordials.ArrayIsArray)(release.assets)) {
|
|
257
|
+
throw new import_primordials.ErrorCtor(
|
|
258
|
+
`Release ${tag} has no assets in ${owner}/${repo}`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
assets = release.assets;
|
|
262
|
+
}
|
|
263
|
+
const asset = assets.find((a) => isMatch(a.name));
|
|
264
|
+
if (!asset) {
|
|
265
|
+
const patternDesc = typeof assetPattern === "string" ? assetPattern : "matching pattern";
|
|
266
|
+
throw new import_primordials.ErrorCtor(`Asset ${patternDesc} not found in release ${tag}`);
|
|
267
|
+
}
|
|
268
|
+
return asset.browser_download_url;
|
|
269
|
+
}, RETRY_CONFIG) ?? void 0;
|
|
270
|
+
}
|
|
271
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
272
|
+
0 && (module.exports = {
|
|
273
|
+
getLatestRelease,
|
|
274
|
+
getReleaseAssetUrl
|
|
275
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview GitHub release archive download + extraction.
|
|
3
|
+
*/
|
|
4
|
+
import { type ArchiveFormat } from '../archives';
|
|
5
|
+
import type { AssetPattern, RepoConfig } from './github-types';
|
|
6
|
+
/**
|
|
7
|
+
* Download and extract an archive from a GitHub release.
|
|
8
|
+
* Supports zip, tar, tar.gz, and tgz formats.
|
|
9
|
+
* Automatically handles downloading, extracting, and cleanup.
|
|
10
|
+
*
|
|
11
|
+
* @param tag - Release tag name
|
|
12
|
+
* @param assetPattern - Asset name or pattern (glob string, prefix/suffix object, or RegExp)
|
|
13
|
+
* @param outputDir - Directory to extract the archive contents to
|
|
14
|
+
* @param repoConfig - Repository configuration (owner/repo)
|
|
15
|
+
* @param options - Additional options
|
|
16
|
+
* @param options.quiet - Suppress log messages
|
|
17
|
+
* @param options.cleanup - Remove downloaded archive after extraction (default: true)
|
|
18
|
+
* @param options.strip - Strip leading path components (like tar --strip-components)
|
|
19
|
+
* @param options.format - Archive format (auto-detected if not specified)
|
|
20
|
+
* @returns Path to the extraction directory
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const outputDir = await downloadAndExtractArchive(
|
|
25
|
+
* 'v1.0.0', 'data-*.tar.gz', '/tmp/data',
|
|
26
|
+
* { owner: 'SocketDev', repo: 'socket-btm' },
|
|
27
|
+
* )
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function downloadAndExtractArchive(tag: string, assetPattern: string | AssetPattern, outputDir: string, repoConfig: RepoConfig, options?: {
|
|
31
|
+
cleanup?: boolean;
|
|
32
|
+
format?: ArchiveFormat;
|
|
33
|
+
quiet?: boolean;
|
|
34
|
+
strip?: number;
|
|
35
|
+
}): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Download and extract a zip file from a GitHub release.
|
|
38
|
+
* Automatically handles downloading, extracting, and cleanup.
|
|
39
|
+
*
|
|
40
|
+
* @param tag - Release tag name
|
|
41
|
+
* @param assetPattern - Asset name or pattern (glob string, prefix/suffix object, or RegExp)
|
|
42
|
+
* @param outputDir - Directory to extract the zip contents to
|
|
43
|
+
* @param repoConfig - Repository configuration (owner/repo)
|
|
44
|
+
* @param options - Additional options
|
|
45
|
+
* @param options.quiet - Suppress log messages
|
|
46
|
+
* @param options.cleanup - Remove downloaded zip file after extraction (default: true)
|
|
47
|
+
* @returns Path to the extraction directory
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const outputDir = await downloadAndExtractZip(
|
|
52
|
+
* 'v1.0.0', 'models-*.zip', '/tmp/models',
|
|
53
|
+
* { owner: 'SocketDev', repo: 'socket-btm' },
|
|
54
|
+
* )
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function downloadAndExtractZip(tag: string, assetPattern: string | AssetPattern, outputDir: string, repoConfig: RepoConfig, options?: {
|
|
58
|
+
cleanup?: boolean;
|
|
59
|
+
quiet?: boolean;
|
|
60
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Socket Lib - Built with esbuild */
|
|
3
|
+
"use strict";
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var github_archives_exports = {};
|
|
22
|
+
__export(github_archives_exports, {
|
|
23
|
+
downloadAndExtractArchive: () => downloadAndExtractArchive,
|
|
24
|
+
downloadAndExtractZip: () => downloadAndExtractZip
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(github_archives_exports);
|
|
27
|
+
var import_archives = require("../archives");
|
|
28
|
+
var import_fs = require("../fs");
|
|
29
|
+
var import_logger = require("../logger");
|
|
30
|
+
var import_primordials = require("../primordials");
|
|
31
|
+
var import_github_downloads = require("./github-downloads");
|
|
32
|
+
const logger = (0, import_logger.getDefaultLogger)();
|
|
33
|
+
let _fs;
|
|
34
|
+
let _path;
|
|
35
|
+
// @__NO_SIDE_EFFECTS__
|
|
36
|
+
function getFs() {
|
|
37
|
+
if (_fs === void 0) {
|
|
38
|
+
_fs = require("node:fs");
|
|
39
|
+
}
|
|
40
|
+
return _fs;
|
|
41
|
+
}
|
|
42
|
+
// @__NO_SIDE_EFFECTS__
|
|
43
|
+
function getPath() {
|
|
44
|
+
if (_path === void 0) {
|
|
45
|
+
_path = require("node:path");
|
|
46
|
+
}
|
|
47
|
+
return _path;
|
|
48
|
+
}
|
|
49
|
+
async function downloadAndExtractArchive(tag, assetPattern, outputDir, repoConfig, options = {}) {
|
|
50
|
+
const { cleanup = true, format, quiet = false, strip } = options;
|
|
51
|
+
const path = /* @__PURE__ */ getPath();
|
|
52
|
+
const fs = /* @__PURE__ */ getFs();
|
|
53
|
+
await (0, import_fs.safeMkdir)(outputDir);
|
|
54
|
+
let ext = ".archive";
|
|
55
|
+
if (format) {
|
|
56
|
+
ext = format === "tar.gz" ? ".tar.gz" : `.${format}`;
|
|
57
|
+
} else if (typeof assetPattern === "string") {
|
|
58
|
+
const detectedFormat = (0, import_archives.detectArchiveFormat)(assetPattern);
|
|
59
|
+
if (detectedFormat) {
|
|
60
|
+
ext = detectedFormat === "tar.gz" ? ".tar.gz" : `.${detectedFormat}`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const archivePath = path.join(outputDir, `__temp_download__${ext}`);
|
|
64
|
+
if (!quiet) {
|
|
65
|
+
logger.info(`Downloading archive from release ${tag}...`);
|
|
66
|
+
}
|
|
67
|
+
await (0, import_github_downloads.downloadReleaseAsset)(tag, assetPattern, archivePath, repoConfig, {
|
|
68
|
+
quiet
|
|
69
|
+
});
|
|
70
|
+
if (!quiet) {
|
|
71
|
+
logger.info(`Extracting archive to ${outputDir}...`);
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
await (0, import_archives.extractArchive)(archivePath, outputDir, { quiet, strip });
|
|
75
|
+
if (!quiet) {
|
|
76
|
+
logger.info(`Extracted archive contents to ${outputDir}`);
|
|
77
|
+
}
|
|
78
|
+
} catch (cause) {
|
|
79
|
+
throw new import_primordials.ErrorCtor(`Failed to extract archive: ${archivePath}`, { cause });
|
|
80
|
+
} finally {
|
|
81
|
+
if (cleanup) {
|
|
82
|
+
try {
|
|
83
|
+
await fs.promises.unlink(archivePath);
|
|
84
|
+
if (!quiet) {
|
|
85
|
+
logger.info("Cleaned up temporary archive file");
|
|
86
|
+
}
|
|
87
|
+
} catch (e) {
|
|
88
|
+
if (!quiet) {
|
|
89
|
+
logger.warn(`Failed to cleanup archive file: ${e}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return outputDir;
|
|
95
|
+
}
|
|
96
|
+
async function downloadAndExtractZip(tag, assetPattern, outputDir, repoConfig, options = {}) {
|
|
97
|
+
const { cleanup = true, quiet = false } = options;
|
|
98
|
+
const path = /* @__PURE__ */ getPath();
|
|
99
|
+
const fs = /* @__PURE__ */ getFs();
|
|
100
|
+
await (0, import_fs.safeMkdir)(outputDir);
|
|
101
|
+
const zipPath = path.join(outputDir, "__temp_download__.zip");
|
|
102
|
+
if (!quiet) {
|
|
103
|
+
logger.info(`Downloading zip asset from release ${tag}...`);
|
|
104
|
+
}
|
|
105
|
+
await (0, import_github_downloads.downloadReleaseAsset)(tag, assetPattern, zipPath, repoConfig, { quiet });
|
|
106
|
+
if (!quiet) {
|
|
107
|
+
logger.info(`Extracting zip to ${outputDir}...`);
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
await (0, import_archives.extractArchive)(zipPath, outputDir, { quiet });
|
|
111
|
+
if (!quiet) {
|
|
112
|
+
logger.info(`Extracted zip contents to ${outputDir}`);
|
|
113
|
+
}
|
|
114
|
+
} catch (cause) {
|
|
115
|
+
throw new import_primordials.ErrorCtor(`Failed to extract zip file: ${zipPath}`, { cause });
|
|
116
|
+
} finally {
|
|
117
|
+
if (cleanup) {
|
|
118
|
+
try {
|
|
119
|
+
await fs.promises.unlink(zipPath);
|
|
120
|
+
if (!quiet) {
|
|
121
|
+
logger.info("Cleaned up temporary zip file");
|
|
122
|
+
}
|
|
123
|
+
} catch (e) {
|
|
124
|
+
if (!quiet) {
|
|
125
|
+
logger.warn(`Failed to cleanup zip file: ${e}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return outputDir;
|
|
131
|
+
}
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
downloadAndExtractArchive,
|
|
135
|
+
downloadAndExtractZip
|
|
136
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Asset matching helpers for GitHub releases.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Create a matcher function for a pattern using picomatch for glob patterns
|
|
6
|
+
* or simple prefix/suffix matching for object patterns.
|
|
7
|
+
*
|
|
8
|
+
* @param pattern - Pattern to match (string glob, prefix/suffix object, or RegExp)
|
|
9
|
+
* @returns Function that tests if a string matches the pattern
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const isMatch = createAssetMatcher('tool-*-linux-x64')
|
|
14
|
+
* isMatch('tool-v1.0-linux-x64') // true
|
|
15
|
+
* isMatch('tool-v1.0-darwin-arm64') // false
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function createAssetMatcher(pattern: string | {
|
|
19
|
+
prefix: string;
|
|
20
|
+
suffix: string;
|
|
21
|
+
} | RegExp): (input: string) => boolean;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Socket Lib - Built with esbuild */
|
|
3
|
+
"use strict";
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
var github_assets_exports = {};
|
|
32
|
+
__export(github_assets_exports, {
|
|
33
|
+
createAssetMatcher: () => createAssetMatcher
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(github_assets_exports);
|
|
36
|
+
var import_picomatch = __toESM(require("../external/picomatch"));
|
|
37
|
+
var import_primordials = require("../primordials");
|
|
38
|
+
function createAssetMatcher(pattern) {
|
|
39
|
+
if (typeof pattern === "string") {
|
|
40
|
+
const isMatch = (0, import_picomatch.default)(pattern);
|
|
41
|
+
return (input) => isMatch(input);
|
|
42
|
+
}
|
|
43
|
+
if (pattern instanceof RegExp) {
|
|
44
|
+
return (input) => pattern.test(input);
|
|
45
|
+
}
|
|
46
|
+
const { prefix, suffix } = pattern;
|
|
47
|
+
return (input) => (0, import_primordials.StringPrototypeStartsWith)(input, prefix) && (0, import_primordials.StringPrototypeEndsWith)(input, suffix);
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
createAssetMatcher
|
|
52
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview GitHub API authentication header helpers.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Get GitHub authentication headers if token is available.
|
|
6
|
+
* Checks GH_TOKEN or GITHUB_TOKEN environment variables.
|
|
7
|
+
*
|
|
8
|
+
* @returns Headers object with Authorization header if token exists.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const headers = getAuthHeaders()
|
|
13
|
+
* // { Accept: 'application/vnd.github+json', Authorization: 'Bearer ...' }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function getAuthHeaders(): Record<string, string>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Socket Lib - Built with esbuild */
|
|
3
|
+
"use strict";
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
var github_auth_exports = {};
|
|
32
|
+
__export(github_auth_exports, {
|
|
33
|
+
getAuthHeaders: () => getAuthHeaders
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(github_auth_exports);
|
|
36
|
+
var import_node_process = __toESM(require("node:process"));
|
|
37
|
+
function getAuthHeaders() {
|
|
38
|
+
const token = import_node_process.default.env["GH_TOKEN"] || import_node_process.default.env["GITHUB_TOKEN"];
|
|
39
|
+
const headers = {
|
|
40
|
+
Accept: "application/vnd.github+json",
|
|
41
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
42
|
+
};
|
|
43
|
+
if (token) {
|
|
44
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
45
|
+
}
|
|
46
|
+
return headers;
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
getAuthHeaders
|
|
51
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview GitHub release asset downloads.
|
|
3
|
+
*/
|
|
4
|
+
import type { AssetPattern, DownloadGitHubReleaseConfig, RepoConfig } from './github-types';
|
|
5
|
+
/**
|
|
6
|
+
* Download a binary from any GitHub repository with version caching.
|
|
7
|
+
*
|
|
8
|
+
* @param config - Download configuration
|
|
9
|
+
* @returns Path to the downloaded binary
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const binaryPath = await downloadGitHubRelease({
|
|
14
|
+
* owner: 'SocketDev', repo: 'socket-btm',
|
|
15
|
+
* toolName: 'lief', toolPrefix: 'lief-',
|
|
16
|
+
* assetName: 'lief-linux-x64', binaryName: 'lief',
|
|
17
|
+
* platformArch: 'linux-x64',
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function downloadGitHubRelease(config: DownloadGitHubReleaseConfig): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Download a specific release asset.
|
|
24
|
+
* Supports pattern matching for dynamic asset discovery.
|
|
25
|
+
*
|
|
26
|
+
* @param tag - Release tag name
|
|
27
|
+
* @param assetPattern - Asset name or pattern (glob string, prefix/suffix object, or RegExp)
|
|
28
|
+
* @param outputPath - Path to write the downloaded file
|
|
29
|
+
* @param repoConfig - Repository configuration (owner/repo)
|
|
30
|
+
* @param options - Additional options
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* await downloadReleaseAsset(
|
|
35
|
+
* 'v1.0.0', 'tool-linux-x64', '/tmp/tool',
|
|
36
|
+
* { owner: 'SocketDev', repo: 'socket-btm' },
|
|
37
|
+
* )
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function downloadReleaseAsset(tag: string, assetPattern: string | AssetPattern, outputPath: string, repoConfig: RepoConfig, options?: {
|
|
41
|
+
quiet?: boolean;
|
|
42
|
+
}): Promise<void>;
|