Skip to content

🎥 Make videos programmatically with React

bundled

Jonny Burgerc444dcaf2e4a
diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.ts
index e5b7790d48..15f9bc491c 100644
--- a/packages/cli/src/compositions.ts
+++ b/packages/cli/src/compositions.ts
@@ -4,7 +4,7 @@ import {getCliOptions} from './get-cli-options';
import {loadConfig} from './get-config-file-name';
import {Log} from './log';
import {parsedCli, quietFlagProvided} from './parse-command-line';
-import {bundleOnCli} from './setup-cache';
+import {bundleOnCliOrTakeServeUrl} from './setup-cache';
const max = (arr: number[]) => {
if (arr.length === 0) {
@@ -56,11 +56,12 @@ export const listCompositionsCommand = async (remotionRoot: string) => {
type: 'get-compositions',
});
- const bundled = await bundleOnCli({
- remotionRoot,
- fullPath,
- steps: ['bundling'],
- });
+ const {urlOrBundle: bundled, cleanup: cleanupBundle} =
+ await bundleOnCliOrTakeServeUrl({
+ remotionRoot,
+ fullPath,
+ steps: ['bundling'],
+ });
const compositions = await getCompositions(bundled, {
browserExecutable,
@@ -114,5 +115,6 @@ export const listCompositionsCommand = async (remotionRoot: string) => {
);
await RenderInternals.cleanDownloadMap(downloadMap);
+ await cleanupBundle();
Log.verbose('Cleaned up', downloadMap.assetDir);
};
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 171850f383..40306e5d8d 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -27,7 +27,7 @@ import {
createOverwriteableCliOutput,
makeRenderingAndStitchingProgress,
} from './progress-bar';
-import {bundleOnCli} from './setup-cache';
+import {bundleOnCliOrTakeServeUrl} from './setup-cache';
import type {RenderStep} from './step';
import {checkAndValidateFfmpegVersion} from './validate-ffmpeg-version';
@@ -123,9 +123,13 @@ export const render = async (remotionRoot: string) => {
shouldOutputImageSequence ? null : ('stitching' as const),
].filter(Internals.truthy);
- const urlOrBundle = RenderInternals.isServeUrl(fullPath)
- ? fullPath
- : await bundleOnCli({fullPath, remotionRoot, steps});
+ const {urlOrBundle, cleanup: cleanupBundle} = await bundleOnCliOrTakeServeUrl(
+ {
+ fullPath,
+ remotionRoot,
+ steps,
+ }
+ );
const onDownload: RenderMediaOnDownload = (src) => {
const id = Math.random();
@@ -341,8 +345,9 @@ export const render = async (remotionRoot: string) => {
Log.info(chalk.cyan(`▶ ${absoluteOutputFile}`));
try {
- await RenderInternals.deleteDirectory(urlOrBundle);
+ await cleanupBundle();
await RenderInternals.cleanDownloadMap(downloadMap);
+
Log.verbose('Cleaned up', downloadMap.assetDir);
} catch (err) {
Log.warn('Could not clean up directory.');
diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.ts
index fe175c393b..507ae4fcdc 100644
--- a/packages/cli/src/setup-cache.ts
+++ b/packages/cli/src/setup-cache.ts
@@ -1,5 +1,6 @@
import type {BundleOptions} from '@remotion/bundler';
import {bundle, BundlerInternals} from '@remotion/bundler';
+import {RenderInternals} from '@remotion/renderer';
import {ConfigInternals} from './config';
import {Log} from './log';
import {quietFlagProvided} from './parse-command-line';
@@ -9,6 +10,33 @@ import {
} from './progress-bar';
import type {RenderStep} from './step';
+export const bundleOnCliOrTakeServeUrl = async ({
+ fullPath,
+ remotionRoot,
+ steps,
+}: {
+ fullPath: string;
+ remotionRoot: string;
+ steps: RenderStep[];
+}): Promise<{
+ urlOrBundle: string;
+ cleanup: () => Promise<void>;
+}> => {
+ if (RenderInternals.isServeUrl(fullPath)) {
+ return {
+ urlOrBundle: fullPath,
+ cleanup: () => Promise.resolve(undefined),
+ };
+ }
+
+ const bundled = await bundleOnCli({fullPath, remotionRoot, steps});
+
+ return {
+ urlOrBundle: bundled,
+ cleanup: () => RenderInternals.deleteDirectory(bundled),
+ };
+};
+
export const bundleOnCli = async ({
fullPath,
steps,
diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.ts
index 6c706b3008..2d0f86a54d 100644
--- a/packages/cli/src/still.ts
+++ b/packages/cli/src/still.ts
@@ -22,7 +22,7 @@ import {
createOverwriteableCliOutput,
makeRenderingAndStitchingProgress,
} from './progress-bar';
-import {bundleOnCli} from './setup-cache';
+import {bundleOnCliOrTakeServeUrl} from './setup-cache';
import type {RenderStep} from './step';
import {truthy} from './truthy';
import {
@@ -139,15 +139,15 @@ export const still = async (remotionRoot: string) => {
'rendering' as const,
].filter(truthy);
- const urlOrBundle = RenderInternals.isServeUrl(fullPath)
- ? Promise.resolve(fullPath)
- : await bundleOnCli({fullPath, remotionRoot, steps});
+ const {cleanup: cleanupBundle, urlOrBundle} = await bundleOnCliOrTakeServeUrl(
+ {fullPath, remotionRoot, steps}
+ );
const puppeteerInstance = await browserInstance;
const downloadMap = RenderInternals.makeDownloadMap();
- const comps = await getCompositions(await urlOrBundle, {
+ const comps = await getCompositions(urlOrBundle, {
inputProps,
puppeteerInstance,
envVariables,
@@ -212,7 +212,7 @@ export const still = async (remotionRoot: string) => {
composition,
frame: stillFrame,
output: absoluteOutputLocation,
- serveUrl: await urlOrBundle,
+ serveUrl: urlOrBundle,
quality,
dumpBrowserLogs: RenderInternals.isEqualOrBelowLogLevel(
ConfigInternals.Logging.getLogLevel(),
@@ -252,5 +252,7 @@ export const still = async (remotionRoot: string) => {
Log.info(chalk.cyan(`▶️ ${absoluteOutputLocation}`));
await closeBrowserPromise;
await RenderInternals.cleanDownloadMap(downloadMap);
+ await cleanupBundle();
+
Log.verbose('Cleaned up', downloadMap.assetDir);
};