mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 23:47:33 +00:00
fix(cli): pin the sherpa-onnx native package to the runtime's exact version
This commit is contained in:
@@ -136,7 +136,7 @@ export function loadBesideCli(name: OptionalPackage, cliUrl = import.meta.url):
|
||||
return pinnedCopyBesideCli(name, cliUrl) ? createRequire(cliUrl)(name) : null;
|
||||
}
|
||||
|
||||
function runNpm(args: string[]): Promise<void> {
|
||||
export function runNpm(args: string[]): Promise<void> {
|
||||
const npm = buildNpmCommand(args);
|
||||
const child = spawn(npm.command, npm.args, { stdio: ["ignore", "pipe", "pipe"] });
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -4,7 +4,13 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { DownloadOptions } from "../cloud/download.js";
|
||||
import { ensureParakeetModel, sherpaUnsupportedReason, type ModelFile } from "./sherpa.js";
|
||||
import {
|
||||
ensureParakeetModel,
|
||||
installSherpaRuntime,
|
||||
sherpaPlatformPackage,
|
||||
sherpaUnsupportedReason,
|
||||
type ModelFile,
|
||||
} from "./sherpa.js";
|
||||
|
||||
const file = (name: string, content: string): ModelFile => ({
|
||||
name,
|
||||
@@ -22,6 +28,26 @@ function fakeDownload(served: Record<string, string>) {
|
||||
});
|
||||
}
|
||||
|
||||
describe("installSherpaRuntime", () => {
|
||||
it.each([
|
||||
["darwin", "arm64", "sherpa-onnx-darwin-arm64@1.13.8"],
|
||||
["linux", "x64", "sherpa-onnx-linux-x64@1.13.8"],
|
||||
["win32", "ia32", "sherpa-onnx-win-ia32@1.13.8"],
|
||||
])("pins the %s-%s native package", (platform, arch, spec) => {
|
||||
expect(sherpaPlatformPackage(platform as NodeJS.Platform, arch)).toBe(spec);
|
||||
});
|
||||
|
||||
it("asks npm for the runtime and its native package at the same exact version", async () => {
|
||||
const run = vi.fn(async () => {
|
||||
throw new Error("stop before touching the cache");
|
||||
});
|
||||
await installSherpaRuntime(run).catch(() => undefined);
|
||||
const args = run.mock.calls[0]?.[0] as string[] | undefined;
|
||||
expect(args).toContain("sherpa-onnx-node@1.13.8");
|
||||
expect(args).toContain(sherpaPlatformPackage());
|
||||
});
|
||||
});
|
||||
|
||||
describe("ensureParakeetModel", () => {
|
||||
let dir: string;
|
||||
afterEach(() => rmSync(dir, { recursive: true, force: true }));
|
||||
|
||||
@@ -5,7 +5,7 @@ import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { downloadToFile } from "../cloud/download.js";
|
||||
import { CACHE_DIR, install, isInstalled } from "../utils/optionalPackages.js";
|
||||
import { CACHE_DIR, install, isInstalled, runNpm } from "../utils/optionalPackages.js";
|
||||
import {
|
||||
mergeWindowsToWords,
|
||||
SHERPA_ERROR_PREFIX,
|
||||
@@ -78,8 +78,14 @@ export function sherpaRuntimeInstalled(): boolean {
|
||||
return isInstalled(SHERPA_RUNTIME_DIR, RUNTIME);
|
||||
}
|
||||
|
||||
export function installSherpaRuntime(): Promise<void> {
|
||||
return install(SHERPA_RUNTIME_DIR, RUNTIME, RUNTIME_VERSION);
|
||||
/** The native package, pinned too: the runtime's own optionalDependencies accept any 1.13.x. */
|
||||
export function sherpaPlatformPackage(platform = process.platform, arch = process.arch): string {
|
||||
return `sherpa-onnx-${platform === "win32" ? "win" : platform}-${arch}@${RUNTIME_VERSION}`;
|
||||
}
|
||||
|
||||
export function installSherpaRuntime(run = runNpm): Promise<void> {
|
||||
const native = sherpaPlatformPackage();
|
||||
return install(SHERPA_RUNTIME_DIR, RUNTIME, RUNTIME_VERSION, (args) => run([...args, native]));
|
||||
}
|
||||
|
||||
/** Sizes only: hashing 650 MB on every transcribe is too slow, and install already verified them. */
|
||||
|
||||
Reference in New Issue
Block a user