🎥 Make videos programmatically with React
@remotion/studio: Restart with upgraded CLI
Jonny Burger8d4e53468eca
diff --git a/packages/cli/src/restart-studio-process.ts b/packages/cli/src/restart-studio-process.tsnew file mode 100644index 0000000000..3094e9bca1--- /dev/null+++ b/packages/cli/src/restart-studio-process.ts@@ -0,0 +1,32 @@+import {spawn} from 'node:child_process';++export const restartStudioProcess = ({+ command,+ args,+}: {+ command: string;+ args: string[];+}) => {+ return new Promise<void>((resolve, reject) => {+ const child = spawn(command, args, {+ stdio: 'inherit',+ });++ child.once('error', reject);+ child.once('close', (code, signal) => {+ if (signal !== null) {+ reject(+ new Error(`Restarted Studio process exited with signal ${signal}.`),+ );+ return;+ }++ if (code !== 0) {+ reject(new Error(`Restarted Studio process exited with code ${code}.`));+ return;+ }++ resolve();+ });+ });+};diff --git a/packages/cli/src/studio.ts b/packages/cli/src/studio.tsindex 15c0ad29bc..8abc2e77bb 100644--- a/packages/cli/src/studio.ts+++ b/packages/cli/src/studio.ts@@ -29,6 +29,7 @@ import {getRenderQueue,removeJob,} from './render-queue/queue';+import {restartStudioProcess} from './restart-studio-process';const {binariesDirectoryOption,@@ -350,6 +351,8 @@ export const studioCommand = async (return;}- // If the server is restarted through the UI, let's do the whole thing again.- await studioCommand(remotionRoot, args, logLevel);+ await restartStudioProcess({+ command: process.execPath,+ args: [...process.execArgv, ...process.argv.slice(1)],+ });};diff --git a/packages/cli/src/test/restart-studio-process.test.ts b/packages/cli/src/test/restart-studio-process.test.tsnew file mode 100644index 0000000000..27ffcec891--- /dev/null+++ b/packages/cli/src/test/restart-studio-process.test.ts@@ -0,0 +1,26 @@+import {expect, test} from 'bun:test';+import {restartStudioProcess} from '../restart-studio-process';++test('waits for the restarted process to exit', async () => {+ let exited = false;+ const restart = restartStudioProcess({+ command: process.execPath,+ args: ['-e', 'process.exit(0)'],+ }).then(() => {+ exited = true;+ });++ await Promise.resolve();+ expect(exited).toBe(false);+ await restart;+ expect(exited).toBe(true);+});++test('rejects if the restarted process fails', async () => {+ await expect(+ restartStudioProcess({+ command: process.execPath,+ args: ['-e', 'process.exit(4)'],+ }),+ ).rejects.toThrow('Restarted Studio process exited with code 4.');+});diff --git a/packages/studio-server/src/test/upgrade-remotion.test.ts b/packages/studio-server/src/test/upgrade-remotion.test.tsindex 3041ecc931..8e82d65fe4 100644--- a/packages/studio-server/src/test/upgrade-remotion.test.ts+++ b/packages/studio-server/src/test/upgrade-remotion.test.ts@@ -18,7 +18,7 @@ import {handleRequest} from '../preview-server/handler';// Run the actual upgrade CLI, replacing only the external package manager.test.skipIf(process.platform === 'win32')(- 'Studio upgrades through the CLI, reports installation failures, and acknowledges shutdown',+ 'Studio upgrades through the CLI, reports installation failures, and acknowledges restart',async () => {const root = await mkdtemp(path.join(tmpdir(), 'studio-upgrade-'));const previousPath = process.env.PATH;@@ -57,8 +57,8 @@ if (process.argv[2] === 'view') {process.env.PATH = `${bin}${path.delimiter}${previousPath}`;const server = createServer((request, response) => {const handler =- request.url === '/api/shutdown-studio'- ? allApiRoutes['/api/shutdown-studio']+ request.url === '/api/restart-studio'+ ? allApiRoutes['/api/restart-studio']: allApiRoutes['/api/upgrade-remotion'];handleRequest({request,@@ -117,12 +117,12 @@ if (process.argv[2] === 'view') {expect(await request('/api/upgrade-remotion', {version: '4.0.521'}),).toEqual({success: true, data: {}});- const shutdown = noOpUntilRestart();- expect(await request('/api/shutdown-studio', {})).toEqual({+ const restart = noOpUntilRestart();+ expect(await request('/api/restart-studio', {})).toEqual({success: true,data: {},});- expect(await shutdown).toBe('shutdown');+ expect(await restart).toBe('restart');} finally {process.env.PATH = previousPath;server.closeAllConnections();diff --git a/packages/studio/src/components/UpdateStatusContext.tsx b/packages/studio/src/components/UpdateStatusContext.tsxindex c26e96ac01..3fbe0ce714 100644--- a/packages/studio/src/components/UpdateStatusContext.tsx+++ b/packages/studio/src/components/UpdateStatusContext.tsx@@ -9,7 +9,7 @@ import React, {useState,} from 'react';import {VERSION} from 'remotion';-import {shutDownStudio} from '../api/shut-down-studio';+import {restartStudio} from '../api/restart-studio';import {getBrowserStudioOperations} from '../helpers/browser-studio-operations';import {canShowUpdates} from '../helpers/can-show-updates';import {StudioServerConnectionCtx} from '../helpers/client-id';@@ -24,18 +24,13 @@ export type Bug = {versions: string[];};-type UpgradeState =- | 'idle'- | 'upgrading'- | 'upgraded'- | 'shutting-down'- | 'shutdown';+type UpgradeState = 'idle' | 'upgrading' | 'upgraded' | 'restarting';type UpdateStatusContextValue = {readonly upgradeState: UpgradeState;readonly upgradeError: string | null;readonly upgrade: (version: string) => Promise<void>;- readonly shutdown: () => Promise<void>;+ readonly restart: () => Promise<void>;readonly error: string | null;readonly info: UpdateAvailableResponse | null;readonly knownBugs: Bug[] | null;@@ -70,17 +65,16 @@ export const UpdateStatusProvider: React.FC<{busy.current = false;}}, []);- const shutdown = useCallback(async () => {+ const restart = useCallback(async () => {if (busy.current) {return;}busy.current = true;- setUpgradeState('shutting-down');+ setUpgradeState('restarting');setUpgradeError(null);try {- await shutDownStudio();- setUpgradeState('shutdown');+ await restartStudio();} catch (err) {setUpgradeError((err as Error).message);setUpgradeState('upgraded');@@ -151,9 +145,9 @@ export const UpdateStatusProvider: React.FC<{upgradeState,upgradeError,upgrade,- shutdown,+ restart,};- }, [error, info, knownBugs, upgradeState, upgradeError, upgrade, shutdown]);+ }, [error, info, knownBugs, upgradeState, upgradeError, upgrade, restart]);return (<UpdateStatusContext.Provider value={value}>diff --git a/packages/studio/src/components/UpdatesSettings.tsx b/packages/studio/src/components/UpdatesSettings.tsxindex 2c30670547..7789d11018 100644--- a/packages/studio/src/components/UpdatesSettings.tsx+++ b/packages/studio/src/components/UpdatesSettings.tsx@@ -234,15 +234,8 @@ const RenderedReleaseNotes: React.FC<{export const UpdatesSettings: React.FC = () => {const {remotionSkillsInfo} = useSettings();- const {- error,- info,- knownBugs,- upgradeState,- upgradeError,- upgrade,- shutdown,- } = useUpdateStatus();+ const {error, info, knownBugs, upgradeState, upgradeError, upgrade, restart} =+ useUpdateStatus();const [releaseNotes, setReleaseNotes] = useState<| (GetReleaseNotesResponse & {currentVersion: string;@@ -331,19 +324,19 @@ export const UpdatesSettings: React.FC = () => {<div style={text}>{upgradeState === 'upgrading'? 'This may take a few minutes. You can follow the progress in your terminal.'- : upgradeState === 'shutdown'- ? 'Studio is shutting down. Run your Studio start command again in the terminal to use the new version.'- : 'Restart Studio to use the new version. Shut down the server below, then run your Studio start command again in the terminal.'}+ : upgradeState === 'restarting'+ ? 'Studio is restarting with the new version.'+ : 'Restart Studio to use the new version.'}</div>- {upgradeState === 'upgraded' || upgradeState === 'shutting-down' ? (+ {upgradeState === 'upgraded' || upgradeState === 'restarting' ? (<div style={{marginTop: 12}}><ModalButton- onClick={shutdown}- disabled={upgradeState === 'shutting-down'}+ onClick={restart}+ disabled={upgradeState === 'restarting'}>- {upgradeState === 'shutting-down'- ? 'Shutting down...'- : 'Shut down Studio'}+ {upgradeState === 'restarting'+ ? 'Restarting...'+ : 'Restart Studio'}</ModalButton></div>) : null}