Repository navigation
Expand file tree
/
Copy pathbun.ts
More file actions
79 lines (67 loc) · 2.12 KB
/
Copy pathbun.ts
File metadata and controls
79 lines (67 loc) · 2.12 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
import fs from 'node:fs/promises';
import { join } from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';
@injectable()
@injectFromHierarchy()
export class BunInstallService extends BaseInstallService {
readonly name = 'bun';
/** The architecture name used by the bun release assets. */
private get ghArch(): string {
switch (this.envSvc.arch) {
case 'arm64':
return 'aarch64';
case 'amd64':
return 'x64';
}
}
/**
* Downloads the bun archive from GitHub, verified against the release's
* `SHASUMS256.txt`, and extracts it into the versioned `bin` folder. On x64
* without AVX2 the baseline build is used.
*/
override async install(version: string): Promise<void> {
const baseUrl = `https://github.com/oven-sh/bun/releases/download/bun-v${version}/`;
let { ghArch } = this;
if (ghArch === 'x64') {
try {
const cpuInfo = await fs.readFile('/proc/cpuinfo', 'utf-8');
if (!cpuInfo.includes('avx2')) {
ghArch = 'x64-baseline';
}
} catch {
ghArch = 'x64-baseline';
}
}
const filename = `bun-linux-${ghArch}.zip`;
const expectedChecksum = await this.findChecksum(
`${baseUrl}SHASUMS256.txt`,
filename,
);
const file = await this.http.download({
url: `${baseUrl}${filename}`,
checksumType: 'sha256',
expectedChecksum,
});
await this.pathSvc.ensureToolPath(this.name);
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await this.compress.extract({
file,
cwd: path,
strip: 1,
});
}
/** Links the `bun` binary into the global bin folder. */
override async link(version: string): Promise<void> {
const src = join(this.pathSvc.versionedToolPath(this.name, version), 'bin');
await this.shellwrapper({ srcDir: src });
}
/** Checks that `bun --version` runs. */
override async test(_version: string): Promise<void> {
await this._spawn(this.name, ['--version']);
}
}