🎥 Make videos programmatically with React
Fix Whisper installation in Windows paths containing spaces
Jonny Burgerb8b2d2f5db88
diff --git a/packages/install-whisper-cpp/src/install-whisper-cpp.ts b/packages/install-whisper-cpp/src/install-whisper-cpp.tsindex ba3c04dcd5..738dbefd5d 100644--- a/packages/install-whisper-cpp/src/install-whisper-cpp.ts+++ b/packages/install-whisper-cpp/src/install-whisper-cpp.ts@@ -14,14 +14,14 @@ const execute = ({printOutput,signal,cwd,- shell,+ env,args,bin,}: {printOutput: boolean;signal: AbortSignal | null;cwd: string | null;- shell: string | null;+ env: NodeJS.ProcessEnv | null;bin: string;args: string[];}) => {@@ -32,7 +32,7 @@ const execute = ({stdio,signal: signal ?? undefined,cwd: cwd ?? undefined,- shell: shell ?? undefined,+ env: env ?? undefined,});child.on('exit', (code, exitSignal) => {@@ -83,12 +83,21 @@ const installForWindows = async ({});await execute({- shell: 'powershell',+ env: {+ ...process.env,+ REMOTION_WHISPER_ARCHIVE: filePath,+ REMOTION_WHISPER_DESTINATION: to,+ },printOutput,signal,cwd: null,- bin: 'Expand-Archive',- args: ['-Force', filePath, to],+ bin: 'powershell.exe',+ args: [+ '-NoProfile',+ '-NonInteractive',+ '-Command',+ 'Expand-Archive -Force -LiteralPath $env:REMOTION_WHISPER_ARCHIVE -DestinationPath $env:REMOTION_WHISPER_DESTINATION -ErrorAction Stop',+ ],});rmSync(filePath);@@ -111,7 +120,7 @@ const installWhisperForUnix = async ({printOutput,signal,cwd: null,- shell: null,+ env: null,});const ref = getIsSemVer(version) ? `v${version}` : version;@@ -122,7 +131,7 @@ const installWhisperForUnix = async ({printOutput,cwd: to,signal,- shell: null,+ env: null,});await execute({@@ -131,7 +140,7 @@ const installWhisperForUnix = async ({cwd: to,signal,printOutput,- shell: null,+ env: null,});};diff --git a/packages/install-whisper-cpp/src/test/install-whisper-cpp.test.ts b/packages/install-whisper-cpp/src/test/install-whisper-cpp.test.tsnew file mode 100644index 0000000000..9511683dd9--- /dev/null+++ b/packages/install-whisper-cpp/src/test/install-whisper-cpp.test.ts@@ -0,0 +1,78 @@+import {expect, spyOn, test} from 'bun:test';+import {execFileSync} from 'child_process';+import {+ existsSync,+ mkdirSync,+ mkdtempSync,+ readFileSync,+ rmSync,+ writeFileSync,+} from 'fs';+import os from 'os';+import path from 'path';+import {installWhisperCpp} from '../install-whisper-cpp';++test.skipIf(process.platform !== 'win32')(+ 'installs Whisper in Windows paths containing spaces and PowerShell characters',+ async () => {+ const root = mkdtempSync(path.join(os.tmpdir(), 'remotion-whisper-'));+ const previousCwd = process.cwd();+ const project = path.join(+ root,+ "NodeJs Projects [1] $value & 'quote' `tick`",+ );+ const to = path.join(+ project,+ "data [2] $value & 'quote' `tick`",+ 'whisper.cpp',+ );+ const source = path.join(root, 'main.exe');+ const archive = path.join(root, 'fixture.zip');+ const executableContents = 'Whisper executable fixture';+ const fetchSpy = spyOn(globalThis, 'fetch');++ try {+ mkdirSync(project);+ writeFileSync(source, executableContents);+ execFileSync(+ 'powershell.exe',+ [+ '-NoProfile',+ '-NonInteractive',+ '-Command',+ 'Compress-Archive -LiteralPath $env:WHISPER_TEST_SOURCE -DestinationPath $env:WHISPER_TEST_ARCHIVE -ErrorAction Stop',+ ],+ {+ env: {+ ...process.env,+ WHISPER_TEST_SOURCE: source,+ WHISPER_TEST_ARCHIVE: archive,+ },+ },+ );+ const zip = readFileSync(archive);+ fetchSpy.mockResolvedValue(+ new Response(new Uint8Array(zip).buffer, {+ headers: {'content-length': String(zip.length)},+ }),+ );+ process.chdir(project);++ expect(+ await installWhisperCpp({to, version: '1.5.5', printOutput: false}),+ ).toEqual({alreadyExisted: false});+ expect(readFileSync(path.join(to, 'main.exe'), 'utf8')).toBe(+ executableContents,+ );+ expect(existsSync(path.join(project, 'whisper-bin-x64.zip'))).toBe(false);+ expect(+ await installWhisperCpp({to, version: '1.5.5', printOutput: false}),+ ).toEqual({alreadyExisted: true});+ } finally {+ fetchSpy.mockRestore();+ process.chdir(previousCwd);+ rmSync(root, {recursive: true, force: true});+ }+ },+ 30_000,+);