fix(cli): pin the sherpa-onnx native package to the runtime's exact version

This commit is contained in:
Miguel Ángel
2026-09-26 23:06:04 -04:00
parent 46d7937d14
commit 87208de524
3 changed files with 37 additions and 5 deletions
+1 -1
View File
@@ -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) => {
+27 -1
View File
@@ -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 }));
+9 -3
View File
@@ -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. */