🎥 Make videos programmatically with React
Move `ensureLocalBundle` from `@remotion/vercel` to `template-vercel`
Jonny Burgerf5d6729f692d
diff --git a/packages/template-vercel/create-snapshot.ts b/packages/template-vercel/create-snapshot.tsindex 431248e5da..b1a4350cd6 100644--- a/packages/template-vercel/create-snapshot.ts+++ b/packages/template-vercel/create-snapshot.ts@@ -1,5 +1,6 @@import { put } from "@vercel/blob";import { addBundleToSandbox, createSandbox } from "@remotion/vercel";+import { ensureLocalBundle } from "./src/app/api/render/helpers";const getSnapshotBlobKey = () =>`snapshot-cache/${process.env.VERCEL_DEPLOYMENT_ID ?? "local"}.json`;@@ -12,6 +13,7 @@ const sandbox = await createSandbox({});console.log("[create-snapshot] Adding Remotion bundle...");+ensureLocalBundle(".remotion");await addBundleToSandbox({ sandbox, bundleDir: ".remotion" });console.log("[create-snapshot] Taking snapshot...");diff --git a/packages/template-vercel/src/app/api/render/helpers.ts b/packages/template-vercel/src/app/api/render/helpers.tsindex 69908ddd33..e99d636620 100644--- a/packages/template-vercel/src/app/api/render/helpers.ts+++ b/packages/template-vercel/src/app/api/render/helpers.ts@@ -1,3 +1,22 @@+import { execSync } from "child_process";+import { existsSync } from "fs";+import path from "path";++export function ensureLocalBundle(bundleDir: string): void {+ const fullBundleDir = path.join(process.cwd(), bundleDir);+ if (!existsSync(fullBundleDir)) {+ try {+ execSync(`node_modules/.bin/remotion bundle --out-dir ./${bundleDir}`, {+ cwd: process.cwd(),+ stdio: "pipe",+ });+ } catch (e) {+ const stderr = (e as { stderr?: Buffer }).stderr?.toString() ?? "";+ throw new Error(`Remotion bundle failed: ${stderr}`);+ }+ }+}+export type RenderProgress =| { type: "phase"; phase: string; progress: number; subtitle?: string }| { type: "done"; url: string; size: number }diff --git a/packages/template-vercel/src/app/api/render/route.ts b/packages/template-vercel/src/app/api/render/route.tsindex e2daf05318..df975e6d68 100644--- a/packages/template-vercel/src/app/api/render/route.ts+++ b/packages/template-vercel/src/app/api/render/route.ts@@ -7,7 +7,7 @@ import {import { waitUntil } from "@vercel/functions";import { COMP_NAME } from "../../../../types/constants";import { RenderRequest } from "../../../../types/schema";-import { formatSSE, type RenderProgress } from "./helpers";+import { ensureLocalBundle, formatSSE, type RenderProgress } from "./helpers";import { restoreSnapshot } from "./restore-snapshot";export async function POST(req: Request) {@@ -46,6 +46,7 @@ export async function POST(req: Request) {try {if (!process.env.VERCEL) {+ ensureLocalBundle(".remotion");await addBundleToSandbox({ sandbox, bundleDir: ".remotion" });}diff --git a/packages/vercel/src/add-bundle-to-sandbox.ts b/packages/vercel/src/add-bundle-to-sandbox.tsindex ccf0fefb40..6ee53bc0b3 100644--- a/packages/vercel/src/add-bundle-to-sandbox.ts+++ b/packages/vercel/src/add-bundle-to-sandbox.ts@@ -1,29 +1,8 @@import type {Sandbox} from '@vercel/sandbox';-import {execSync} from 'child_process';-import {existsSync} from 'fs';import {readdir, readFile} from 'fs/promises';import path from 'path';import {REMOTION_SANDBOX_BUNDLE_DIR} from './internals/add-bundle';-function ensureLocalBundle(bundleDir: string): void {- if (process.env.VERCEL) {- return;- }-- const fullBundleDir = path.join(process.cwd(), bundleDir);- if (!existsSync(fullBundleDir)) {- try {- execSync(`node_modules/.bin/remotion bundle --out-dir ./${bundleDir}`, {- cwd: process.cwd(),- stdio: 'pipe',- });- } catch (e) {- const stderr = (e as {stderr?: Buffer}).stderr?.toString() ?? '';- throw new Error(`Remotion bundle failed: ${stderr}`);- }- }-}-async function getRemotionBundleFiles(bundleDir: string,): Promise<{path: string; content: Buffer}[]> {@@ -56,7 +35,6 @@ export async function addBundleToSandbox({sandbox: Sandbox;bundleDir: string;}): Promise<void> {- ensureLocalBundle(bundleDir);const bundleFiles = await getRemotionBundleFiles(bundleDir);const dirs = new Set<string>();