🎥 Make videos programmatically with React
`@remotion/studio-server`: Try to find root file based on entry point
Jonny Burger94d678e000d2
diff --git a/packages/studio-server/src/preview-server/project-info.ts b/packages/studio-server/src/preview-server/project-info.tsindex e92c3646b4..3071b874bc 100644--- a/packages/studio-server/src/preview-server/project-info.ts+++ b/packages/studio-server/src/preview-server/project-info.ts@@ -2,8 +2,11 @@ import type {ProjectInfo} from '@remotion/studio-shared';import {existsSync} from 'node:fs';import path from 'node:path';-export const getProjectInfo = (remotionRoot: string): Promise<ProjectInfo> => {- const pathsToLookFor = [+export const getProjectInfo = (+ remotionRoot: string,+ entryPoint: string,+): Promise<ProjectInfo> => {+ const knownPaths = ['src/Root.tsx','src/Root.jsx','remotion/Root.tsx',@@ -13,9 +16,17 @@ export const getProjectInfo = (remotionRoot: string): Promise<ProjectInfo> => {'src/Video.jsx','src/remotion/Root.tsx','src/remotion/Root.jsx',- ].map((p) => {- return path.join(remotionRoot, p);- });+ ];++ const pathsToLookFor = [+ ...knownPaths.map((p) => {+ return path.join(remotionRoot, p);+ }),+ path.join(entryPoint, 'Root.tsx'),+ path.join(entryPoint, 'Root.jsx'),+ path.join(entryPoint, 'remotion/Root.tsx'),+ path.join(entryPoint, 'remotion/Root.jsx'),+ ];const rootFile = pathsToLookFor.find((p) => existsSync(p)) ?? null;diff --git a/packages/studio-server/src/preview-server/routes/apply-codemod.ts b/packages/studio-server/src/preview-server/routes/apply-codemod.tsindex cc83e0ea63..a0aeeb2c27 100644--- a/packages/studio-server/src/preview-server/routes/apply-codemod.ts+++ b/packages/studio-server/src/preview-server/routes/apply-codemod.ts@@ -16,10 +16,10 @@ import {checkIfTypeScriptFile} from './can-update-default-props';export const applyCodemodHandler: ApiHandler<ApplyCodemodRequest,ApplyCodemodResponse-> = async ({input: {codemod, dryRun}, logLevel, remotionRoot}) => {+> = async ({input: {codemod, dryRun}, logLevel, remotionRoot, entryPoint}) => {try {const time = Date.now();- const projectInfo = await getProjectInfo(remotionRoot);+ const projectInfo = await getProjectInfo(remotionRoot, entryPoint);if (!projectInfo.rootFile) {throw new Error('Cannot find root file in project');}diff --git a/packages/studio-server/src/preview-server/routes/can-update-default-props.ts b/packages/studio-server/src/preview-server/routes/can-update-default-props.tsindex f492b9142a..b90180fec6 100644--- a/packages/studio-server/src/preview-server/routes/can-update-default-props.ts+++ b/packages/studio-server/src/preview-server/routes/can-update-default-props.ts@@ -21,9 +21,9 @@ export const checkIfTypeScriptFile = (file: string) => {export const canUpdateDefaultPropsHandler: ApiHandler<CanUpdateDefaultPropsRequest,CanUpdateDefaultPropsResponse-> = async ({input: {compositionId}, remotionRoot}) => {+> = async ({input: {compositionId}, remotionRoot, entryPoint}) => {try {- const projectInfo = await getProjectInfo(remotionRoot);+ const projectInfo = await getProjectInfo(remotionRoot, entryPoint);if (!projectInfo.rootFile) {throw new Error('Cannot find root file in project');}diff --git a/packages/studio-server/src/preview-server/routes/project-info.ts b/packages/studio-server/src/preview-server/routes/project-info.tsindex acee4f08f9..f2afbe39e7 100644--- a/packages/studio-server/src/preview-server/routes/project-info.ts+++ b/packages/studio-server/src/preview-server/routes/project-info.ts@@ -8,7 +8,7 @@ import {getProjectInfo} from '../project-info';export const projectInfoHandler: ApiHandler<ProjectInfoRequest,ProjectInfoResponse-> = async ({remotionRoot}) => {- const info = await getProjectInfo(remotionRoot);+> = async ({remotionRoot, entryPoint}) => {+ const info = await getProjectInfo(remotionRoot, entryPoint);return {projectInfo: info};};diff --git a/packages/studio-server/src/preview-server/routes/update-default-props.ts b/packages/studio-server/src/preview-server/routes/update-default-props.tsindex d8d433b0b1..d7fca95c43 100644--- a/packages/studio-server/src/preview-server/routes/update-default-props.ts+++ b/packages/studio-server/src/preview-server/routes/update-default-props.ts@@ -11,9 +11,13 @@ import {checkIfTypeScriptFile} from './can-update-default-props';export const updateDefaultPropsHandler: ApiHandler<UpdateDefaultPropsRequest,UpdateDefaultPropsResponse-> = async ({input: {compositionId, defaultProps, enumPaths}, remotionRoot}) => {+> = async ({+ input: {compositionId, defaultProps, enumPaths},+ remotionRoot,+ entryPoint,+}) => {try {- const projectInfo = await getProjectInfo(remotionRoot);+ const projectInfo = await getProjectInfo(remotionRoot, entryPoint);if (!projectInfo.rootFile) {throw new Error('Cannot find root file in project');}diff --git a/packages/studio-server/src/start-studio.ts b/packages/studio-server/src/start-studio.tsindex d09d5659c3..1100ad6f13 100644--- a/packages/studio-server/src/start-studio.ts+++ b/packages/studio-server/src/start-studio.ts@@ -119,7 +119,7 @@ export const startStudio = async ({}} catch {}- watchRootFile(remotionRoot);+ watchRootFile(remotionRoot, previewEntry);const publicDir = getAbsolutePublicDir({relativePublicDir,remotionRoot,diff --git a/packages/studio-server/src/watch-root-file.ts b/packages/studio-server/src/watch-root-file.tsindex d0a6274b62..3fc6e87301 100644--- a/packages/studio-server/src/watch-root-file.ts+++ b/packages/studio-server/src/watch-root-file.ts@@ -2,8 +2,11 @@ import {installFileWatcher} from './file-watcher';import {waitForLiveEventsListener} from './preview-server/live-events';import {getProjectInfo} from './preview-server/project-info';-export const watchRootFile = async (remotionRoot: string) => {- const rootFile = await getProjectInfo(remotionRoot);+export const watchRootFile = async (+ remotionRoot: string,+ entryPoint: string,+) => {+ const rootFile = await getProjectInfo(remotionRoot, entryPoint);if (!rootFile.rootFile) {return;}