Repository navigation
Expand file tree
/
Copy pathsbt.ts
More file actions
99 lines (83 loc) · 3.45 KB
/
Copy pathsbt.ts
File metadata and controls
99 lines (83 loc) · 3.45 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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';
import { BasePrepareService } from '../../prepare-tool/base-prepare.service.ts';
import { semverGte } from '../../utils/index.ts';
@injectable()
@injectFromHierarchy()
export class SbtPrepareService extends BasePrepareService {
override readonly name = 'sbt';
/** Initializes the cache and links `~/.sbt` to it, keeping an existing one. */
override async prepare(): Promise<void> {
await this.initialize();
await this.pathSvc.createSymlink(
join(this.pathSvc.cachePath, '.sbt'),
join(this.envSvc.userHome, '.sbt'),
);
}
/** Creates the `.sbt` folder in the containerbase cache. */
override async initialize(): Promise<void> {
await this.pathSvc.createDir(join(this.pathSvc.cachePath, '.sbt'));
}
}
@injectable()
@injectFromHierarchy()
export class SbtInstallService extends BaseInstallService {
override readonly name = 'sbt';
/** Older releases have no assets. */
override readonly minVersion = '0.13.17';
override readonly parent = 'java';
/** The sbt launcher's downloaded sbt and scala versions. */
override readonly cacheDirs = ['.sbt/boot'];
/**
* Downloads the sbt archive from GitHub, extracts it into the versioned tool
* path and drops the macOS and Windows launchers. The file and its checksum
* come from the tool-versions data, without data it is verified against its
* `.sha256` since v1.3.5.
*/
override async install(version: string): Promise<void> {
const url = `https://github.com/sbt/sbt/releases/download/v${version}/${this.name}-${version}.tgz`;
// sbt only publishes a `.sha256` checksum file since v1.3.5.
const file = semverGte(version, '1.3.5')
? await this.downloadChecksumSidecar(version, url, '.sha256')
: await this.downloadWithoutChecksum(version, url);
await this.pathSvc.ensureToolPath(this.name);
const path = await this.pathSvc.createVersionedToolPath(this.name, version);
await this.compress.extract({ file, cwd: path, strip: 1 });
const bin = join(path, 'bin');
for (const f of await fs.readdir(bin)) {
if (f.endsWith('-darwin') || f.endsWith('.exe') || f.endsWith('.bat')) {
await fs.rm(join(bin, f));
}
}
}
/** Links the `sbt` launcher 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 `sbt --version` runs in an empty folder, then removes the
* temp and home data it leaves behind, keeping hidden entries in `~/.sbt`.
* @see {@link https://github.com/sbt/sbt/issues/1458}
*/
override async test(_version: string): Promise<void> {
await this.pathSvc.withTempDir(`${this.name}-`, async (tmp) => {
await this._spawn(this.name, ['--version'], { cwd: tmp });
});
// cleanup sbt temp data
await fs.rm(join(this.envSvc.tmpDir, '.sbt'), {
recursive: true,
force: true,
});
const home = join(this.envSvc.home, '.sbt');
for (const f of await fs.readdir(home).catch(() => [])) {
// keep hidden entries, like the shell glob `~/.sbt/*` did
if (f.startsWith('.')) {
continue;
}
await fs.rm(join(home, f), { recursive: true, force: true });
}
}
}