-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasset-names.ts
More file actions
79 lines (72 loc) · 2.49 KB
/
Copy pathasset-names.ts
File metadata and controls
79 lines (72 loc) · 2.49 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
78
79
/**
* @file Upstream janus release asset-name mapping per `platform-arch`. janus
* publishes per-platform tarballs under
* https://github.com/divmain/janus/releases/download/v<X.Y.Z>/. At v1.22.0
* only darwin-arm64 is shipped; this map will expand as upstream adds builds.
* Callers receive `undefined` for unsupported platforms — surface that as an
* actionable "janus is mac-arm64 only" error rather than blindly fetching a
* 404.
*/
import { ObjectFreeze, ObjectKeys } from '../../primordials/object'
export interface JanusAssetEntry {
/**
* Full asset filename (version-free; the helper interpolates the tag).
*/
readonly asset: string
}
export const JANUS_ASSET_MAP: Readonly<Record<string, JanusAssetEntry>> =
ObjectFreeze({
__proto__: null,
'darwin-arm64': ObjectFreeze({
__proto__: null,
asset: 'janus-aarch64-apple-darwin.tar.gz',
}) as unknown as JanusAssetEntry,
}) as unknown as Readonly<Record<string, JanusAssetEntry>>
/**
* Single source of truth for the platform-arch tokens janus ships. Derived from
* JANUS_ASSET_MAP keys so adding a new asset entry automatically updates the
* supported set. Use this from `from-download.ts` to throw a helpful error
* rather than letting the URL builder silently return undefined.
*/
export const JANUS_SUPPORTED_PLATFORM_ARCHES: readonly string[] = ObjectFreeze(
ObjectKeys(JANUS_ASSET_MAP),
) as readonly string[]
export function getJanusAssetEntry(
platformArch: string,
): JanusAssetEntry | undefined {
return JANUS_ASSET_MAP[platformArch]
}
export interface JanusDownloadOptions {
/**
* Janus release version, e.g. `'1.22.0'` (no `v` prefix; the helper prepends
* it for the release tag).
*/
version: string
/**
* Fleet platform-arch token — looked up in `JANUS_ASSET_MAP`. Returns
* `undefined` for any platform-arch janus doesn't ship a build for.
*/
platformArch: string
}
/**
* Build the GitHub release-asset download URL for an upstream janus binary.
* Returns `undefined` when no entry exists for the requested platform-arch.
*
* Reference: https://github.com/divmain/janus/releases.
*/
export function getJanusDownloadUrl(
options: JanusDownloadOptions,
): string | undefined {
const { platformArch, version } = {
__proto__: null,
...options,
} as typeof options
const entry = JANUS_ASSET_MAP[platformArch]
if (!entry) {
return undefined
}
return (
`https://github.com/divmain/janus/releases/download/v${version}/` +
entry.asset
)
}