@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
package/dist/effects/ultra.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Ultrathink rainbow gradient effect.
|
|
3
|
-
* Provides rainbow gradient color generation for shimmer animations.
|
|
4
|
-
* "Ultrathink" is Claude's intensive thinking mode for deep analysis.
|
|
5
|
-
*/
|
|
6
|
-
import type { ShimmerColorGradient } from './types';
|
|
7
|
-
/**
|
|
8
|
-
* Rainbow gradient colors used for ultrathink effect.
|
|
9
|
-
* This gradient cycles through the full color spectrum with smooth transitions.
|
|
10
|
-
*/
|
|
11
|
-
export declare const RAINBOW_GRADIENT: ShimmerColorGradient;
|
|
12
|
-
/**
|
|
13
|
-
* Generate rainbow gradient colors for any text length.
|
|
14
|
-
* Colors are distributed evenly across the text by cycling through the gradient.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const colors = generateRainbowGradient('Hello'.length)
|
|
19
|
-
* console.log(colors.length) // 5
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare function generateRainbowGradient(textLength: number): ShimmerColorGradient;
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview GitHub release download utilities.
|
|
3
|
-
*/
|
|
4
|
-
import { type ArchiveFormat } from '../archives';
|
|
5
|
-
/**
|
|
6
|
-
* Pattern for matching release assets.
|
|
7
|
-
* Can be either:
|
|
8
|
-
* - A string with glob pattern syntax
|
|
9
|
-
* - A prefix/suffix pair for explicit matching (backward compatible)
|
|
10
|
-
* - A RegExp for complex patterns
|
|
11
|
-
*
|
|
12
|
-
* String patterns support full glob syntax via picomatch.
|
|
13
|
-
* Examples:
|
|
14
|
-
* - Simple wildcard: yoga-sync-*.mjs matches yoga-sync-abc123.mjs
|
|
15
|
-
* - Complex: models-*.tar.gz matches models-2024-01-15.tar.gz
|
|
16
|
-
* - Prefix wildcard: *-models.tar.gz matches foo-models.tar.gz
|
|
17
|
-
* - Suffix wildcard: yoga-* matches yoga-layout
|
|
18
|
-
* - Brace expansion: {yoga,models}-*.{mjs,js} matches yoga-abc.mjs or models-xyz.js
|
|
19
|
-
*
|
|
20
|
-
* For backward compatibility, prefix/suffix objects are still supported but glob patterns are recommended.
|
|
21
|
-
*/
|
|
22
|
-
export type AssetPattern = string | {
|
|
23
|
-
prefix: string;
|
|
24
|
-
suffix: string;
|
|
25
|
-
} | RegExp;
|
|
26
|
-
/**
|
|
27
|
-
* Configuration for downloading a GitHub release.
|
|
28
|
-
*/
|
|
29
|
-
export interface DownloadGitHubReleaseConfig {
|
|
30
|
-
/** Asset name on GitHub. */
|
|
31
|
-
assetName: string;
|
|
32
|
-
/** Binary filename (e.g., 'node', 'binject'). */
|
|
33
|
-
binaryName: string;
|
|
34
|
-
/** Working directory (defaults to process.cwd()). */
|
|
35
|
-
cwd?: string;
|
|
36
|
-
/** Download destination directory. @default 'build/downloaded' */
|
|
37
|
-
downloadDir?: string;
|
|
38
|
-
/** GitHub repository owner/organization. */
|
|
39
|
-
owner: string;
|
|
40
|
-
/** Platform-arch identifier (e.g., 'linux-x64-musl'). */
|
|
41
|
-
platformArch: string;
|
|
42
|
-
/** Suppress log messages. @default false */
|
|
43
|
-
quiet?: boolean;
|
|
44
|
-
/** Remove macOS quarantine attribute after download. @default true */
|
|
45
|
-
removeMacOSQuarantine?: boolean;
|
|
46
|
-
/** GitHub repository name. */
|
|
47
|
-
repo: string;
|
|
48
|
-
/** Specific release tag to download. */
|
|
49
|
-
tag?: string;
|
|
50
|
-
/** Tool name for directory structure. */
|
|
51
|
-
toolName: string;
|
|
52
|
-
/** Tool prefix for finding latest release. */
|
|
53
|
-
toolPrefix?: string;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Configuration for repository access.
|
|
57
|
-
*/
|
|
58
|
-
export interface RepoConfig {
|
|
59
|
-
/**
|
|
60
|
-
* GitHub repository owner/organization.
|
|
61
|
-
*/
|
|
62
|
-
owner: string;
|
|
63
|
-
/**
|
|
64
|
-
* GitHub repository name.
|
|
65
|
-
*/
|
|
66
|
-
repo: string;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Create a matcher function for a pattern using picomatch for glob patterns
|
|
70
|
-
* or simple prefix/suffix matching for object patterns.
|
|
71
|
-
*
|
|
72
|
-
* @param pattern - Pattern to match (string glob, prefix/suffix object, or RegExp)
|
|
73
|
-
* @returns Function that tests if a string matches the pattern
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```typescript
|
|
77
|
-
* const isMatch = createAssetMatcher('tool-*-linux-x64')
|
|
78
|
-
* isMatch('tool-v1.0-linux-x64') // true
|
|
79
|
-
* isMatch('tool-v1.0-darwin-arm64') // false
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
export declare function createAssetMatcher(pattern: string | {
|
|
83
|
-
prefix: string;
|
|
84
|
-
suffix: string;
|
|
85
|
-
} | RegExp): (input: string) => boolean;
|
|
86
|
-
/**
|
|
87
|
-
* Download and extract an archive from a GitHub release.
|
|
88
|
-
* Supports zip, tar, tar.gz, and tgz formats.
|
|
89
|
-
* Automatically handles downloading, extracting, and cleanup.
|
|
90
|
-
*
|
|
91
|
-
* @param tag - Release tag name
|
|
92
|
-
* @param assetPattern - Asset name or pattern (glob string, prefix/suffix object, or RegExp)
|
|
93
|
-
* @param outputDir - Directory to extract the archive contents to
|
|
94
|
-
* @param repoConfig - Repository configuration (owner/repo)
|
|
95
|
-
* @param options - Additional options
|
|
96
|
-
* @param options.quiet - Suppress log messages
|
|
97
|
-
* @param options.cleanup - Remove downloaded archive after extraction (default: true)
|
|
98
|
-
* @param options.strip - Strip leading path components (like tar --strip-components)
|
|
99
|
-
* @param options.format - Archive format (auto-detected if not specified)
|
|
100
|
-
* @returns Path to the extraction directory
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* const outputDir = await downloadAndExtractArchive(
|
|
105
|
-
* 'v1.0.0', 'data-*.tar.gz', '/tmp/data',
|
|
106
|
-
* { owner: 'SocketDev', repo: 'socket-btm' },
|
|
107
|
-
* )
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
export declare function downloadAndExtractArchive(tag: string, assetPattern: string | AssetPattern, outputDir: string, repoConfig: RepoConfig, options?: {
|
|
111
|
-
cleanup?: boolean;
|
|
112
|
-
format?: ArchiveFormat;
|
|
113
|
-
quiet?: boolean;
|
|
114
|
-
strip?: number;
|
|
115
|
-
}): Promise<string>;
|
|
116
|
-
/**
|
|
117
|
-
* Download and extract a zip file from a GitHub release.
|
|
118
|
-
* Automatically handles downloading, extracting, and cleanup.
|
|
119
|
-
*
|
|
120
|
-
* @param tag - Release tag name
|
|
121
|
-
* @param assetPattern - Asset name or pattern (glob string, prefix/suffix object, or RegExp)
|
|
122
|
-
* @param outputDir - Directory to extract the zip contents to
|
|
123
|
-
* @param repoConfig - Repository configuration (owner/repo)
|
|
124
|
-
* @param options - Additional options
|
|
125
|
-
* @param options.quiet - Suppress log messages
|
|
126
|
-
* @param options.cleanup - Remove downloaded zip file after extraction (default: true)
|
|
127
|
-
* @returns Path to the extraction directory
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```typescript
|
|
131
|
-
* const outputDir = await downloadAndExtractZip(
|
|
132
|
-
* 'v1.0.0', 'models-*.zip', '/tmp/models',
|
|
133
|
-
* { owner: 'SocketDev', repo: 'socket-btm' },
|
|
134
|
-
* )
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
export declare function downloadAndExtractZip(tag: string, assetPattern: string | AssetPattern, outputDir: string, repoConfig: RepoConfig, options?: {
|
|
138
|
-
cleanup?: boolean;
|
|
139
|
-
quiet?: boolean;
|
|
140
|
-
}): Promise<string>;
|
|
141
|
-
/**
|
|
142
|
-
* Download a binary from any GitHub repository with version caching.
|
|
143
|
-
*
|
|
144
|
-
* @param config - Download configuration
|
|
145
|
-
* @returns Path to the downloaded binary
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```typescript
|
|
149
|
-
* const binaryPath = await downloadGitHubRelease({
|
|
150
|
-
* owner: 'SocketDev', repo: 'socket-btm',
|
|
151
|
-
* toolName: 'lief', toolPrefix: 'lief-',
|
|
152
|
-
* assetName: 'lief-linux-x64', binaryName: 'lief',
|
|
153
|
-
* platformArch: 'linux-x64',
|
|
154
|
-
* })
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
export declare function downloadGitHubRelease(config: DownloadGitHubReleaseConfig): Promise<string>;
|
|
158
|
-
/**
|
|
159
|
-
* Download a specific release asset.
|
|
160
|
-
* Supports pattern matching for dynamic asset discovery.
|
|
161
|
-
*
|
|
162
|
-
* @param tag - Release tag name
|
|
163
|
-
* @param assetPattern - Asset name or pattern (glob string, prefix/suffix object, or RegExp)
|
|
164
|
-
* @param outputPath - Path to write the downloaded file
|
|
165
|
-
* @param repoConfig - Repository configuration (owner/repo)
|
|
166
|
-
* @param options - Additional options
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```typescript
|
|
170
|
-
* await downloadReleaseAsset(
|
|
171
|
-
* 'v1.0.0', 'tool-linux-x64', '/tmp/tool',
|
|
172
|
-
* { owner: 'SocketDev', repo: 'socket-btm' },
|
|
173
|
-
* )
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
export declare function downloadReleaseAsset(tag: string, assetPattern: string | AssetPattern, outputPath: string, repoConfig: RepoConfig, options?: {
|
|
177
|
-
quiet?: boolean;
|
|
178
|
-
}): Promise<void>;
|
|
179
|
-
/**
|
|
180
|
-
* Get GitHub authentication headers if token is available.
|
|
181
|
-
* Checks GH_TOKEN or GITHUB_TOKEN environment variables.
|
|
182
|
-
*
|
|
183
|
-
* @returns Headers object with Authorization header if token exists.
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* ```typescript
|
|
187
|
-
* const headers = getAuthHeaders()
|
|
188
|
-
* // { Accept: 'application/vnd.github+json', Authorization: 'Bearer ...' }
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
export declare function getAuthHeaders(): Record<string, string>;
|
|
192
|
-
/**
|
|
193
|
-
* Get latest release tag matching a tool prefix.
|
|
194
|
-
* Optionally filter by releases containing a matching asset.
|
|
195
|
-
*
|
|
196
|
-
* @param toolPrefix - Tool name prefix to search for (e.g., 'node-smol-')
|
|
197
|
-
* @param repoConfig - Repository configuration (owner/repo)
|
|
198
|
-
* @param options - Additional options
|
|
199
|
-
* @param options.assetPattern - Optional pattern to filter releases by matching asset
|
|
200
|
-
* @returns Latest release tag or null if not found
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* ```typescript
|
|
204
|
-
* const tag = await getLatestRelease('lief-', {
|
|
205
|
-
* owner: 'SocketDev', repo: 'socket-btm',
|
|
206
|
-
* })
|
|
207
|
-
* console.log(tag) // 'lief-2025-01-15-abc1234'
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
export declare function getLatestRelease(toolPrefix: string, repoConfig: RepoConfig, options?: {
|
|
211
|
-
assetPattern?: AssetPattern;
|
|
212
|
-
quiet?: boolean;
|
|
213
|
-
}): Promise<string | null>;
|
|
214
|
-
/**
|
|
215
|
-
* Get download URL for a specific release asset.
|
|
216
|
-
* Supports pattern matching for dynamic asset discovery.
|
|
217
|
-
*
|
|
218
|
-
* @param tag - Release tag name
|
|
219
|
-
* @param assetPattern - Asset name or pattern (glob string, prefix/suffix object, or RegExp)
|
|
220
|
-
* @param repoConfig - Repository configuration (owner/repo)
|
|
221
|
-
* @param options - Additional options
|
|
222
|
-
* @returns Browser download URL for the asset
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* ```typescript
|
|
226
|
-
* const url = await getReleaseAssetUrl(
|
|
227
|
-
* 'v1.0.0', 'tool-linux-x64',
|
|
228
|
-
* { owner: 'SocketDev', repo: 'socket-btm' },
|
|
229
|
-
* )
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
export declare function getReleaseAssetUrl(tag: string, assetPattern: string | AssetPattern, repoConfig: RepoConfig, options?: {
|
|
233
|
-
quiet?: boolean;
|
|
234
|
-
}): Promise<string | null>;
|
package/dist/releases/github.js
DELETED
|
@@ -1,417 +0,0 @@
|
|
|
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_exports = {};
|
|
32
|
-
__export(github_exports, {
|
|
33
|
-
createAssetMatcher: () => createAssetMatcher,
|
|
34
|
-
downloadAndExtractArchive: () => downloadAndExtractArchive,
|
|
35
|
-
downloadAndExtractZip: () => downloadAndExtractZip,
|
|
36
|
-
downloadGitHubRelease: () => downloadGitHubRelease,
|
|
37
|
-
downloadReleaseAsset: () => downloadReleaseAsset,
|
|
38
|
-
getAuthHeaders: () => getAuthHeaders,
|
|
39
|
-
getLatestRelease: () => getLatestRelease,
|
|
40
|
-
getReleaseAssetUrl: () => getReleaseAssetUrl
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(github_exports);
|
|
43
|
-
var import_node_process = __toESM(require("node:process"));
|
|
44
|
-
var import_picomatch = __toESM(require("../external/picomatch"));
|
|
45
|
-
var import_archives = require("../archives");
|
|
46
|
-
var import_errors = require("../errors");
|
|
47
|
-
var import_fs = require("../fs");
|
|
48
|
-
var import_http_request = require("../http-request");
|
|
49
|
-
var import_logger = require("../logger");
|
|
50
|
-
var import_promises = require("../promises");
|
|
51
|
-
var import_spawn = require("../spawn");
|
|
52
|
-
const RETRY_CONFIG = Object.freeze({
|
|
53
|
-
__proto__: null,
|
|
54
|
-
// Exponential backoff: delay doubles with each retry (5s, 10s, 20s).
|
|
55
|
-
backoffFactor: 2,
|
|
56
|
-
// Initial delay before first retry.
|
|
57
|
-
baseDelayMs: 5e3,
|
|
58
|
-
// Maximum number of retry attempts (excluding initial request).
|
|
59
|
-
retries: 2
|
|
60
|
-
});
|
|
61
|
-
const logger = (0, import_logger.getDefaultLogger)();
|
|
62
|
-
let _fs;
|
|
63
|
-
let _path;
|
|
64
|
-
// @__NO_SIDE_EFFECTS__
|
|
65
|
-
function getFs() {
|
|
66
|
-
if (_fs === void 0) {
|
|
67
|
-
_fs = require("node:fs");
|
|
68
|
-
}
|
|
69
|
-
return _fs;
|
|
70
|
-
}
|
|
71
|
-
// @__NO_SIDE_EFFECTS__
|
|
72
|
-
function getPath() {
|
|
73
|
-
if (_path === void 0) {
|
|
74
|
-
_path = require("node:path");
|
|
75
|
-
}
|
|
76
|
-
return _path;
|
|
77
|
-
}
|
|
78
|
-
function createAssetMatcher(pattern) {
|
|
79
|
-
if (typeof pattern === "string") {
|
|
80
|
-
const isMatch = (0, import_picomatch.default)(pattern);
|
|
81
|
-
return (input) => isMatch(input);
|
|
82
|
-
}
|
|
83
|
-
if (pattern instanceof RegExp) {
|
|
84
|
-
return (input) => pattern.test(input);
|
|
85
|
-
}
|
|
86
|
-
const { prefix, suffix } = pattern;
|
|
87
|
-
return (input) => input.startsWith(prefix) && input.endsWith(suffix);
|
|
88
|
-
}
|
|
89
|
-
async function downloadAndExtractArchive(tag, assetPattern, outputDir, repoConfig, options = {}) {
|
|
90
|
-
const { cleanup = true, format, quiet = false, strip } = options;
|
|
91
|
-
const path = /* @__PURE__ */ getPath();
|
|
92
|
-
const fs = /* @__PURE__ */ getFs();
|
|
93
|
-
await (0, import_fs.safeMkdir)(outputDir);
|
|
94
|
-
let ext = ".archive";
|
|
95
|
-
if (format) {
|
|
96
|
-
ext = format === "tar.gz" ? ".tar.gz" : `.${format}`;
|
|
97
|
-
} else if (typeof assetPattern === "string") {
|
|
98
|
-
const detectedFormat = (0, import_archives.detectArchiveFormat)(assetPattern);
|
|
99
|
-
if (detectedFormat) {
|
|
100
|
-
ext = detectedFormat === "tar.gz" ? ".tar.gz" : `.${detectedFormat}`;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const archivePath = path.join(outputDir, `__temp_download__${ext}`);
|
|
104
|
-
if (!quiet) {
|
|
105
|
-
logger.info(`Downloading archive from release ${tag}...`);
|
|
106
|
-
}
|
|
107
|
-
await downloadReleaseAsset(tag, assetPattern, archivePath, repoConfig, {
|
|
108
|
-
quiet
|
|
109
|
-
});
|
|
110
|
-
if (!quiet) {
|
|
111
|
-
logger.info(`Extracting archive to ${outputDir}...`);
|
|
112
|
-
}
|
|
113
|
-
try {
|
|
114
|
-
await (0, import_archives.extractArchive)(archivePath, outputDir, { quiet, strip });
|
|
115
|
-
if (!quiet) {
|
|
116
|
-
logger.info(`Extracted archive contents to ${outputDir}`);
|
|
117
|
-
}
|
|
118
|
-
} catch (cause) {
|
|
119
|
-
throw new Error(`Failed to extract archive: ${archivePath}`, { cause });
|
|
120
|
-
} finally {
|
|
121
|
-
if (cleanup) {
|
|
122
|
-
try {
|
|
123
|
-
await fs.promises.unlink(archivePath);
|
|
124
|
-
if (!quiet) {
|
|
125
|
-
logger.info("Cleaned up temporary archive file");
|
|
126
|
-
}
|
|
127
|
-
} catch (e) {
|
|
128
|
-
if (!quiet) {
|
|
129
|
-
logger.warn(`Failed to cleanup archive file: ${e}`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return outputDir;
|
|
135
|
-
}
|
|
136
|
-
async function downloadAndExtractZip(tag, assetPattern, outputDir, repoConfig, options = {}) {
|
|
137
|
-
const { cleanup = true, quiet = false } = options;
|
|
138
|
-
const path = /* @__PURE__ */ getPath();
|
|
139
|
-
const fs = /* @__PURE__ */ getFs();
|
|
140
|
-
await (0, import_fs.safeMkdir)(outputDir);
|
|
141
|
-
const zipPath = path.join(outputDir, "__temp_download__.zip");
|
|
142
|
-
if (!quiet) {
|
|
143
|
-
logger.info(`Downloading zip asset from release ${tag}...`);
|
|
144
|
-
}
|
|
145
|
-
await downloadReleaseAsset(tag, assetPattern, zipPath, repoConfig, { quiet });
|
|
146
|
-
if (!quiet) {
|
|
147
|
-
logger.info(`Extracting zip to ${outputDir}...`);
|
|
148
|
-
}
|
|
149
|
-
try {
|
|
150
|
-
await (0, import_archives.extractArchive)(zipPath, outputDir, { quiet });
|
|
151
|
-
if (!quiet) {
|
|
152
|
-
logger.info(`Extracted zip contents to ${outputDir}`);
|
|
153
|
-
}
|
|
154
|
-
} catch (cause) {
|
|
155
|
-
throw new Error(`Failed to extract zip file: ${zipPath}`, { cause });
|
|
156
|
-
} finally {
|
|
157
|
-
if (cleanup) {
|
|
158
|
-
try {
|
|
159
|
-
await fs.promises.unlink(zipPath);
|
|
160
|
-
if (!quiet) {
|
|
161
|
-
logger.info("Cleaned up temporary zip file");
|
|
162
|
-
}
|
|
163
|
-
} catch (e) {
|
|
164
|
-
if (!quiet) {
|
|
165
|
-
logger.warn(`Failed to cleanup zip file: ${e}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return outputDir;
|
|
171
|
-
}
|
|
172
|
-
async function downloadGitHubRelease(config) {
|
|
173
|
-
const {
|
|
174
|
-
assetName,
|
|
175
|
-
binaryName,
|
|
176
|
-
cwd = import_node_process.default.cwd(),
|
|
177
|
-
downloadDir = "build/downloaded",
|
|
178
|
-
owner,
|
|
179
|
-
platformArch,
|
|
180
|
-
quiet = false,
|
|
181
|
-
removeMacOSQuarantine = true,
|
|
182
|
-
repo,
|
|
183
|
-
tag: explicitTag,
|
|
184
|
-
toolName,
|
|
185
|
-
toolPrefix
|
|
186
|
-
} = config;
|
|
187
|
-
let tag;
|
|
188
|
-
if (explicitTag) {
|
|
189
|
-
tag = explicitTag;
|
|
190
|
-
} else if (toolPrefix) {
|
|
191
|
-
const latestTag = await getLatestRelease(
|
|
192
|
-
toolPrefix,
|
|
193
|
-
{ owner, repo },
|
|
194
|
-
{ quiet }
|
|
195
|
-
);
|
|
196
|
-
if (!latestTag) {
|
|
197
|
-
throw new Error(`No ${toolPrefix} release found in ${owner}/${repo}`);
|
|
198
|
-
}
|
|
199
|
-
tag = latestTag;
|
|
200
|
-
} else {
|
|
201
|
-
throw new Error("Either toolPrefix or tag must be provided");
|
|
202
|
-
}
|
|
203
|
-
const path = /* @__PURE__ */ getPath();
|
|
204
|
-
const resolvedDownloadDir = path.isAbsolute(downloadDir) ? downloadDir : path.join(cwd, downloadDir);
|
|
205
|
-
const binaryDir = resolvedDownloadDir;
|
|
206
|
-
const binaryPath = path.join(binaryDir, binaryName);
|
|
207
|
-
const versionPath = path.join(binaryDir, ".version");
|
|
208
|
-
const fs = /* @__PURE__ */ getFs();
|
|
209
|
-
if (fs.existsSync(versionPath) && fs.existsSync(binaryPath)) {
|
|
210
|
-
const cachedVersion = (await fs.promises.readFile(versionPath, "utf8")).trim();
|
|
211
|
-
if (cachedVersion === tag && fs.existsSync(binaryPath)) {
|
|
212
|
-
if (!quiet) {
|
|
213
|
-
logger.info(`Using cached ${toolName} (${platformArch}): ${binaryPath}`);
|
|
214
|
-
}
|
|
215
|
-
return binaryPath;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
if (!quiet) {
|
|
219
|
-
logger.info(`Downloading ${toolName} for ${platformArch}...`);
|
|
220
|
-
}
|
|
221
|
-
await downloadReleaseAsset(
|
|
222
|
-
tag,
|
|
223
|
-
assetName,
|
|
224
|
-
binaryPath,
|
|
225
|
-
{ owner, repo },
|
|
226
|
-
{ quiet }
|
|
227
|
-
);
|
|
228
|
-
const isWindows = binaryName.endsWith(".exe");
|
|
229
|
-
if (!isWindows) {
|
|
230
|
-
fs.chmodSync(binaryPath, 493);
|
|
231
|
-
if (removeMacOSQuarantine && import_node_process.default.platform === "darwin" && platformArch.startsWith("darwin")) {
|
|
232
|
-
try {
|
|
233
|
-
await (0, import_spawn.spawn)("xattr", ["-d", "com.apple.quarantine", binaryPath], {
|
|
234
|
-
stdio: "ignore"
|
|
235
|
-
});
|
|
236
|
-
} catch {
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
await fs.promises.writeFile(versionPath, tag, "utf8");
|
|
241
|
-
if (!quiet) {
|
|
242
|
-
logger.info(`Downloaded ${toolName} to ${binaryPath}`);
|
|
243
|
-
}
|
|
244
|
-
return binaryPath;
|
|
245
|
-
}
|
|
246
|
-
async function downloadReleaseAsset(tag, assetPattern, outputPath, repoConfig, options = {}) {
|
|
247
|
-
const { owner, repo } = repoConfig;
|
|
248
|
-
const { quiet = false } = options;
|
|
249
|
-
const downloadUrl = await getReleaseAssetUrl(
|
|
250
|
-
tag,
|
|
251
|
-
assetPattern,
|
|
252
|
-
{ owner, repo },
|
|
253
|
-
{ quiet }
|
|
254
|
-
);
|
|
255
|
-
if (!downloadUrl) {
|
|
256
|
-
const patternDesc = typeof assetPattern === "string" ? assetPattern : "matching pattern";
|
|
257
|
-
throw new Error(`Asset ${patternDesc} not found in release ${tag}`);
|
|
258
|
-
}
|
|
259
|
-
const path = /* @__PURE__ */ getPath();
|
|
260
|
-
await (0, import_fs.safeMkdir)(path.dirname(outputPath));
|
|
261
|
-
await (0, import_http_request.httpDownload)(downloadUrl, outputPath, {
|
|
262
|
-
logger: quiet ? void 0 : logger,
|
|
263
|
-
progressInterval: 10,
|
|
264
|
-
retries: 2,
|
|
265
|
-
retryDelay: 5e3
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
function getAuthHeaders() {
|
|
269
|
-
const token = import_node_process.default.env["GH_TOKEN"] || import_node_process.default.env["GITHUB_TOKEN"];
|
|
270
|
-
const headers = {
|
|
271
|
-
Accept: "application/vnd.github+json",
|
|
272
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
273
|
-
};
|
|
274
|
-
if (token) {
|
|
275
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
276
|
-
}
|
|
277
|
-
return headers;
|
|
278
|
-
}
|
|
279
|
-
async function getLatestRelease(toolPrefix, repoConfig, options = {}) {
|
|
280
|
-
const { assetPattern, quiet = false } = options;
|
|
281
|
-
const { owner, repo } = repoConfig;
|
|
282
|
-
const isMatch = assetPattern ? createAssetMatcher(assetPattern) : void 0;
|
|
283
|
-
return await (0, import_promises.pRetry)(
|
|
284
|
-
async () => {
|
|
285
|
-
const response = await (0, import_http_request.httpRequest)(
|
|
286
|
-
`https://api.github.com/repos/${owner}/${repo}/releases?per_page=100`,
|
|
287
|
-
{
|
|
288
|
-
headers: getAuthHeaders()
|
|
289
|
-
}
|
|
290
|
-
);
|
|
291
|
-
if (!response.ok) {
|
|
292
|
-
throw new Error(`Failed to fetch releases: ${response.status}`);
|
|
293
|
-
}
|
|
294
|
-
let releases;
|
|
295
|
-
try {
|
|
296
|
-
releases = JSON.parse(response.body.toString("utf8"));
|
|
297
|
-
} catch (cause) {
|
|
298
|
-
throw new Error(
|
|
299
|
-
`Failed to parse GitHub releases response from https://api.github.com/repos/${owner}/${repo}/releases`,
|
|
300
|
-
{ cause }
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
const matchingReleases = releases.filter((release) => {
|
|
304
|
-
const { assets, tag_name: tag2 } = release;
|
|
305
|
-
if (!tag2.startsWith(toolPrefix)) {
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
if (!assets || assets.length === 0) {
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
if (isMatch) {
|
|
312
|
-
const hasMatchingAsset = assets.some(
|
|
313
|
-
(a) => isMatch(a.name)
|
|
314
|
-
);
|
|
315
|
-
if (!hasMatchingAsset) {
|
|
316
|
-
return false;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return true;
|
|
320
|
-
});
|
|
321
|
-
if (matchingReleases.length === 0) {
|
|
322
|
-
if (!quiet) {
|
|
323
|
-
logger.info(`No ${toolPrefix} release found in latest 100 releases`);
|
|
324
|
-
}
|
|
325
|
-
return null;
|
|
326
|
-
}
|
|
327
|
-
matchingReleases.sort(
|
|
328
|
-
(a, b) => new Date(b.published_at).getTime() - new Date(a.published_at).getTime()
|
|
329
|
-
);
|
|
330
|
-
const latestRelease = matchingReleases[0];
|
|
331
|
-
const tag = latestRelease.tag_name;
|
|
332
|
-
if (!quiet) {
|
|
333
|
-
logger.info(`Found release: ${tag}`);
|
|
334
|
-
}
|
|
335
|
-
return tag;
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
...RETRY_CONFIG,
|
|
339
|
-
onRetry: (attempt, error) => {
|
|
340
|
-
if (!quiet) {
|
|
341
|
-
logger.info(
|
|
342
|
-
`Retry attempt ${attempt + 1}/${RETRY_CONFIG.retries + 1} for ${toolPrefix} release...`
|
|
343
|
-
);
|
|
344
|
-
logger.warn(
|
|
345
|
-
`Attempt ${attempt + 1}/${RETRY_CONFIG.retries + 1} failed: ${(0, import_errors.errorMessage)(error)}`
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
return void 0;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
) ?? null;
|
|
352
|
-
}
|
|
353
|
-
async function getReleaseAssetUrl(tag, assetPattern, repoConfig, options = {}) {
|
|
354
|
-
const { owner, repo } = repoConfig;
|
|
355
|
-
const { quiet = false } = options;
|
|
356
|
-
const isMatch = typeof assetPattern === "string" && !assetPattern.includes("*") && !assetPattern.includes("{") ? (input) => input === assetPattern : createAssetMatcher(assetPattern);
|
|
357
|
-
return await (0, import_promises.pRetry)(
|
|
358
|
-
async () => {
|
|
359
|
-
const response = await (0, import_http_request.httpRequest)(
|
|
360
|
-
`https://api.github.com/repos/${owner}/${repo}/releases/tags/${tag}`,
|
|
361
|
-
{
|
|
362
|
-
headers: getAuthHeaders()
|
|
363
|
-
}
|
|
364
|
-
);
|
|
365
|
-
if (!response.ok) {
|
|
366
|
-
throw new Error(`Failed to fetch release ${tag}: ${response.status}`);
|
|
367
|
-
}
|
|
368
|
-
let release;
|
|
369
|
-
try {
|
|
370
|
-
release = JSON.parse(response.body.toString("utf8"));
|
|
371
|
-
} catch (cause) {
|
|
372
|
-
throw new Error(
|
|
373
|
-
`Failed to parse GitHub release response for tag ${tag}`,
|
|
374
|
-
{ cause }
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
const assets = release.assets;
|
|
378
|
-
if (!Array.isArray(assets)) {
|
|
379
|
-
throw new Error(`Release ${tag} has no assets`);
|
|
380
|
-
}
|
|
381
|
-
const asset = assets.find((a) => isMatch(a.name));
|
|
382
|
-
if (!asset) {
|
|
383
|
-
const patternDesc = typeof assetPattern === "string" ? assetPattern : "matching pattern";
|
|
384
|
-
throw new Error(`Asset ${patternDesc} not found in release ${tag}`);
|
|
385
|
-
}
|
|
386
|
-
if (!quiet) {
|
|
387
|
-
logger.info(`Found asset: ${asset.name}`);
|
|
388
|
-
}
|
|
389
|
-
return asset.browser_download_url;
|
|
390
|
-
},
|
|
391
|
-
{
|
|
392
|
-
...RETRY_CONFIG,
|
|
393
|
-
onRetry: (attempt, error) => {
|
|
394
|
-
if (!quiet) {
|
|
395
|
-
logger.info(
|
|
396
|
-
`Retry attempt ${attempt + 1}/${RETRY_CONFIG.retries + 1} for asset URL...`
|
|
397
|
-
);
|
|
398
|
-
logger.warn(
|
|
399
|
-
`Attempt ${attempt + 1}/${RETRY_CONFIG.retries + 1} failed: ${(0, import_errors.errorMessage)(error)}`
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
return void 0;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
) ?? null;
|
|
406
|
-
}
|
|
407
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
408
|
-
0 && (module.exports = {
|
|
409
|
-
createAssetMatcher,
|
|
410
|
-
downloadAndExtractArchive,
|
|
411
|
-
downloadAndExtractZip,
|
|
412
|
-
downloadGitHubRelease,
|
|
413
|
-
downloadReleaseAsset,
|
|
414
|
-
getAuthHeaders,
|
|
415
|
-
getLatestRelease,
|
|
416
|
-
getReleaseAssetUrl
|
|
417
|
-
});
|