🎥 Make videos programmatically with React
`@remotion/bundler`: allow to pass a prebundled directory as entry point
Jonny Burgerc072adb02a4b
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.tsindex 7d90de8a79..3200d6ee1a 100644--- a/packages/cli/src/benchmark.ts+++ b/packages/cli/src/benchmark.ts@@ -164,11 +164,12 @@ export const benchmarkCommand = async () => {const runs: number = parsedCli.runs ?? DEFAULT_RUNS;- const {file, reason, remainingArgs} = findEntryPoint(+ const {file, reason, remainingArgs} = findEntryPoint({args,remotionRoot,logLevel,- );+ allowDirectory: true,+ });if (!file) {Log.error({indent: false, logLevel}, 'No entry file passed.');diff --git a/packages/cli/src/bundle.ts b/packages/cli/src/bundle.tsindex e65ac6d82e..aa49916e1a 100644--- a/packages/cli/src/bundle.ts+++ b/packages/cli/src/bundle.ts@@ -18,7 +18,12 @@ export const bundleCommand = async (args: string[],logLevel: LogLevel,) => {- const {file, reason} = findEntryPoint(args, remotionRoot, logLevel);+ const {file, reason} = findEntryPoint({+ args,+ remotionRoot,+ logLevel,+ allowDirectory: false,+ });const explicitlyPassed = args[0];if (explicitlyPassed &&diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.tsindex e9593ab0a1..e8bd126394 100644--- a/packages/cli/src/compositions.ts+++ b/packages/cli/src/compositions.ts@@ -25,7 +25,12 @@ export const listCompositionsCommand = async (args: string[],logLevel: LogLevel,) => {- const {file, reason} = findEntryPoint(args, remotionRoot, logLevel);+ const {file, reason} = findEntryPoint({+ args,+ remotionRoot,+ logLevel,+ allowDirectory: true,+ });if (!file) {Log.error(diff --git a/packages/cli/src/entry-point.ts b/packages/cli/src/entry-point.tsindex 4bc4a0f849..6b37f7e1dd 100644--- a/packages/cli/src/entry-point.ts+++ b/packages/cli/src/entry-point.ts@@ -1,6 +1,6 @@import type {LogLevel} from '@remotion/renderer';import {RenderInternals} from '@remotion/renderer';-import {existsSync, lstatSync} from 'node:fs';+import {existsSync} from 'node:fs';import path from 'node:path';import {ConfigInternals} from './config';import {Log} from './log';@@ -30,11 +30,17 @@ type FoundReason =| 'common paths'| 'none found';-export const findEntryPoint = (- args: string[],- remotionRoot: string,- logLevel: LogLevel,-): {+export const findEntryPoint = ({+ args,+ logLevel,+ remotionRoot,+ allowDirectory,+}: {+ args: string[];+ remotionRoot: string;+ logLevel: LogLevel;+ allowDirectory: boolean;+}): {file: string | null;remainingArgs: string[];reason: FoundReason;@@ -54,7 +60,7 @@ export const findEntryPoint = ();}- if (lstatSync(result.file).isDirectory()) {+ if (result.isDirectory && !allowDirectory) {throw new Error(`${result.file} was chosen as the entry point (reason = ${result.reason}) but it is a directory - it needs to be a file.`,);@@ -63,12 +69,17 @@ export const findEntryPoint = (return result;};+const isBundledCode = (p: string) => {+ return existsSync(p) && existsSync(path.join(p, 'index.html'));+};+const findEntryPointInner = (args: string[],remotionRoot: string,logLevel: LogLevel,): {file: string | null;+ isDirectory: boolean;remainingArgs: string[];reason: FoundReason;} => {@@ -89,6 +100,7 @@ const findEntryPointInner = (file: cwdResolution,remainingArgs: args.slice(1),reason: 'argument passed - found in cwd',+ isDirectory: isBundledCode(cwdResolution),};}@@ -98,11 +110,17 @@ const findEntryPointInner = (file: remotionRootResolution,remainingArgs: args.slice(1),reason: 'argument passed - found in root',+ isDirectory: isBundledCode(remotionRootResolution),};}if (RenderInternals.isServeUrl(file)) {- return {file, remainingArgs: args.slice(1), reason: 'argument passed'};+ return {+ file,+ remainingArgs: args.slice(1),+ reason: 'argument passed',+ isDirectory: false,+ };}}@@ -119,6 +137,7 @@ const findEntryPointInner = (file: path.resolve(remotionRoot, file),remainingArgs: args,reason: 'config file',+ isDirectory: isBundledCode(path.resolve(remotionRoot, file)),};}@@ -137,8 +156,14 @@ const findEntryPointInner = (file: absolutePath,remainingArgs: args,reason: 'common paths',+ isDirectory: false,};}- return {file: null, remainingArgs: args, reason: 'none found'};+ return {+ file: null,+ remainingArgs: args,+ reason: 'none found',+ isDirectory: false,+ };};diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 6c45491749..dd735768c6 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -46,7 +46,7 @@ export const render = async (file,remainingArgs,reason: entryPointReason,- } = findEntryPoint(args, remotionRoot, logLevel);+ } = findEntryPoint({args, remotionRoot, logLevel, allowDirectory: true});if (!file) {Log.error(diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.tsindex 27914cd4d9..dfc4fb0a01 100644--- a/packages/cli/src/setup-cache.ts+++ b/packages/cli/src/setup-cache.ts@@ -4,6 +4,8 @@ import type {LogLevel} from '@remotion/renderer';import {RenderInternals} from '@remotion/renderer';import type {GitSource} from '@remotion/studio';import type {BundlingState, CopyingState} from '@remotion/studio-server';+import {existsSync} from 'fs';+import path from 'path';import {ConfigInternals} from './config';import {Log} from './log';import type {SymbolicLinksState} from './progress-bar';@@ -52,7 +54,10 @@ export const bundleOnCliOrTakeServeUrl = async ({urlOrBundle: string;cleanup: () => void;}> => {- if (RenderInternals.isServeUrl(fullPath)) {+ const isServeUrl = RenderInternals.isServeUrl(fullPath);+ const isBundle =+ existsSync(fullPath) && existsSync(path.join(fullPath, 'index.html'));+ if (isServeUrl || isBundle) {onProgress({bundling: {doneIn: 0,diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.tsindex 853a633030..c4c646f7a8 100644--- a/packages/cli/src/still.ts+++ b/packages/cli/src/still.ts@@ -31,7 +31,7 @@ export const still = async (file,remainingArgs,reason: entryPointReason,- } = findEntryPoint(args, remotionRoot, logLevel);+ } = findEntryPoint({args, remotionRoot, logLevel, allowDirectory: true});if (!file) {Log.error(diff --git a/packages/cli/src/studio.ts b/packages/cli/src/studio.tsindex f71b750d4e..a11fefa8ba 100644--- a/packages/cli/src/studio.ts+++ b/packages/cli/src/studio.ts@@ -36,7 +36,12 @@ export const studioCommand = async (args: string[],logLevel: LogLevel,) => {- const {file, reason} = findEntryPoint(args, remotionRoot, logLevel);+ const {file, reason} = findEntryPoint({+ args,+ remotionRoot,+ logLevel,+ allowDirectory: false,+ });Log.verbose({indent: false, logLevel},diff --git a/packages/cli/src/test/find-entry-point.test.ts b/packages/cli/src/test/find-entry-point.test.tsindex b774b1754d..ff64ce8757 100644--- a/packages/cli/src/test/find-entry-point.test.ts+++ b/packages/cli/src/test/find-entry-point.test.ts@@ -3,11 +3,12 @@ import {expect, test} from 'vitest';import {findEntryPoint} from '../entry-point';test('Should accept URL as entry point', () => {- const entryPoint = findEntryPoint(- ['https://www.example.com'],- path.resolve(process.cwd(), '..', 'example'),- 'info',- );+ const entryPoint = findEntryPoint({+ args: ['https://www.example.com'],+ remotionRoot: path.resolve(process.cwd(), '..', 'example'),+ logLevel: 'info',+ allowDirectory: true,+ });expect(entryPoint.file).toBe('https://www.example.com');expect(entryPoint.remainingArgs).toEqual([]);@@ -15,11 +16,12 @@ test('Should accept URL as entry point', () => {});test('Should find entry point automatically', () => {- const entryPoint = findEntryPoint(- [],- path.resolve(process.cwd(), '..', 'example'),- 'info',- );+ const entryPoint = findEntryPoint({+ args: [],+ remotionRoot: path.resolve(process.cwd(), '..', 'example'),+ allowDirectory: true,+ logLevel: 'info',+ });expect(entryPoint.file).toBe(path.resolve(process.cwd(), '..', 'example/src/index.ts'),@@ -29,11 +31,12 @@ test('Should find entry point automatically', () => {});test('Should use explicit entry point', () => {- const entryPoint = findEntryPoint(- ['src/ts-entry.tsx'],- path.resolve(process.cwd(), '..', 'example'),- 'info',- );+ const entryPoint = findEntryPoint({+ args: ['src/ts-entry.tsx'],+ remotionRoot: path.resolve(process.cwd(), '..', 'example'),+ logLevel: 'info',+ allowDirectory: true,+ });expect(entryPoint.file).toBe(path.resolve(process.cwd(), '..', 'example/src/ts-entry.tsx'),diff --git a/packages/cloudrun/src/cli/commands/sites/create.ts b/packages/cloudrun/src/cli/commands/sites/create.tsindex 811efb716f..33fd5a8bd7 100644--- a/packages/cloudrun/src/cli/commands/sites/create.ts+++ b/packages/cloudrun/src/cli/commands/sites/create.ts@@ -30,11 +30,12 @@ export const sitesCreateSubcommand = async (remotionRoot: string,logLevel: LogLevel,) => {- const {file, reason} = CliInternals.findEntryPoint(+ const {file, reason} = CliInternals.findEntryPoint({args,remotionRoot,logLevel,- );+ allowDirectory: false,+ });if (!file) {Log.error({indent: false, logLevel}, 'No entry file passed.');Log.info(diff --git a/packages/lambda/src/cli/commands/sites/create.ts b/packages/lambda/src/cli/commands/sites/create.tsindex 22f300c57e..bc971962da 100644--- a/packages/lambda/src/cli/commands/sites/create.ts+++ b/packages/lambda/src/cli/commands/sites/create.ts@@ -31,11 +31,12 @@ export const sitesCreateSubcommand = async (remotionRoot: string,logLevel: LogLevel,) => {- const {file, reason} = CliInternals.findEntryPoint(+ const {file, reason} = CliInternals.findEntryPoint({args,remotionRoot,logLevel,- );+ allowDirectory: false,+ });if (!file) {Log.error({indent: false, logLevel}, 'No entry file passed.');Log.info(