🎥 Make videos programmatically with React
new bundle signature
Jonny Burger531d5f44b897
diff --git a/packages/bundler/src/bundle.ts b/packages/bundler/src/bundle.tsindex b045f58886..bc12a6d29c 100644--- a/packages/bundler/src/bundle.ts+++ b/packages/bundler/src/bundle.ts@@ -49,13 +49,13 @@ export const getConfig = ({entryPoint,outDir,resolvedRemotionRoot,- onProgressUpdate,+ onProgress,options,}: {outDir: string;entryPoint: string;resolvedRemotionRoot: string;- onProgressUpdate?: (progress: number) => void;+ onProgress?: (progress: number) => void;options?: LegacyBundleOptions;}) => {const entry = require.resolve('./renderEntry');@@ -66,7 +66,7 @@ export const getConfig = ({outDir,environment: 'production',webpackOverride: options?.webpackOverride ?? ((f) => f),- onProgressUpdate,+ onProgress,enableCaching: options?.enableCaching ?? true,maxTimelineTracks: 15,// For production, the variables are set dynamically@@ -79,14 +79,14 @@ export const getConfig = ({export type BundleOptions = {entryPoint: string;- onProgressUpdate?: (progress: number) => void;+ onProgress?: (progress: number) => void;} & LegacyBundleOptions;type Arguments =| [options: BundleOptions]| [entryPoint: string,- onProgressUpdate?: (progress: number) => void,+ onProgress?: (progress: number) => void,options?: LegacyBundleOptions];@@ -99,7 +99,7 @@ const convertArgumentsIntoOptions = (args: Arguments): BundleOptions => {if (typeof firstArg === 'string') {return {entryPoint: firstArg,- onProgressUpdate: args[1],+ onProgress: args[1],...(args[2] ?? {}),};}@@ -125,12 +125,12 @@ export async function bundle(...args: Arguments): Promise<string> {process.chdir(resolvedRemotionRoot);}- const {entryPoint, onProgressUpdate, ...options} = actualArgs;+ const {entryPoint, onProgress, ...options} = actualArgs;const [, config] = getConfig({outDir,entryPoint,resolvedRemotionRoot,- onProgressUpdate,+ onProgress,options,});diff --git a/packages/bundler/src/webpack-config.ts b/packages/bundler/src/webpack-config.tsindex a144d23916..c92819855d 100644--- a/packages/bundler/src/webpack-config.ts+++ b/packages/bundler/src/webpack-config.ts@@ -39,7 +39,7 @@ export const webpackConfig = ({outDir,environment,webpackOverride = (f) => f,- onProgressUpdate,+ onProgress,enableCaching = true,envVariables,maxTimelineTracks,@@ -52,7 +52,7 @@ export const webpackConfig = ({outDir: string;environment: 'development' | 'production';webpackOverride: WebpackOverrideFn;- onProgressUpdate?: (f: number) => void;+ onProgress?: (f: number) => void;enableCaching?: boolean;envVariables: Record<string, string>;maxTimelineTracks: number;@@ -110,8 +110,8 @@ export const webpackConfig = ({]: [new ProgressPlugin((p) => {- if (onProgressUpdate) {- onProgressUpdate(Number((p * 100).toFixed(2)));+ if (onProgress) {+ onProgress(Number((p * 100).toFixed(2)));}}),],diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.tsindex c5eed0fac7..95601bf0e6 100644--- a/packages/cli/src/setup-cache.ts+++ b/packages/cli/src/setup-cache.ts@@ -1,4 +1,4 @@-import type {BundleOptions} from '@remotion/bundler';+import type {LegacyBundleOptions} from '@remotion/bundler';import {bundle, BundlerInternals} from '@remotion/bundler';import {RenderInternals} from '@remotion/renderer';import {ConfigInternals} from './config';@@ -62,7 +62,7 @@ export const bundleOnCli = async ({);};- const options: BundleOptions = {+ const options: LegacyBundleOptions = {enableCaching: shouldCache,webpackOverride: ConfigInternals.getWebpackOverrideFn() ?? ((f) => f),rootDir: remotionRoot,@@ -72,7 +72,7 @@ export const bundleOnCli = async ({const [hash] = BundlerInternals.getConfig({outDir: '',entryPoint: fullPath,- onProgressUpdate: onProgress,+ onProgress,options,resolvedRemotionRoot: remotionRoot,});@@ -95,9 +95,9 @@ export const bundleOnCli = async ({const bundleStartTime = Date.now();const bundlingProgress = createOverwriteableCliOutput(quietFlagProvided());- const bundled = await bundle(- fullPath,- (progress) => {+ const bundled = await bundle({+ entryPoint: fullPath,+ onProgress: (progress) => {bundlingProgress.update(makeBundlingProgress({progress: progress / 100,@@ -106,8 +106,8 @@ export const bundleOnCli = async ({}));},- options- );+ ...options,+ });bundlingProgress.update(makeBundlingProgress({progress: 1,diff --git a/packages/docs/blog/2021-08-11-remotion-2-3.md b/packages/docs/blog/2021-08-11-remotion-2-3.mdindex 90cc06764f..e88f21d8d1 100644--- a/packages/docs/blog/2021-08-11-remotion-2-3.md+++ b/packages/docs/blog/2021-08-11-remotion-2-3.md@@ -69,7 +69,9 @@ import { getCompositions, renderStill } from "@remotion/renderer";// The composition you want to renderconst compositionId = "HelloWorld";-const bundleLocation = await bundle(require.resolve("./src/index"));+const bundleLocation = await bundle({+ entryPoint: require.resolve("./src/index"),+});const comps = await getCompositions(bundleLocation, {inputProps: {diff --git a/packages/docs/docs/bundle.md b/packages/docs/docs/bundle.mdindex c1467b607f..87a524728d 100644--- a/packages/docs/docs/bundle.md+++ b/packages/docs/docs/bundle.md@@ -8,18 +8,16 @@ _Part of the `@remotion/bundler` package._Bundles a Remotion project using Webpack and prepares it for rendering using [`renderMedia()`](/docs/renderer/render-media).```ts-const bundle: (- entryPoint: string,- onProgressUpdate?: (progress: number) => void,- options?: {- webpackOverride?: WebpackOverrideFn;- outDir?: string;- enableCaching?: boolean;- publicPath?: string;- rootDir?: string;- publicDir?: string | null;- }-) => Promise<string>;+const bundle: (options?: {+ entryPoint: string;+ onProgress?: (progress: number) => void;+ webpackOverride?: WebpackOverrideFn;+ outDir?: string;+ enableCaching?: boolean;+ publicPath?: string;+ rootDir?: string;+ publicDir?: string | null;+}) => Promise<string>;```## Arguments@@ -28,12 +26,12 @@ const bundle: (A `string` containing an absolute path of the entry point of a Remotion project. In a default Remotion project created with the template, the entry point is located at `src/index.tsx`.-### `onProgressUpdate?`+### `onProgress?`A callback function that notifies about the progress of the Webpack bundling. Passes a number between `0` and `100`. Example function:```ts twoslash-const onProgressUpdate = (progress: number) => {+const onProgress = (progress: number) => {console.log(`Webpack bundling progress: ${progress}%`);};```@@ -93,6 +91,35 @@ _Available from v3.2.13_TODO!!!+## Legacy function signature++Remotion versions earlier than v3.2.17 had the following function signature instead:++```ts+const bundle: (+ entryPoint: string,+ onProgress?: (progress: number) => void,+ options?: {+ webpackOverride?: WebpackOverrideFn;+ outDir?: string;+ enableCaching?: boolean;+ publicPath?: string;+ rootDir?: string;+ publicDir?: string | null;+ }+) => Promise<string>;+```++Example:++```ts+await bundle("src/index.tsx", () => console.log(progress * 100 + "% done"), {+ webpackOverride,+});+```++It is still supported in Remotion v3, but we encourage to migrate to the new function signature.+## Return valueA promise which will resolve into a `string` specifying the output directory.diff --git a/packages/docs/docs/legacy-babel-loader.md b/packages/docs/docs/legacy-babel-loader.mdindex 5c469e5fe4..ab26ca3a65 100644--- a/packages/docs/docs/legacy-babel-loader.md+++ b/packages/docs/docs/legacy-babel-loader.md@@ -71,7 +71,8 @@ export const webpackOverride: WebpackOverrideFn = (c) => c;import { bundle } from "@remotion/bundler";import { replaceLoadersWithBabel } from "@remotion/babel-loader";-await bundle(require.resolve("./src/index.ts"), () => undefined, {+await bundle({+ entryPoint: require.resolve("./src/index.ts"),webpackOverride: (config) => replaceLoadersWithBabel(config),});```diff --git a/packages/docs/docs/miscellaneous/render-all.md b/packages/docs/docs/miscellaneous/render-all.mdindex 4631950f49..e65350a397 100644--- a/packages/docs/docs/miscellaneous/render-all.md+++ b/packages/docs/docs/miscellaneous/render-all.md@@ -37,14 +37,11 @@ import { bundle } from "@remotion/bundler";import { getCompositions, renderMedia } from "@remotion/renderer";const start = async () => {- const bundled = await bundle(- require.resolve("./src/index.tsx"),- () => undefined,- {- // If you have a Webpack override, make sure to add it here- webpackOverride: (config) => config,- }- );+ const bundled = await bundle({+ entryPoint: require.resolve("./src/index.tsx"),+ // If you have a Webpack override, make sure to add it here+ webpackOverride: (config) => config,+ });const compositions = await getCompositions(bundled);diff --git a/packages/docs/docs/overwriting-webpack-config.md b/packages/docs/docs/overwriting-webpack-config.mdindex 3cde7bec4a..5c8f3e344f 100644--- a/packages/docs/docs/overwriting-webpack-config.md+++ b/packages/docs/docs/overwriting-webpack-config.md@@ -71,7 +71,8 @@ export const webpackOverride: WebpackOverrideFn = (c) => c;import { bundle } from "@remotion/bundler";import { webpackOverride } from "./src/webpack-override";-await bundle(require.resolve("./src/index.ts"), () => undefined, {+await bundle({+ entryPoint: require.resolve("./src/index.ts"),webpackOverride,});```diff --git a/packages/docs/docs/renderer/render-still.md b/packages/docs/docs/renderer/render-still.mdindex 9d57a62e15..24ab144e6c 100644--- a/packages/docs/docs/renderer/render-still.md+++ b/packages/docs/docs/renderer/render-still.md@@ -24,7 +24,9 @@ import { getCompositions, renderStill } from "@remotion/renderer";// The composition you want to renderconst compositionId = "HelloWorld";-const bundleLocation = await bundle(require.resolve("./src/index"));+const bundleLocation = await bundle({+ entryPoint: require.resolve("./src/index"),+});const comps = await getCompositions(bundleLocation, {inputProps: {diff --git a/packages/example/render-all.ts b/packages/example/render-all.tsindex 0eabf66d4d..b03ffcd048 100644--- a/packages/example/render-all.ts+++ b/packages/example/render-all.ts@@ -3,13 +3,10 @@ import {getCompositions, renderMedia} from '@remotion/renderer';import {webpackOverride} from './src/webpack-override';const start = async () => {- const bundled = await bundle(- require.resolve('./src/index.tsx'),- () => undefined,- {- webpackOverride,- }- );+ const bundled = await bundle({+ entryPoint: require.resolve('./src/index.tsx'),+ webpackOverride,+ });const compositions = await getCompositions(bundled);diff --git a/packages/example/src/simulate-lambda.ts b/packages/example/src/simulate-lambda.tsindex 68d012a7c4..8627f2c0cc 100644--- a/packages/example/src/simulate-lambda.ts+++ b/packages/example/src/simulate-lambda.ts@@ -9,7 +9,8 @@ import path from 'path';import {webpackOverride} from './webpack-override';const start = async () => {- const bundled = await bundle('./src/index.tsx', () => undefined, {+ const bundled = await bundle({+ entryPoint: './src/index.tsx',webpackOverride,});diff --git a/packages/example/src/test/stills.test.ts b/packages/example/src/test/stills.test.tsindex b00e89859d..9c7bdc41a9 100644--- a/packages/example/src/test/stills.test.ts+++ b/packages/example/src/test/stills.test.ts@@ -12,11 +12,10 @@ import {expect, test} from 'vitest';import {webpackOverride} from '../webpack-override';test('Can render a still using Node.JS APIs', async () => {- const bundled = await bundle(- path.join(process.cwd(), 'src/index.tsx'),- () => undefined,- {webpackOverride}- );+ const bundled = await bundle({+ entryPoint: path.join(process.cwd(), 'src/index.tsx'),+ webpackOverride,+ });const compositions = await getCompositions(bundled);