-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrom-download.ts
More file actions
77 lines (70 loc) · 2.75 KB
/
Copy pathfrom-download.ts
File metadata and controls
77 lines (70 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @file `janusFromDownload()` — fetches upstream janus and returns a
* `ResolvedJanus` pointing at the extracted binary. janus ships tar.gz
* archives containing a bare `janus` binary at the archive root (no nested
* directory). Defaults install under the shared wheelhouse dir
* (`~/.socket/_wheelhouse/janus/<version>/<platform-arch>/`) rather than the
* per-process dlx cache, so multiple fleet consumers reuse the same extracted
* binary.
*/
import path from 'node:path'
import { getSocketWheelhouseDir } from '../../paths/socket'
import { downloadAndExtractTool } from '../from-download'
import {
getJanusDownloadUrl,
JANUS_SUPPORTED_PLATFORM_ARCHES,
} from './asset-names'
import type { BinaryDownloader } from '../from-download'
import type { HashSpec } from '../../integrity'
import type { ResolvedJanus } from './types'
import { ErrorCtor } from '../../primordials/error'
export interface JanusFromDownloadOptions {
version: string
platformArch: string
integrity?: HashSpec | undefined
/**
* Override the install directory. By default the binary lands in
* `<getSocketWheelhouseDir()>/janus/<version>/<platformArch>/` — a shared
* cross-fleet location so multiple Socket tools resolve the same binary
* without per-process duplication.
*/
cacheDir?: string | undefined
downloader?: BinaryDownloader | undefined
}
export async function janusFromDownload(
options: JanusFromDownloadOptions,
): Promise<ResolvedJanus> {
const { cacheDir, downloader, integrity, platformArch, version } = {
__proto__: null,
...options,
} as typeof options
if (!JANUS_SUPPORTED_PLATFORM_ARCHES.includes(platformArch)) {
const supported = JANUS_SUPPORTED_PLATFORM_ARCHES.map(p => `\`${p}\``).join(
', ',
)
throw new ErrorCtor(
`janusFromDownload: platformArch must be one of [${supported}], got \`${platformArch}\`. Upstream janus only publishes the macOS arm64 build (see https://github.com/divmain/janus/releases); request \`darwin-arm64\` or use a different tool for other platforms.`,
)
}
const url = getJanusDownloadUrl({ version, platformArch })
if (!url) {
throw new ErrorCtor(
`janusFromDownload: no upstream asset for janus@${version} on \`${platformArch}\`. The platform is in the supported set but the version may be missing; check https://github.com/divmain/janus/releases/tag/v${version}.`,
)
}
const extractedDir =
cacheDir ??
path.join(getSocketWheelhouseDir(), 'janus', version, platformArch)
const archive = await downloadAndExtractTool({
url,
name: `janus-${version}-${platformArch}.tar.gz`,
integrity,
extractedDir,
downloader,
})
return {
path: path.join(extractedDir, 'janus'),
source: 'download',
integrity: archive.integrity,
}
}