🎥 Make videos programmatically with React
`@remotion/cli`: Preserve \`catalog:\` entries during \`remotion upgrade\`
Igor Samokhovets11a7ca946c98
diff --git a/packages/cli/src/catalog-utils.ts b/packages/cli/src/catalog-utils.tsnew file mode 100644index 0000000000..d96d4885fc--- /dev/null+++ b/packages/cli/src/catalog-utils.ts@@ -0,0 +1,272 @@+import fs from 'node:fs';+import path from 'node:path';++const WORKSPACE_ROOT_SEARCH_LIMIT = 5;++export const isCatalogProtocol = (version: string): boolean => {+ return version.startsWith('catalog:');+};++export const findVersionSpecifier = (+ depsWithVersions: {+ dependencies: Record<string, string>;+ devDependencies: Record<string, string>;+ optionalDependencies: Record<string, string>;+ peerDependencies: Record<string, string>;+ },+ pkg: string,+): string | null => {+ return (+ depsWithVersions.dependencies[pkg] ??+ depsWithVersions.devDependencies[pkg] ??+ depsWithVersions.optionalDependencies[pkg] ??+ depsWithVersions.peerDependencies[pkg] ??+ null+ );+};++export const findWorkspaceRoot = (startDir: string): string | null => {+ let currentDir = path.resolve(startDir);++ for (let i = 0; i < WORKSPACE_ROOT_SEARCH_LIMIT; i++) {+ const packageJsonPath = path.join(currentDir, 'package.json');++ if (fs.existsSync(packageJsonPath)) {+ try {+ const packageJson = JSON.parse(+ fs.readFileSync(packageJsonPath, 'utf-8'),+ );+ if (packageJson.workspaces) {+ return currentDir;+ }+ } catch {}+ }++ const pnpmWorkspacePath = path.join(currentDir, 'pnpm-workspace.yaml');+ if (fs.existsSync(pnpmWorkspacePath)) {+ return currentDir;+ }++ const parentDir = path.dirname(currentDir);+ if (parentDir === currentDir) {+ return null;+ }++ currentDir = parentDir;+ }++ return null;+};++type CatalogSource =+ | {type: 'package-json'; filePath: string; catalogKey: 'workspaces' | 'root'}+ | {type: 'pnpm-workspace'; filePath: string};++export const findCatalogSource = (+ workspaceRoot: string,+): CatalogSource | null => {+ const packageJsonPath = path.join(workspaceRoot, 'package.json');++ if (fs.existsSync(packageJsonPath)) {+ try {+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));++ if (+ packageJson.workspaces &&+ typeof packageJson.workspaces === 'object' &&+ !Array.isArray(packageJson.workspaces) &&+ packageJson.workspaces.catalog+ ) {+ return {+ type: 'package-json',+ filePath: packageJsonPath,+ catalogKey: 'workspaces',+ };+ }++ if (packageJson.catalog) {+ return {+ type: 'package-json',+ filePath: packageJsonPath,+ catalogKey: 'root',+ };+ }+ } catch {}+ }++ const pnpmWorkspacePath = path.join(workspaceRoot, 'pnpm-workspace.yaml');+ if (fs.existsSync(pnpmWorkspacePath)) {+ const content = fs.readFileSync(pnpmWorkspacePath, 'utf-8');+ if (/^catalog:/m.test(content)) {+ return {type: 'pnpm-workspace', filePath: pnpmWorkspacePath};+ }+ }++ return null;+};++export const getCatalogEntries = (+ workspaceRoot: string,+): Record<string, string> => {+ const source = findCatalogSource(workspaceRoot);+ if (!source) {+ return {};+ }++ if (source.type === 'package-json') {+ const packageJson = JSON.parse(fs.readFileSync(source.filePath, 'utf-8'));++ if (source.catalogKey === 'workspaces') {+ return (packageJson.workspaces.catalog ?? {}) as Record<string, string>;+ }++ return (packageJson.catalog ?? {}) as Record<string, string>;+ }++ return parsePnpmWorkspaceCatalog(fs.readFileSync(source.filePath, 'utf-8'));+};++export const parsePnpmWorkspaceCatalog = (+ content: string,+): Record<string, string> => {+ const lines = content.split('\n');+ const catalog: Record<string, string> = {};+ let inCatalogSection = false;++ for (const line of lines) {+ if (/^catalog:\s*$/.test(line)) {+ inCatalogSection = true;+ continue;+ }++ if (inCatalogSection && /^\S/.test(line) && line.trim() !== '') {+ inCatalogSection = false;+ continue;+ }++ if (inCatalogSection && line.trim() !== '') {+ const match = line.match(+ /^\s+(['"]?)([^'":\s]+)\1:\s*['"]?([^'"#\s]+)['"]?/,+ );+ if (match && match[2] && match[3]) {+ catalog[match[2]] = match[3];+ }+ }+ }++ return catalog;+};++export const updateCatalogEntryInPackageJson = ({+ filePath,+ catalogKey,+ pkg,+ newVersion,+}: {+ filePath: string;+ catalogKey: 'workspaces' | 'root';+ pkg: string;+ newVersion: string;+}): boolean => {+ const content = fs.readFileSync(filePath, 'utf-8');+ const packageJson = JSON.parse(content);++ const catalog =+ catalogKey === 'workspaces'+ ? packageJson.workspaces?.catalog+ : packageJson.catalog;++ if (!catalog || !(pkg in catalog)) {+ return false;+ }++ catalog[pkg] = newVersion;++ const indentMatch = content.match(/^(\s+)"/m);+ const indent = indentMatch ? indentMatch[1] : '\t';++ fs.writeFileSync(filePath, JSON.stringify(packageJson, null, indent) + '\n');++ return true;+};++export const updateCatalogEntryInPnpmWorkspace = ({+ filePath,+ pkg,+ newVersion,+}: {+ filePath: string;+ pkg: string;+ newVersion: string;+}): boolean => {+ const content = fs.readFileSync(filePath, 'utf-8');+ const lines = content.split('\n');+ let inCatalogSection = false;+ let updated = false;++ for (let i = 0; i < lines.length; i++) {+ const line = lines[i] as string;++ if (/^catalog:\s*$/.test(line)) {+ inCatalogSection = true;+ continue;+ }++ if (inCatalogSection && /^\S/.test(line) && line.trim() !== '') {+ inCatalogSection = false;+ continue;+ }++ if (inCatalogSection) {+ const escapedPkg = pkg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+ const lineRegex = new RegExp(+ `^(\\s+(?:['"]?)${escapedPkg}(?:['"]?):\\s*)(['"]?)([^'"#\\s]+)\\2(.*)$`,+ );+ const match = line.match(lineRegex);+ if (match) {+ const prefix = match[1] ?? '';+ const quote = match[2] ?? '';+ const suffix = match[4] ?? '';+ lines[i] = `${prefix}${quote}${newVersion}${quote}${suffix}`;+ updated = true;+ break;+ }+ }+ }++ if (updated) {+ fs.writeFileSync(filePath, lines.join('\n'));+ }++ return updated;+};++export const updateCatalogEntry = ({+ workspaceRoot,+ pkg,+ newVersion,+}: {+ workspaceRoot: string;+ pkg: string;+ newVersion: string;+}): boolean => {+ const source = findCatalogSource(workspaceRoot);+ if (!source) {+ return false;+ }++ if (source.type === 'package-json') {+ return updateCatalogEntryInPackageJson({+ filePath: source.filePath,+ catalogKey: source.catalogKey,+ pkg,+ newVersion,+ });+ }++ return updateCatalogEntryInPnpmWorkspace({+ filePath: source.filePath,+ pkg,+ newVersion,+ });+};diff --git a/packages/cli/src/test/catalog-utils.test.ts b/packages/cli/src/test/catalog-utils.test.tsnew file mode 100644index 0000000000..73f44852f2--- /dev/null+++ b/packages/cli/src/test/catalog-utils.test.ts@@ -0,0 +1,356 @@+import {afterEach, beforeEach, expect, test} from 'bun:test';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import {+ findCatalogSource,+ findVersionSpecifier,+ findWorkspaceRoot,+ getCatalogEntries,+ isCatalogProtocol,+ parsePnpmWorkspaceCatalog,+ updateCatalogEntry,+ updateCatalogEntryInPackageJson,+ updateCatalogEntryInPnpmWorkspace,+} from '../catalog-utils';++let tmpDir: string;++beforeEach(() => {+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'remotion-catalog-test-'));+});++afterEach(() => {+ fs.rmSync(tmpDir, {recursive: true, force: true});+});++test('isCatalogProtocol detects catalog: prefixes and rejects other version specifiers', () => {+ expect(isCatalogProtocol('catalog:')).toBe(true);+ expect(isCatalogProtocol('catalog:default')).toBe(true);+ expect(isCatalogProtocol('catalog:testing')).toBe(true);++ expect(isCatalogProtocol('^4.0.0')).toBe(false);+ expect(isCatalogProtocol('4.0.0')).toBe(false);+ expect(isCatalogProtocol('workspace:*')).toBe(false);+});++test('findVersionSpecifier finds packages across all dependency groups and returns null for unknown', () => {+ const depsWithVersions = {+ dependencies: {+ '@remotion/core': '^4.0.10',+ zod: 'catalog:',+ },+ devDependencies: {+ '@remotion/bundler': 'workspace:*',+ eslint: 'catalog:',+ },+ optionalDependencies: {+ sharp: '^0.34.0',+ },+ peerDependencies: {+ react: 'catalog:',+ },+ };++ expect(findVersionSpecifier(depsWithVersions, '@remotion/core')).toBe(+ '^4.0.10',+ );+ expect(findVersionSpecifier(depsWithVersions, '@remotion/bundler')).toBe(+ 'workspace:*',+ );+ expect(findVersionSpecifier(depsWithVersions, 'sharp')).toBe('^0.34.0');+ expect(findVersionSpecifier(depsWithVersions, 'react')).toBe('catalog:');+ expect(findVersionSpecifier(depsWithVersions, 'nonexistent')).toBeNull();+});++test('parsePnpmWorkspaceCatalog handles basic, quoted, scoped entries and stops at next top-level key', () => {+ const richContent = [+ 'packages:',+ ' - packages/*',+ 'catalog:',+ ' react: ^18.3.1',+ ' zod: 4.3.6',+ ' "react-dom": "^18.3.1"',+ " typescript: '5.8.3'",+ ' "@remotion/core": 4.0.10',+ ' "@aws-sdk/client-s3": 3.986.0',+ 'catalogs:',+ ' testing:',+ ' jest: 30.0.0',+ ].join('\n');++ const result = parsePnpmWorkspaceCatalog(richContent);+ expect(result.react).toBe('^18.3.1');+ expect(result.zod).toBe('4.3.6');+ expect(result['react-dom']).toBe('^18.3.1');+ expect(result.typescript).toBe('5.8.3');+ expect(result['@remotion/core']).toBe('4.0.10');+ expect(result['@aws-sdk/client-s3']).toBe('3.986.0');+ expect(result.jest).toBeUndefined();++ expect(parsePnpmWorkspaceCatalog('packages:\n - packages/*\n')).toEqual({});+});++test('bun-style monorepo: finds workspace root, catalog source, and reads entries', () => {+ fs.writeFileSync(+ path.join(tmpDir, 'package.json'),+ JSON.stringify({+ name: 'my-monorepo',+ workspaces: {+ packages: ['packages/*'],+ catalog: {+ react: '^19.0.0',+ zod: '4.3.6',+ },+ },+ }),+ );++ const subPkgDir = path.join(tmpDir, 'packages', 'my-app');+ fs.mkdirSync(subPkgDir, {recursive: true});+ fs.writeFileSync(+ path.join(subPkgDir, 'package.json'),+ JSON.stringify({name: 'my-app'}),+ );++ expect(findWorkspaceRoot(subPkgDir)).toBe(tmpDir);++ const source = findCatalogSource(tmpDir);+ expect(source).not.toBeNull();+ expect(source!.type).toBe('package-json');+ if (source!.type === 'package-json') {+ expect(source!.catalogKey).toBe('workspaces');+ }++ expect(getCatalogEntries(tmpDir)).toEqual({+ react: '^19.0.0',+ zod: '4.3.6',+ });+});++test('top-level catalog in package.json: finds catalog source and reads entries', () => {+ fs.writeFileSync(+ path.join(tmpDir, 'package.json'),+ JSON.stringify({+ name: 'my-monorepo',+ catalog: {zod: '4.3.6'},+ }),+ );++ const source = findCatalogSource(tmpDir);+ expect(source).not.toBeNull();+ expect(source!.type).toBe('package-json');+ if (source!.type === 'package-json') {+ expect(source!.catalogKey).toBe('root');+ }++ expect(getCatalogEntries(tmpDir)).toEqual({zod: '4.3.6'});+});++test('pnpm monorepo: finds workspace root, catalog source, and reads entries', () => {+ fs.writeFileSync(+ path.join(tmpDir, 'pnpm-workspace.yaml'),+ 'packages:\n - packages/*\ncatalog:\n zod: 4.3.6\n react: ^19.0.0\n',+ );++ const subPkgDir = path.join(tmpDir, 'packages', 'my-app');+ fs.mkdirSync(subPkgDir, {recursive: true});++ expect(findWorkspaceRoot(subPkgDir)).toBe(tmpDir);++ const source = findCatalogSource(tmpDir);+ expect(source).not.toBeNull();+ expect(source!.type).toBe('pnpm-workspace');++ expect(getCatalogEntries(tmpDir)).toEqual({+ zod: '4.3.6',+ react: '^19.0.0',+ });+});++test('standalone project: returns null/empty for workspace root, catalog source, and entries', () => {+ fs.writeFileSync(+ path.join(tmpDir, 'package.json'),+ JSON.stringify({name: 'standalone-project'}),+ );++ const deepDir = path.join(tmpDir, 'a', 'b', 'c', 'd', 'e', 'f', 'g');+ fs.mkdirSync(deepDir, {recursive: true});++ expect(findWorkspaceRoot(deepDir)).toBeNull();+ expect(findCatalogSource(tmpDir)).toBeNull();+ expect(getCatalogEntries(tmpDir)).toEqual({});+});++test('updating catalog entries in bun-style package.json', () => {+ const filePath = path.join(tmpDir, 'package.json');+ fs.writeFileSync(+ filePath,+ JSON.stringify(+ {+ name: 'my-monorepo',+ workspaces: {+ packages: ['packages/*'],+ catalog: {+ react: '^18.0.0',+ zod: '4.3.6',+ mediabunny: '1.34.4',+ },+ },+ },+ null,+ '\t',+ ) + '\n',+ );++ expect(+ updateCatalogEntryInPackageJson({+ filePath,+ catalogKey: 'workspaces',+ pkg: 'zod',+ newVersion: '4.4.0',+ }),+ ).toBe(true);++ const afterZodUpdate = JSON.parse(fs.readFileSync(filePath, 'utf-8'));+ expect(afterZodUpdate.workspaces.catalog.zod).toBe('4.4.0');+ expect(afterZodUpdate.workspaces.catalog.react).toBe('^18.0.0');++ expect(+ updateCatalogEntry({+ workspaceRoot: tmpDir,+ pkg: 'mediabunny',+ newVersion: '1.35.0',+ }),+ ).toBe(true);++ const afterBothUpdates = JSON.parse(fs.readFileSync(filePath, 'utf-8'));+ expect(afterBothUpdates.workspaces.catalog.mediabunny).toBe('1.35.0');+ expect(afterBothUpdates.workspaces.catalog.react).toBe('^18.0.0');++ expect(+ updateCatalogEntryInPackageJson({+ filePath,+ catalogKey: 'workspaces',+ pkg: 'nonexistent',+ newVersion: '1.0.0',+ }),+ ).toBe(false);+});++test('updating catalog entries in top-level package.json catalog', () => {+ const filePath = path.join(tmpDir, 'package.json');+ fs.writeFileSync(+ filePath,+ JSON.stringify(+ {+ name: 'my-monorepo',+ catalog: {zod: '4.3.6', mediabunny: '1.34.4'},+ },+ null,+ '\t',+ ) + '\n',+ );++ expect(+ updateCatalogEntryInPackageJson({+ filePath,+ catalogKey: 'root',+ pkg: 'mediabunny',+ newVersion: '1.35.0',+ }),+ ).toBe(true);++ const updated = JSON.parse(fs.readFileSync(filePath, 'utf-8'));+ expect(updated.catalog.mediabunny).toBe('1.35.0');+ expect(updated.catalog.zod).toBe('4.3.6');+});++test('updating catalog entries in pnpm-workspace.yaml', () => {+ const filePath = path.join(tmpDir, 'pnpm-workspace.yaml');+ fs.writeFileSync(+ filePath,+ [+ 'packages:',+ ' - packages/*',+ 'catalog:',+ ' react: ^18.3.1',+ ' zod: 4.3.6',+ ' "react-dom": "^18.3.1"',+ ' "@aws-sdk/client-s3": 3.986.0',+ 'catalogs:',+ ' testing:',+ ' jest: 30.0.0',+ '',+ ].join('\n'),+ );++ expect(+ updateCatalogEntryInPnpmWorkspace({+ filePath,+ pkg: 'zod',+ newVersion: '4.4.0',+ }),+ ).toBe(true);++ let content = fs.readFileSync(filePath, 'utf-8');+ expect(content).toContain('zod: 4.4.0');+ expect(content).toContain('react: ^18.3.1');++ expect(+ updateCatalogEntryInPnpmWorkspace({+ filePath,+ pkg: 'react-dom',+ newVersion: '^19.0.0',+ }),+ ).toBe(true);++ content = fs.readFileSync(filePath, 'utf-8');+ expect(content).toContain('"react-dom": "^19.0.0"');++ expect(+ updateCatalogEntryInPnpmWorkspace({+ filePath,+ pkg: '@aws-sdk/client-s3',+ newVersion: '3.987.0',+ }),+ ).toBe(true);++ content = fs.readFileSync(filePath, 'utf-8');+ expect(content).toContain('"@aws-sdk/client-s3": 3.987.0');+ expect(content).toContain('jest: 30.0.0');++ expect(+ updateCatalogEntryInPnpmWorkspace({+ filePath,+ pkg: 'nonexistent',+ newVersion: '1.0.0',+ }),+ ).toBe(false);++ expect(+ updateCatalogEntry({+ workspaceRoot: tmpDir,+ pkg: 'react',+ newVersion: '^19.0.0',+ }),+ ).toBe(true);++ content = fs.readFileSync(filePath, 'utf-8');+ expect(content).toContain('react: ^19.0.0');+});++test('updateCatalogEntry returns false when no catalog source exists', () => {+ fs.writeFileSync(+ path.join(tmpDir, 'package.json'),+ JSON.stringify({name: 'standalone'}),+ );++ expect(+ updateCatalogEntry({+ workspaceRoot: tmpDir,+ pkg: 'zod',+ newVersion: '4.4.0',+ }),+ ).toBe(false);+});diff --git a/packages/cli/src/test/upgrade-protocols.test.ts b/packages/cli/src/test/upgrade-protocols.test.tsnew file mode 100644index 0000000000..38c691ad8e--- /dev/null+++ b/packages/cli/src/test/upgrade-protocols.test.ts@@ -0,0 +1,223 @@+import {afterEach, beforeEach, expect, test} from 'bun:test';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import {+ findVersionSpecifier,+ isCatalogProtocol,+ updateCatalogEntry,+} from '../catalog-utils';++let tmpDir: string;++beforeEach(() => {+ tmpDir = fs.mkdtempSync(+ path.join(os.tmpdir(), 'remotion-upgrade-proto-test-'),+ );+});++afterEach(() => {+ fs.rmSync(tmpDir, {recursive: true, force: true});+});++const partitionPackages = (+ depsWithVersions: {+ dependencies: Record<string, string>;+ devDependencies: Record<string, string>;+ optionalDependencies: Record<string, string>;+ peerDependencies: Record<string, string>;+ },+ packagesToUpgrade: string[],+ targetVersion: string,+) => {+ const normalPackages: {pkg: string; version: string}[] = [];+ const catalogPackages: {pkg: string; version: string}[] = [];++ for (const pkg of packagesToUpgrade) {+ const versionSpec = findVersionSpecifier(depsWithVersions, pkg);++ if (versionSpec && isCatalogProtocol(versionSpec)) {+ catalogPackages.push({pkg, version: targetVersion});+ } else {+ normalPackages.push({pkg, version: targetVersion});+ }+ }++ return {normalPackages, catalogPackages};+};++test('partitions packages into normal and catalog groups', () => {+ const depsWithVersions = {+ dependencies: {+ '@remotion/core': '^4.0.10',+ '@remotion/player': '4.0.10',+ zod: 'catalog:',+ mediabunny: 'catalog:',+ },+ devDependencies: {+ '@remotion/eslint-config': 'catalog:default',+ jest: 'catalog:testing',+ },+ optionalDependencies: {},+ peerDependencies: {},+ };++ const semverResult = partitionPackages(+ depsWithVersions,+ ['@remotion/core', '@remotion/player'],+ '4.0.15',+ );+ expect(semverResult.normalPackages).toEqual([+ {pkg: '@remotion/core', version: '4.0.15'},+ {pkg: '@remotion/player', version: '4.0.15'},+ ]);+ expect(semverResult.catalogPackages).toEqual([]);++ const catalogResult = partitionPackages(+ depsWithVersions,+ ['zod', 'mediabunny', '@remotion/eslint-config'],+ '4.0.15',+ );+ expect(catalogResult.normalPackages).toEqual([]);+ expect(catalogResult.catalogPackages).toEqual([+ {pkg: 'zod', version: '4.0.15'},+ {pkg: 'mediabunny', version: '4.0.15'},+ {pkg: '@remotion/eslint-config', version: '4.0.15'},+ ]);++ const mixedResult = partitionPackages(+ depsWithVersions,+ ['@remotion/core', 'zod', '@remotion/player', 'mediabunny'],+ '4.0.15',+ );+ expect(mixedResult.normalPackages).toEqual([+ {pkg: '@remotion/core', version: '4.0.15'},+ {pkg: '@remotion/player', version: '4.0.15'},+ ]);+ expect(mixedResult.catalogPackages).toEqual([+ {pkg: 'zod', version: '4.0.15'},+ {pkg: 'mediabunny', version: '4.0.15'},+ ]);++ const emptyDeps = {+ dependencies: {},+ devDependencies: {},+ optionalDependencies: {},+ peerDependencies: {},+ };+ const unknownResult = partitionPackages(+ emptyDeps,+ ['@remotion/core'],+ '4.0.15',+ );+ expect(unknownResult.normalPackages).toEqual([+ {pkg: '@remotion/core', version: '4.0.15'},+ ]);+});++test('end-to-end: updates catalog in bun-style package.json and preserves catalog: references in sub-packages', () => {+ fs.writeFileSync(+ path.join(tmpDir, 'package.json'),+ JSON.stringify(+ {+ name: 'my-monorepo',+ workspaces: {+ packages: ['packages/*'],+ catalog: {+ zod: '4.3.6',+ mediabunny: '1.34.4',+ react: '19.2.3',+ },+ },+ },+ null,+ '\t',+ ) + '\n',+ );++ const subPkgDir = path.join(tmpDir, 'packages', 'my-app');+ fs.mkdirSync(subPkgDir, {recursive: true});+ fs.writeFileSync(+ path.join(subPkgDir, 'package.json'),+ JSON.stringify({+ name: 'my-app',+ dependencies: {+ '@remotion/core': '^4.0.10',+ zod: 'catalog:',+ },+ devDependencies: {+ mediabunny: 'catalog:',+ },+ }),+ );++ expect(+ updateCatalogEntry({+ workspaceRoot: tmpDir,+ pkg: 'zod',+ newVersion: '4.4.0',+ }),+ ).toBe(true);+ expect(+ updateCatalogEntry({+ workspaceRoot: tmpDir,+ pkg: 'mediabunny',+ newVersion: '1.35.0',+ }),+ ).toBe(true);++ const updatedRoot = JSON.parse(+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),+ );+ expect(updatedRoot.workspaces.catalog.zod).toBe('4.4.0');+ expect(updatedRoot.workspaces.catalog.mediabunny).toBe('1.35.0');+ expect(updatedRoot.workspaces.catalog.react).toBe('19.2.3');++ const subPkg = JSON.parse(+ fs.readFileSync(path.join(subPkgDir, 'package.json'), 'utf-8'),+ );+ expect(subPkg.dependencies.zod).toBe('catalog:');+ expect(subPkg.devDependencies.mediabunny).toBe('catalog:');+});++test('end-to-end: updates catalog in pnpm-workspace.yaml', () => {+ fs.writeFileSync(+ path.join(tmpDir, 'package.json'),+ JSON.stringify({name: 'my-monorepo'}),+ );+ fs.writeFileSync(+ path.join(tmpDir, 'pnpm-workspace.yaml'),+ [+ 'packages:',+ ' - packages/*',+ 'catalog:',+ ' zod: 4.3.6',+ ' mediabunny: 1.34.4',+ ' react: ^19.0.0',+ '',+ ].join('\n'),+ );++ expect(+ updateCatalogEntry({+ workspaceRoot: tmpDir,+ pkg: 'zod',+ newVersion: '4.4.0',+ }),+ ).toBe(true);+ expect(+ updateCatalogEntry({+ workspaceRoot: tmpDir,+ pkg: 'mediabunny',+ newVersion: '1.35.0',+ }),+ ).toBe(true);++ const content = fs.readFileSync(+ path.join(tmpDir, 'pnpm-workspace.yaml'),+ 'utf-8',+ );+ expect(content).toContain('zod: 4.4.0');+ expect(content).toContain('mediabunny: 1.35.0');+ expect(content).toContain('react: ^19.0.0');+});diff --git a/packages/cli/src/upgrade.ts b/packages/cli/src/upgrade.tsindex 5a7a440d26..b35fbbf510 100644--- a/packages/cli/src/upgrade.ts+++ b/packages/cli/src/upgrade.ts@@ -1,6 +1,12 @@import {RenderInternals, type LogLevel} from '@remotion/renderer';import {StudioServerInternals} from '@remotion/studio-server';import {execSync, spawn} from 'node:child_process';+import {+ findVersionSpecifier,+ findWorkspaceRoot,+ isCatalogProtocol,+ updateCatalogEntry,+} from './catalog-utils';import {chalk} from './chalk';import {EXTRA_PACKAGES} from './extra-packages';import {listOfRemotionPackages} from './list-of-remotion-packages';@@ -43,12 +49,8 @@ export const upgradeCommand = async ({logLevel: LogLevel;args: string[];}) => {- const {- dependencies,- devDependencies,- optionalDependencies,- peerDependencies,- } = StudioServerInternals.getInstalledDependencies(remotionRoot);+ const depsWithVersions =+ StudioServerInternals.getInstalledDependenciesWithVersions(remotionRoot);let targetVersion: string;if (version) {@@ -82,33 +84,23 @@ export const upgradeCommand = async ({}const allDeps = [- ...dependencies,- ...devDependencies,- ...optionalDependencies,- ...peerDependencies,+ ...Object.keys(depsWithVersions.dependencies),+ ...Object.keys(depsWithVersions.devDependencies),+ ...Object.keys(depsWithVersions.optionalDependencies),+ ...Object.keys(depsWithVersions.peerDependencies),];const remotionToUpgrade = listOfRemotionPackages.filter((u) =>allDeps.includes(u),);- // Check if extra packages (zod, mediabunny) are installedconst installedExtraPackages = Object.keys(EXTRA_PACKAGES).filter((pkg) =>allDeps.includes(pkg),);- // Get the correct versions for extra packages for this Remotion versionconst extraPackageVersions =getExtraPackageVersionsForRemotionVersion(targetVersion);- // Build the list of packages to upgrade- const packagesWithVersions = [- ...remotionToUpgrade.map((pkg) => `${pkg}@${targetVersion}`),- ...installedExtraPackages.map(- (pkg) => `${pkg}@${extraPackageVersions[pkg]}`,- ),- ];-if (installedExtraPackages.length > 0) {Log.info({indent: false, logLevel},@@ -116,19 +108,122 @@ export const upgradeCommand = async ({);}- const command = StudioServerInternals.getInstallCommand({- manager: manager.manager,- packages: packagesWithVersions,- version: '',- additionalArgs: args,- });+ const allPackagesToUpgrade = [+ ...remotionToUpgrade,+ ...installedExtraPackages,+ ];++ const normalPackages: {pkg: string; version: string}[] = [];+ const catalogPackages: {pkg: string; version: string}[] = [];++ for (const pkg of allPackagesToUpgrade) {+ const versionSpec = findVersionSpecifier(depsWithVersions, pkg);+ const targetVersionForPkg = extraPackageVersions[pkg] ?? targetVersion;- Log.info(- {indent: false, logLevel},- chalk.gray(`$ ${manager.manager} ${command.join(' ')}`),+ if (versionSpec && isCatalogProtocol(versionSpec)) {+ catalogPackages.push({pkg, version: targetVersionForPkg});+ } else {+ normalPackages.push({pkg, version: targetVersionForPkg});+ }+ }++ if (catalogPackages.length > 0) {+ const workspaceRoot = findWorkspaceRoot(remotionRoot);+ if (workspaceRoot) {+ const updatedCatalogEntries: string[] = [];+ const failedCatalogEntries: string[] = [];++ for (const {pkg, version: pkgVersion} of catalogPackages) {+ const didUpdate = updateCatalogEntry({+ workspaceRoot,+ pkg,+ newVersion: pkgVersion,+ });+ if (didUpdate) {+ updatedCatalogEntries.push(`${pkg}@${pkgVersion}`);+ } else {+ failedCatalogEntries.push(pkg);+ }+ }++ if (updatedCatalogEntries.length > 0) {+ Log.info(+ {indent: false, logLevel},+ chalk.green(+ `Updated catalog entries: ${updatedCatalogEntries.join(', ')}`,+ ),+ );+ }++ if (failedCatalogEntries.length > 0) {+ Log.warn(+ {indent: false, logLevel},+ chalk.yellow(+ `Could not find catalog entries for: ${failedCatalogEntries.join(', ')}. Update them manually.`,+ ),+ );+ }+ } else {+ Log.warn(+ {indent: false, logLevel},+ chalk.yellow(+ `Found catalog: references for ${catalogPackages.map((p) => p.pkg).join(', ')}, but could not find workspace root. Update the catalog entries manually.`,+ ),+ );+ }+ }++ const packagesWithVersions = normalPackages.map(+ ({pkg, version: pkgVersion}) => `${pkg}@${pkgVersion}`,);- const task = spawn(manager.manager, command, {+ if (packagesWithVersions.length > 0) {+ const command = StudioServerInternals.getInstallCommand({+ manager: manager.manager,+ packages: packagesWithVersions,+ version: '',+ additionalArgs: args,+ });++ Log.info(+ {indent: false, logLevel},+ chalk.gray(`$ ${manager.manager} ${command.join(' ')}`),+ );++ await runPackageManagerCommand({+ manager: manager.manager,+ command,+ logLevel,+ });+ }++ if (catalogPackages.length > 0 && packagesWithVersions.length === 0) {+ Log.info(+ {indent: false, logLevel},+ chalk.gray(`$ ${manager.manager} install`),+ );++ await runPackageManagerCommand({+ manager: manager.manager,+ command: ['install'],+ logLevel,+ });+ }++ Log.info({indent: false, logLevel}, '⏫ Remotion has been upgraded!');+ Log.info({indent: false, logLevel}, 'https://remotion.dev/changelog');+};++const runPackageManagerCommand = async ({+ manager,+ command,+ logLevel,+}: {+ manager: string;+ command: string[];+ logLevel: LogLevel;+}) => {+ const task = spawn(manager, command, {env: {...process.env,ADBLOCK: '1',@@ -152,7 +247,4 @@ export const upgradeCommand = async ({}});});-- Log.info({indent: false, logLevel}, '⏫ Remotion has been upgraded!');- Log.info({indent: false, logLevel}, 'https://remotion.dev/changelog');};diff --git a/packages/studio-server/src/helpers/get-installed-dependencies.ts b/packages/studio-server/src/helpers/get-installed-dependencies.tsindex 1745bedfd6..decd59859d 100644--- a/packages/studio-server/src/helpers/get-installed-dependencies.ts+++ b/packages/studio-server/src/helpers/get-installed-dependencies.ts@@ -1,20 +1,34 @@import fs from 'node:fs';import path from 'node:path';-export const getInstalledDependencies = (remotionRoot: string) => {+type DepsWithVersions = {+ dependencies: Record<string, string>;+ devDependencies: Record<string, string>;+ optionalDependencies: Record<string, string>;+ peerDependencies: Record<string, string>;+};++export const getInstalledDependenciesWithVersions = (+ remotionRoot: string,+): DepsWithVersions => {const packageJsonFilePath = path.join(remotionRoot, 'package.json');const packageJson = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));- const dependencies = Object.keys(packageJson.dependencies ?? {});- const devDependencies = Object.keys(packageJson.devDependencies ?? {});- const optionalDependencies = Object.keys(- packageJson.optionalDependencies ?? {},- );- const peerDependencies = Object.keys(packageJson.peerDependencies ?? {});return {- dependencies,- devDependencies,- optionalDependencies,- peerDependencies,+ dependencies: packageJson.dependencies ?? {},+ devDependencies: packageJson.devDependencies ?? {},+ optionalDependencies: packageJson.optionalDependencies ?? {},+ peerDependencies: packageJson.peerDependencies ?? {},+ };+};++export const getInstalledDependencies = (remotionRoot: string) => {+ const deps = getInstalledDependenciesWithVersions(remotionRoot);++ return {+ dependencies: Object.keys(deps.dependencies),+ devDependencies: Object.keys(deps.devDependencies),+ optionalDependencies: Object.keys(deps.optionalDependencies),+ peerDependencies: Object.keys(deps.peerDependencies),};};diff --git a/packages/studio-server/src/index.ts b/packages/studio-server/src/index.tsindex 92afc0e8fc..e606cc5df6 100644--- a/packages/studio-server/src/index.ts+++ b/packages/studio-server/src/index.ts@@ -32,7 +32,10 @@ import {import {parseAndApplyCodemod} from './codemods/duplicate-composition';import {installFileWatcher} from './file-watcher';import {getLatestRemotionVersion} from './get-latest-remotion-version';-import {getInstalledDependencies} from './helpers/get-installed-dependencies';+import {+ getInstalledDependencies,+ getInstalledDependenciesWithVersions,+} from './helpers/get-installed-dependencies';import {getInstallCommand} from './helpers/install-command';import {getMaxTimelineTracks,@@ -60,6 +63,7 @@ export const StudioServerInternals = {formatBytes,parseAndApplyCodemod,getInstalledDependencies,+ getInstalledDependenciesWithVersions,getInstallCommand,addCompletedClientRender,getCompletedClientRenders,