🎥 Make videos programmatically with React
remotionRoot refactor complete
Patric Salvisberg6129f2f64b6a
diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.tsindex 668e7112ee..33a87cca9b 100644--- a/packages/cli/src/compositions.ts+++ b/packages/cli/src/compositions.ts@@ -56,6 +56,7 @@ export const listCompositionsCommand = async (remotionRoot: string) => {isLambda: false,type: 'get-compositions',codec: 'h264',+ remotionRoot,});const {urlOrBundle: bundled, cleanup: cleanupBundle} =@@ -66,7 +67,7 @@ export const listCompositionsCommand = async (remotionRoot: string) => {publicDir,});- const compositions = await getCompositions(bundled, {+ const compositions = await getCompositions(bundled, remotionRoot, {browserExecutable,ffmpegExecutable,ffprobeExecutable,diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex 335d6680c7..6654b7b7ce 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -29,13 +29,17 @@ const getAndValidateFrameRange = () => {return frameRange;};-export const validateFfmepgCanUseCodec = async (codec: Codec) => {+export const validateFfmepgCanUseCodec = async (+ codec: Codec,+ remotionRoot: string+) => {const ffmpegExecutable = ConfigInternals.getCustomFfmpegExecutable();if (codec === 'vp8' &&!(await RenderInternals.ffmpegHasFeature({feature: 'enable-libvpx',ffmpegExecutable,+ remotionRoot,}))) {Log.error(@@ -51,6 +55,7 @@ export const validateFfmepgCanUseCodec = async (codec: Codec) => {!(await RenderInternals.ffmpegHasFeature({feature: 'enable-gpl',ffmpegExecutable,+ remotionRoot,}))) {Log.error(@@ -66,6 +71,7 @@ export const validateFfmepgCanUseCodec = async (codec: Codec) => {!(await RenderInternals.ffmpegHasFeature({feature: 'enable-libx265',ffmpegExecutable,+ remotionRoot,}))) {Log.error(@@ -115,16 +121,19 @@ export const getAndValidateAbsoluteOutputFile = (const getAndValidateShouldOutputImageSequence = async ({frameRange,isLambda,+ remotionRoot,}: {frameRange: FrameRange | null;isLambda: boolean;+ remotionRoot: string;}) => {const shouldOutputImageSequence =ConfigInternals.getShouldOutputImageSequence(frameRange);// When parsing options locally, we don't need FFMPEG because the render will happen on Lambdaif (!shouldOutputImageSequence && !isLambda) {await RenderInternals.validateFfmpeg(- ConfigInternals.getCustomFfmpegExecutable()+ ConfigInternals.getCustomFfmpegExecutable(),+ remotionRoot);}@@ -201,6 +210,7 @@ export const getCliOptions = async (options: {isLambda: boolean;type: 'still' | 'series' | 'get-compositions';codec: Codec;+ remotionRoot: string;}) => {const frameRange = getAndValidateFrameRange();@@ -210,6 +220,7 @@ export const getCliOptions = async (options: {: await getAndValidateShouldOutputImageSequence({frameRange,isLambda: options.isLambda,+ remotionRoot: options.remotionRoot,});const overwrite = ConfigInternals.getShouldOverwrite({diff --git a/packages/cli/src/get-env.ts b/packages/cli/src/get-env.tsindex fcdc4fd509..634d0eb0e7 100644--- a/packages/cli/src/get-env.ts+++ b/packages/cli/src/get-env.ts@@ -1,9 +1,9 @@+import {RenderInternals} from '@remotion/renderer';import dotenv from 'dotenv';import fs from 'fs';import path from 'path';import {chalk} from './chalk';import {ConfigInternals} from './config';-import {findRemotionRoot} from './find-closest-package-json';import {Log} from './log';import {parsedCli} from './parse-command-line';@@ -112,7 +112,7 @@ export const getEnvironmentVariables = (return getEnvForEnvFile(processEnv, envFile, onUpdate);}- const remotionRoot = findRemotionRoot();+ const remotionRoot = RenderInternals.findRemotionRoot();const configFileSetting = ConfigInternals.getDotEnvLocation();if (configFileSetting) {diff --git a/packages/cli/src/index.tsx b/packages/cli/src/index.tsxindex ac0bd8cc3a..223f886c5b 100644--- a/packages/cli/src/index.tsx+++ b/packages/cli/src/index.tsx@@ -5,7 +5,6 @@ import {listCompositionsCommand} from './compositions';import {overrideRemotion} from './config/index';import {determineFinalImageFormat} from './determine-image-format';import {getFileSizeDownloadBar} from './download-progress';-import {findRemotionRoot} from './find-closest-package-json';import {formatBytes} from './format-bytes';import {getCliOptions, getFinalCodec} from './get-cli-options';import {loadConfig} from './get-config-file-name';@@ -43,7 +42,7 @@ export const cli = async () => {process.exit(0);}- const remotionRoot = findRemotionRoot();+ const remotionRoot = RenderInternals.findRemotionRoot();// To check node version and to warn if node version is <12.10.0checkNodeVersion();if (command !== VERSIONS_COMMAND) {@@ -106,7 +105,6 @@ export const CliInternals = {handleCommonError,formatBytes,getFileSizeDownloadBar,- findRemotionRoot,getFinalCodec,determineFinalImageFormat,};diff --git a/packages/cli/src/lambda-command.ts b/packages/cli/src/lambda-command.tsindex 162224ab4b..5c9b5db64c 100644--- a/packages/cli/src/lambda-command.ts+++ b/packages/cli/src/lambda-command.ts@@ -10,7 +10,7 @@ export const lambdaCommand = async (remotionRoot: string) => {});const {LambdaInternals} = require(path);- await LambdaInternals.executeCommand(parsedCli._.slice(1));+ await LambdaInternals.executeCommand(parsedCli._.slice(1), remotionRoot);process.exit(0);} catch (err) {const manager = getPackageManager(remotionRoot);diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 33ae2ef6cd..c76572bf3b 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -65,7 +65,7 @@ export const render = async (remotionRoot: string) => {outName: getUserPassedOutputLocation(),});- validateFfmepgCanUseCodec(codec);+ validateFfmepgCanUseCodec(codec, remotionRoot);const {proResProfile,@@ -97,6 +97,7 @@ export const render = async (remotionRoot: string) => {isLambda: false,type: 'series',codec,+ remotionRoot,});const relativeOutputLocation = getOutputFilename({@@ -123,6 +124,7 @@ export const render = async (remotionRoot: string) => {await checkAndValidateFfmpegVersion({ffmpegExecutable,+ remotionRoot,});const browserInstance = openBrowser(browser, {@@ -171,7 +173,7 @@ export const render = async (remotionRoot: string) => {const puppeteerInstance = await browserInstance;- const comps = await getCompositions(urlOrBundle, {+ const comps = await getCompositions(urlOrBundle, remotionRoot, {inputProps,puppeteerInstance,envVariables,diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.tsindex b353e806f9..e1ce580246 100644--- a/packages/cli/src/still.ts+++ b/packages/cli/src/still.ts@@ -63,6 +63,7 @@ export const still = async (remotionRoot: string) => {isLambda: false,type: 'still',codec: 'h264',+ remotionRoot,});Log.verbose('Browser executable: ', browserExecutable);@@ -120,7 +121,7 @@ export const still = async (remotionRoot: string) => {const downloadMap = RenderInternals.makeDownloadMap();- const comps = await getCompositions(urlOrBundle, {+ const comps = await getCompositions(urlOrBundle, remotionRoot, {inputProps,puppeteerInstance,envVariables,diff --git a/packages/cli/src/validate-ffmpeg-version.ts b/packages/cli/src/validate-ffmpeg-version.tsindex 44fbab95c1..b6dafe809b 100644--- a/packages/cli/src/validate-ffmpeg-version.ts+++ b/packages/cli/src/validate-ffmpeg-version.ts@@ -4,13 +4,20 @@ import {warnAboutFfmpegVersion} from './warn-about-ffmpeg-version';export const checkAndValidateFfmpegVersion = async (options: {ffmpegExecutable: string | null;+ remotionRoot: string;}) => {- const ffmpegVersion = await RenderInternals.getFfmpegVersion({- ffmpegExecutable: options.ffmpegExecutable,- });- const buildConf = await RenderInternals.getFfmpegBuildInfo({- ffmpegExecutable: options.ffmpegExecutable,- });+ const ffmpegVersion = await RenderInternals.getFfmpegVersion(+ {+ ffmpegExecutable: options.ffmpegExecutable,+ },+ options.remotionRoot+ );+ const buildConf = await RenderInternals.getFfmpegBuildInfo(+ {+ ffmpegExecutable: options.ffmpegExecutable,+ },+ options.remotionRoot+ );Log.verbose('Your FFMPEG version:',ffmpegVersion ? ffmpegVersion.join('.') : 'Built from source'diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.tsindex ae2f7b7066..ba1d8ed662 100644--- a/packages/lambda/src/cli/commands/render/render.ts+++ b/packages/lambda/src/cli/commands/render/render.ts@@ -22,7 +22,7 @@ import {makeMultiProgressFromStatus, makeProgressString} from './progress';export const RENDER_COMMAND = 'render';-export const renderCommand = async (args: string[]) => {+export const renderCommand = async (args: string[], remotionRoot: string) => {const serveUrl = args[0];if (!serveUrl) {Log.error('No serve URL passed.');@@ -76,6 +76,7 @@ export const renderCommand = async (args: string[]) => {type: 'series',isLambda: true,codec,+ remotionRoot,});const functionName = await findFunctionName();diff --git a/packages/lambda/src/cli/commands/still.ts b/packages/lambda/src/cli/commands/still.tsindex 838679c862..019ad38033 100644--- a/packages/lambda/src/cli/commands/still.ts+++ b/packages/lambda/src/cli/commands/still.ts@@ -17,7 +17,7 @@ import {Log} from '../log';export const STILL_COMMAND = 'still';-export const stillCommand = async (args: string[]) => {+export const stillCommand = async (args: string[], remotionRoot: string) => {const serveUrl = args[0];if (!serveUrl) {@@ -59,6 +59,7 @@ export const stillCommand = async (args: string[]) => {type: 'still',isLambda: true,codec: 'h264',+ remotionRoot,});const functionName = await findFunctionName();diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.tsindex 2e887f19af..ed9a0214f8 100644--- a/packages/lambda/src/cli/index.ts+++ b/packages/lambda/src/cli/index.ts@@ -1,4 +1,5 @@import {CliInternals} from '@remotion/cli';+import {RenderInternals} from '@remotion/renderer';import {ROLE_NAME} from '../api/iam-validation/suggested-policy';import {BINARY_NAME} from '../defaults';import {checkCredentials} from '../shared/check-credentials';@@ -36,7 +37,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);@@ -47,11 +48,11 @@ const matchCommand = (args: string[]) => {}if (args[0] === RENDER_COMMAND) {- return renderCommand(args.slice(1));+ return renderCommand(args.slice(1), remotionRoot);}if (args[0] === STILL_COMMAND) {- return stillCommand(args.slice(1));+ return stillCommand(args.slice(1), remotionRoot);}if (args[0] === FUNCTIONS_COMMAND) {@@ -108,10 +109,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 +165,8 @@ AWS returned an "TooManyRequestsException" error message which could mean you re};export const cli = async () => {- await CliInternals.initializeCli(CliInternals.findRemotionRoot());+ const remotionRoot = RenderInternals.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 7ce9a71b67..8b1553dae9 100644--- a/packages/lambda/src/test/integration/cli.test.ts+++ b/packages/lambda/src/test/integration/cli.test.ts@@ -9,35 +9,37 @@ import {LambdaInternals} from '../../internals';import {LAMBDA_VERSION_STRING} from '../../shared/lambda-version-string';import {getProcessWriteOutput} from './console-hooks';+const remotionRoot = process.cwd();+test('Deploy function', async () => {- await LambdaInternals.executeCommand(['functions', 'deploy']);+ await LambdaInternals.executeCommand(['functions', 'deploy'], remotionRoot);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'], remotionRoot);+ await LambdaInternals.executeCommand(['functions', 'ls'], remotionRoot);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'], remotionRoot);+ await LambdaInternals.executeCommand(['functions', 'deploy'], remotionRoot);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'], remotionRoot);expect(getProcessWriteOutput()).toBe('()');});test('Should handle functions rm called with no functions', async () => {- await LambdaInternals.executeCommand(['functions', 'rm', '()']);+ await LambdaInternals.executeCommand(['functions', 'rm', '()'], remotionRoot);expect(getProcessWriteOutput()).toBe('No functions to remove.');});diff --git a/packages/cli/src/find-closest-package-json.ts b/packages/renderer/src/find-closest-package-json.tssimilarity index 95%rename from packages/cli/src/find-closest-package-json.tsrename to packages/renderer/src/find-closest-package-json.tsindex bb2de25d6d..6a14c37b82 100644--- a/packages/cli/src/find-closest-package-json.ts+++ b/packages/renderer/src/find-closest-package-json.ts@@ -1,6 +1,5 @@import fs from 'fs';import path from 'path';-import {Log} from './log';const recursionLimit = 5;@@ -23,7 +22,7 @@ export const findClosestPackageJson = (): string | null => {export const findRemotionRoot = (): string => {const closestPackageJson = findClosestPackageJson();if (closestPackageJson === null) {- Log.error(+ console.error('Could not find a package.json in the current directory or any of the ' +recursionLimit +' parent directories. Is this a Remotion project?'diff --git a/packages/renderer/src/get-compositions.ts b/packages/renderer/src/get-compositions.tsindex 8082ba83fa..fe0b4fdd51 100644--- a/packages/renderer/src/get-compositions.ts+++ b/packages/renderer/src/get-compositions.ts@@ -7,6 +7,7 @@ import type {Browser} from './browser/Browser';import type {Page} from './browser/BrowserPage';import {handleJavascriptException} from './error-handling/handle-javascript-exception';import type {FfmpegExecutable} from './ffmpeg-executable';+import {findRemotionRoot} from './find-closest-package-json';import {getPageAndCleanupFn} from './get-browser-instance';import type {ChromiumOptions} from './open-browser';import {prepareServer} from './prepare-server';@@ -88,7 +89,6 @@ const innerGetCompositions = async (export const getCompositions = async (serveUrlOrWebpackUrl: string,- remotionRoot: string,config?: GetCompositionsConfig) => {const downloadMap = config?.downloadMap ?? makeDownloadMap();@@ -117,7 +117,7 @@ export const getCompositions = async (ffprobeExecutable: config?.ffprobeExecutable ?? null,port: config?.port ?? null,downloadMap,- remotionRoot,+ remotionRoot: findRemotionRoot(),}).then(({serveUrl, closeServer, offthreadPort}) => {close = closeServer;diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.tsindex 0cef7f76f3..82b65b7979 100644--- a/packages/renderer/src/index.ts+++ b/packages/renderer/src/index.ts@@ -21,6 +21,7 @@ import {getFfmpegBuildInfo,getFfmpegVersion,} from './ffmpeg-flags';+import {findRemotionRoot} from './find-closest-package-json';import {validateFrameRange} from './frame-range';import {getActualConcurrency} from './get-concurrency';import {getFramesToRender} from './get-duration-from-frame-range';@@ -169,6 +170,7 @@ export const RenderInternals = {makeDownloadMap,cleanDownloadMap,convertToPositiveFrameIndex,+ findRemotionRoot,};// Warn of potential performance issues with Apple Silicon (M1 chip under Rosetta)diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.tsindex 74cd83065f..8637694ac6 100644--- a/packages/renderer/src/render-frames.ts+++ b/packages/renderer/src/render-frames.ts@@ -16,6 +16,7 @@ import {compressAsset} from './compress-assets';import {cycleBrowserTabs} from './cycle-browser-tabs';import {handleJavascriptException} from './error-handling/handle-javascript-exception';import type {FfmpegExecutable} from './ffmpeg-executable';+import {findRemotionRoot} from './find-closest-package-json';import type {FrameRange} from './frame-range';import {getActualConcurrency} from './get-concurrency';import {getFramesToRender} from './get-duration-from-frame-range';@@ -89,7 +90,6 @@ type RenderFramesOptions = {ffprobeExecutable?: FfmpegExecutable;port?: number | null;cancelSignal?: CancelSignal;- remotionRoot: string;/*** @deprecated Only for Remotion internal usage*/@@ -482,7 +482,7 @@ export const renderFrames = (ffprobeExecutable: options.ffprobeExecutable ?? null,port: options.port ?? null,downloadMap,- remotionRoot: options.remotionRoot,+ remotionRoot: findRemotionRoot(),}),browserInstance,]).then(([{serveUrl, closeServer, offthreadPort}, puppeteerInstance]) => {diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.tsindex 146dc3220c..b61aaa644e 100644--- a/packages/renderer/src/render-still.ts+++ b/packages/renderer/src/render-still.ts@@ -12,6 +12,7 @@ import {convertToPositiveFrameIndex} from './convert-to-positive-frame-index';import {ensureOutputDirectory} from './ensure-output-directory';import {handleJavascriptException} from './error-handling/handle-javascript-exception';import type {FfmpegExecutable} from './ffmpeg-executable';+import {findRemotionRoot} from './find-closest-package-json';import type {StillImageFormat} from './image-format';import {validateNonNullImageFormat} from './image-format';import type {ServeUrlOrWebpackBundle} from './legacy-webpack-config';@@ -57,7 +58,7 @@ type InnerStillOptions = {export type RenderStillOptions = InnerStillOptions &ServeUrlOrWebpackBundle & {port?: number | null;- } & {remotionRoot: string};+ };const innerRenderStill = async ({composition,@@ -269,7 +270,7 @@ export const renderStill = (options: RenderStillOptions): Promise<void> => {ffprobeExecutable: options.ffprobeExecutable ?? null,port: options.port ?? null,downloadMap,- remotionRoot: options.remotionRoot,+ remotionRoot: findRemotionRoot(),}).then(({serveUrl, closeServer, offthreadPort}) => {close = closeServer;diff --git a/packages/cli/src/test/find-closest-package-json.test.ts b/packages/renderer/src/test/find-closest-package-json.test.tssimilarity index 100%rename from packages/cli/src/test/find-closest-package-json.test.tsrename to packages/renderer/src/test/find-closest-package-json.test.ts