@drakulavich/kesha-voice-kit 1.2.0 → 1.2.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/package.json +1 -1
- package/src/engine-install.ts +49 -14
package/package.json
CHANGED
package/src/engine-install.ts
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import { dirname } from "path";
|
|
2
|
-
import { existsSync, mkdirSync, chmodSync } from "fs";
|
|
2
|
+
import { existsSync, mkdirSync, chmodSync, readFileSync, writeFileSync } from "fs";
|
|
3
3
|
import { getEngineBinPath, getEngineCapabilities } from "./engine";
|
|
4
4
|
import { log } from "./log";
|
|
5
5
|
import { streamResponseToFile } from "./progress";
|
|
6
6
|
|
|
7
7
|
const GITHUB_REPO = "drakulavich/kesha-voice-kit";
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Version-marker file written next to the engine binary on download (#151).
|
|
11
|
+
* Lets `kesha install` detect a stale cached engine after a CLI upgrade and
|
|
12
|
+
* re-download without requiring `--no-cache`.
|
|
13
|
+
*/
|
|
14
|
+
export function getVersionMarkerPath(binPath: string): string {
|
|
15
|
+
return `${binPath}.version`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Read the recorded version for the installed binary, or null if missing / empty. */
|
|
19
|
+
export function readInstalledEngineVersion(binPath: string): string | null {
|
|
20
|
+
try {
|
|
21
|
+
const v = readFileSync(getVersionMarkerPath(binPath), "utf-8").trim();
|
|
22
|
+
return v.length > 0 ? v : null;
|
|
23
|
+
} catch {
|
|
24
|
+
// Missing, unreadable, or permission-denied → treat as no marker so we re-download.
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function writeInstalledEngineVersion(binPath: string, version: string): void {
|
|
30
|
+
writeFileSync(getVersionMarkerPath(binPath), `${version}\n`);
|
|
31
|
+
}
|
|
32
|
+
|
|
9
33
|
function getEngineBinaryName(): string {
|
|
10
34
|
const platform = process.platform;
|
|
11
35
|
const arch = process.arch;
|
|
@@ -28,21 +52,31 @@ export async function downloadEngine(
|
|
|
28
52
|
options: InstallOptions = {},
|
|
29
53
|
): Promise<string> {
|
|
30
54
|
const binPath = getEngineBinPath();
|
|
55
|
+
const pkg = await Bun.file(new URL("../package.json", import.meta.url)).json();
|
|
56
|
+
// The engine version is tracked separately from the CLI version so
|
|
57
|
+
// CLI-only patch releases don't require cutting a new GitHub release
|
|
58
|
+
// + Rust rebuild. Fall back to the CLI version for backwards compat.
|
|
59
|
+
const engineVersion =
|
|
60
|
+
typeof pkg.keshaEngine?.version === "string"
|
|
61
|
+
? pkg.keshaEngine.version
|
|
62
|
+
: typeof pkg.version === "string"
|
|
63
|
+
? pkg.version
|
|
64
|
+
: "unknown";
|
|
31
65
|
|
|
32
|
-
|
|
33
|
-
|
|
66
|
+
const installedVersion = readInstalledEngineVersion(binPath);
|
|
67
|
+
const cacheValid =
|
|
68
|
+
!noCache && existsSync(binPath) && installedVersion === engineVersion;
|
|
69
|
+
|
|
70
|
+
if (cacheValid) {
|
|
71
|
+
log.success(`Engine binary already installed (v${engineVersion}).`);
|
|
34
72
|
} else {
|
|
73
|
+
// Log why we're downloading — helps diagnose surprising re-downloads.
|
|
74
|
+
if (existsSync(binPath) && installedVersion && installedVersion !== engineVersion) {
|
|
75
|
+
log.progress(
|
|
76
|
+
`Upgrading engine v${installedVersion} → v${engineVersion}...`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
35
79
|
const binaryName = getEngineBinaryName();
|
|
36
|
-
const pkg = await Bun.file(new URL("../package.json", import.meta.url)).json();
|
|
37
|
-
// The engine version is tracked separately from the CLI version so
|
|
38
|
-
// CLI-only patch releases don't require cutting a new GitHub release
|
|
39
|
-
// + Rust rebuild. Fall back to the CLI version for backwards compat.
|
|
40
|
-
const engineVersion =
|
|
41
|
-
typeof pkg.keshaEngine?.version === "string"
|
|
42
|
-
? pkg.keshaEngine.version
|
|
43
|
-
: typeof pkg.version === "string"
|
|
44
|
-
? pkg.version
|
|
45
|
-
: "unknown";
|
|
46
80
|
const url = `https://github.com/${GITHUB_REPO}/releases/download/v${engineVersion}/${binaryName}`;
|
|
47
81
|
|
|
48
82
|
mkdirSync(dirname(binPath), { recursive: true });
|
|
@@ -64,7 +98,8 @@ export async function downloadEngine(
|
|
|
64
98
|
|
|
65
99
|
await streamResponseToFile(res, binPath, "kesha-engine binary");
|
|
66
100
|
chmodSync(binPath, 0o755);
|
|
67
|
-
|
|
101
|
+
writeInstalledEngineVersion(binPath, engineVersion);
|
|
102
|
+
log.success(`Engine binary downloaded (v${engineVersion}).`);
|
|
68
103
|
}
|
|
69
104
|
|
|
70
105
|
if (backend) {
|