🎥 Make videos programmatically with React
log entry point and reason
Jonny Burgerd7fd42030865
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.tsindex 38e7194ec8..56e877d8ad 100644--- a/packages/cli/src/benchmark.ts+++ b/packages/cli/src/benchmark.ts@@ -140,7 +140,7 @@ export const benchmarkCommand = async () => {const runs: number = parsedCli.runs ?? DEFAULT_RUNS;- const {file} = findEntryPoint(args);+ const {file, reason, remainingArgs} = findEntryPoint(args, remotionRoot);if (!file) {Log.error('No entry file passed.');@@ -169,6 +169,8 @@ export const benchmarkCommand = async (type: 'series',});+ Log.verbose('Entry point:', file, 'reason:', reason);+const browserInstance = openBrowser(browser, {browserExecutable,shouldDumpIo: RenderInternals.isEqualOrBelowLogLevel(@@ -201,8 +203,8 @@ export const benchmarkCommand = async (});const ids = (- args[1]- ? args[1]+ remainingArgs[0]+ ? remainingArgs[0].split(',').map((c) => c.trim()).filter(truthy)diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.tsindex 82f9a2408c..10ec5f299b 100644--- a/packages/cli/src/compositions.ts+++ b/packages/cli/src/compositions.ts@@ -27,7 +27,7 @@ export const listCompositionsCommand = async (remotionRoot: string,args: string[]) => {- const {file} = findEntryPoint(args);+ const {file, reason} = findEntryPoint(args, remotionRoot);if (!file) {Log.error(@@ -40,6 +40,8 @@ export const listCompositionsCommand = async (process.exit(1);}+ Log.verbose('Entry point:', file, 'reason:', reason);+const downloadMap = RenderInternals.makeDownloadMap();const fullPath = path.join(process.cwd(), file);diff --git a/packages/cli/src/entry-point.ts b/packages/cli/src/entry-point.tsindex 50ddbd2ebb..498849161e 100644--- a/packages/cli/src/entry-point.ts+++ b/packages/cli/src/entry-point.ts@@ -12,31 +12,48 @@ const candidates = [path.join('src', 'index.js'),];-const findCommonPath = () => {- return candidates.find((candidate) => existsSync(candidate));+const findCommonPath = (remotionRoot: string) => {+ return candidates.find((candidate) =>+ existsSync(path.resolve(remotionRoot, candidate))+ );};export const findEntryPoint = (- args: string[]+ args: string[],+ remotionRoot: string): {file: string | null;remainingArgs: string[];+ reason: string;} => {// 1st priority: Explicitly passed entry pointlet file: string | null = args[0];- if (file) return {file, remainingArgs: args.slice(1)};+ if (file) {+ Log.verbose('Checking if', file, 'is the entry file');+ if (existsSync(path.resolve(remotionRoot, file))) {+ return {file, remainingArgs: args.slice(1), reason: 'argument passed'};+ }+ }// 2nd priority: Config filefile = ConfigInternals.getEntryPoint();- if (file) return {file, remainingArgs: args};+ if (file) {+ Log.verbose('Entry point from config file is', file);++ return {file, remainingArgs: args, reason: 'config file'};+ }// 3rd priority: Common paths- const found = findCommonPath();+ const found = findCommonPath(remotionRoot);if (found) {- Log.verbose(`No entry point specified. Using ${found} as fallback`);- return {file: found, remainingArgs: args};+ Log.verbose(+ 'Selected',+ found,+ 'as the entry point because file exists and is a common entry point and no entry point was explicitly selected'+ );+ return {file: found, remainingArgs: args, reason: 'common paths'};}- return {file: null, remainingArgs: args};+ return {file: null, remainingArgs: args, reason: 'none found'};};diff --git a/packages/cli/src/lambda-command.ts b/packages/cli/src/lambda-command.tsindex 2997d49f1f..eab5d9efd4 100644--- a/packages/cli/src/lambda-command.ts+++ b/packages/cli/src/lambda-command.ts@@ -9,7 +9,7 @@ export const lambdaCommand = async (remotionRoot: string, args: string[]) => {});const {LambdaInternals} = require(path);- await LambdaInternals.executeCommand(args);+ await LambdaInternals.executeCommand(args, remotionRoot);process.exit(0);} catch (err) {const manager = getPackageManager(remotionRoot, undefined);diff --git a/packages/cli/src/preview.ts b/packages/cli/src/preview.tsindex 59e36e29b2..cbf02fd426 100644--- a/packages/cli/src/preview.ts+++ b/packages/cli/src/preview.ts@@ -35,7 +35,9 @@ const waitForLiveEventsListener = (): Promise<LiveEventsServer> => {};export const previewCommand = async (remotionRoot: string, args: string[]) => {- const {file} = findEntryPoint(args);+ const {file, reason} = findEntryPoint(args, remotionRoot);++ Log.verbose('Entry point:', file, 'reason:', reason);if (!file) {Log.error(diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 029f485e2e..3a6fd6031d 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -37,7 +37,11 @@ import {getUserPassedOutputLocation} from './user-passed-output-location';export const render = async (remotionRoot: string, args: string[]) => {const startTime = Date.now();- const {file, remainingArgs} = findEntryPoint(args);+ const {+ file,+ remainingArgs,+ reason: entryPointReason,+ } = findEntryPoint(args, remotionRoot);if (!file) {Log.error('No entry point specified. Pass more arguments:');@@ -178,7 +182,7 @@ export const render = async (remotionRoot: string, args: string[]) => {Log.info(chalk.gray(- `Composition = ${compositionId} (${reason}), Codec = ${codec} (${codecReason}), Output = ${relativeOutputLocation}`+ `Entry point = ${file} (${entryPointReason}), Composition = ${compositionId} (${reason}), Codec = ${codec} (${codecReason}), Output = ${relativeOutputLocation}`));diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.tsindex b24046489c..652090876c 100644--- a/packages/cli/src/still.ts+++ b/packages/cli/src/still.ts@@ -33,7 +33,11 @@ import {export const still = async (remotionRoot: string, args: string[]) => {const startTime = Date.now();- const {file, remainingArgs} = findEntryPoint(args);+ const {+ file,+ remainingArgs,+ reason: entryPointReason,+ } = findEntryPoint(args, remotionRoot);if (!file) {Log.error('No entry point specified. Pass more arguments:');@@ -141,7 +145,7 @@ export const still = async (remotionRoot: string, args: string[]) => {Log.info(chalk.gray(- `Output = ${relativeOutputLocation}, Format = ${imageFormat} (${source}), Composition = ${compositionId} (${reason})`+ `Entry point = ${file} (${entryPointReason}), Output = ${relativeOutputLocation}, Format = ${imageFormat} (${source}), Composition = ${compositionId} (${reason})`));diff --git a/packages/lambda/src/cli/commands/sites/create.ts b/packages/lambda/src/cli/commands/sites/create.tsindex 7f30462e02..34ff2f6839 100644--- a/packages/lambda/src/cli/commands/sites/create.ts+++ b/packages/lambda/src/cli/commands/sites/create.ts@@ -22,8 +22,11 @@ import {Log} from '../../log';export const SITES_CREATE_SUBCOMMAND = 'create';-export const sitesCreateSubcommand = async (args: string[]) => {- const {file} = CliInternals.findEntryPoint(args);+export const sitesCreateSubcommand = async (+ args: string[],+ remotionRoot: string+) => {+ const {file, reason} = CliInternals.findEntryPoint(args, remotionRoot);if (!file) {Log.error('No entry file passed.');Log.info(@@ -35,6 +38,8 @@ export const sitesCreateSubcommand = async (args: string[]) => {return;}+ Log.verbose('Entry point:', file, 'Reason:', reason);+const absoluteFile = path.join(process.cwd(), file);if (!existsSync(absoluteFile)) {Log.error(diff --git a/packages/lambda/src/cli/commands/sites/index.ts b/packages/lambda/src/cli/commands/sites/index.tsindex ce3935eb8d..3905c48895 100644--- a/packages/lambda/src/cli/commands/sites/index.ts+++ b/packages/lambda/src/cli/commands/sites/index.ts@@ -28,7 +28,7 @@ const printSitesHelp = () => {Log.info(CliInternals.chalk.gray('Remove a site from the S3 bucket.'));};-export const sitesCommand = (args: string[]) => {+export const sitesCommand = (args: string[], remotionRoot: string) => {if (args[0] === SITES_LS_SUBCOMMAND) {return sitesLsSubcommand();}@@ -42,7 +42,7 @@ export const sitesCommand = (args: string[]) => {}if (args[0] === SITES_CREATE_SUBCOMMAND) {- return sitesCreateSubcommand(args.slice(1));+ return sitesCreateSubcommand(args.slice(1), remotionRoot);}if (args[0]) {diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.tsindex 2e887f19af..08c2d07c57 100644--- a/packages/lambda/src/cli/index.ts+++ b/packages/lambda/src/cli/index.ts@@ -36,7 +36,7 @@ const requiresCredentials = (args: string[]) => {return true;};-const matchCommand = (args: string[]) => {+const matchCommand = (args: string[], remotionRoot: string) => {if (parsedLambdaCli.help || args.length === 0) {printHelp();quit(0);@@ -71,7 +71,7 @@ const matchCommand = (args: string[]) => {}if (args[0] === SITES_COMMAND) {- return sitesCommand(args.slice(1));+ return sitesCommand(args.slice(1), remotionRoot);}if (args[0] === 'upload') {@@ -108,10 +108,10 @@ const matchCommand = (args: string[]) => {quit(1);};-export const executeCommand = async (args: string[]) => {+export const executeCommand = async (args: string[], remotionRoot: string) => {try {setIsCli(true);- await matchCommand(args);+ await matchCommand(args, remotionRoot);} catch (err) {const error = err as Error;if (@@ -164,7 +164,8 @@ AWS returned an "TooManyRequestsException" error message which could mean you re};export const cli = async () => {- await CliInternals.initializeCli(CliInternals.findRemotionRoot());+ const remotionRoot = CliInternals.findRemotionRoot();+ await CliInternals.initializeCli(remotionRoot);- await executeCommand(parsedLambdaCli._);+ await executeCommand(parsedLambdaCli._, remotionRoot);};diff --git a/packages/lambda/src/test/integration/cli.test.ts b/packages/lambda/src/test/integration/cli.test.tsindex 0efad5f5a4..c6903d70e2 100644--- a/packages/lambda/src/test/integration/cli.test.ts+++ b/packages/lambda/src/test/integration/cli.test.ts@@ -11,34 +11,37 @@ import {LAMBDA_VERSION_STRING} from '../../shared/lambda-version-string';import {getProcessWriteOutput} from './console-hooks';test('Deploy function', async () => {- await LambdaInternals.executeCommand(['functions', 'deploy']);+ await LambdaInternals.executeCommand(['functions', 'deploy'], process.cwd());expect(getProcessWriteOutput()).toContain(`Deployed as remotion-render-${LAMBDA_VERSION_STRING}-mem${DEFAULT_MEMORY_SIZE}mb-disk${DEFAULT_EPHEMERAL_STORAGE_IN_MB}mb-${DEFAULT_TIMEOUT}sec\n`);});test('Deploy function and list it', async () => {- await LambdaInternals.executeCommand(['functions', 'deploy']);- await LambdaInternals.executeCommand(['functions', 'ls']);+ await LambdaInternals.executeCommand(['functions', 'deploy'], process.cwd());+ await LambdaInternals.executeCommand(['functions', 'ls'], process.cwd());expect(getProcessWriteOutput()).toContain('Getting functions...');expect(getProcessWriteOutput()).toContain('Memory (MB)');expect(getProcessWriteOutput()).toMatch(/remotion-render-(.*)\s+2048\s+120/g);});test('Deploy function and it already exists should fail', async () => {- await LambdaInternals.executeCommand(['functions', 'deploy']);- await LambdaInternals.executeCommand(['functions', 'deploy']);+ await LambdaInternals.executeCommand(['functions', 'deploy'], process.cwd());+ await LambdaInternals.executeCommand(['functions', 'deploy'], process.cwd());expect(getProcessWriteOutput()).toMatch(/Already exists as remotion-render/);});test('If no functions are there and is quiet, should return "()"', async () => {CliInternals.parsedCli.q = true;- await LambdaInternals.executeCommand(['functions', 'ls']);+ await LambdaInternals.executeCommand(['functions', 'ls'], process.cwd());expect(getProcessWriteOutput()).toBe('()');});test('Should handle functions rm called with no functions', async () => {- await LambdaInternals.executeCommand(['functions', 'rm', '()']);+ await LambdaInternals.executeCommand(+ ['functions', 'rm', '()'],+ process.cwd()+ );expect(getProcessWriteOutput()).toBe('No functions to remove.');});