🎥 Make videos programmatically with React
alright
Jonny Burgerebb8f3853ff9
diff --git a/packages/lambda/src/api/__mocks__/create-function.ts b/packages/lambda/src/api/__mocks__/create-function.tsdeleted file mode 100644index c48dba7772..0000000000--- a/packages/lambda/src/api/__mocks__/create-function.ts+++ /dev/null@@ -1,26 +0,0 @@-import {VERSION} from 'remotion/version';-import {- DEFAULT_EPHEMERAL_STORAGE_IN_MB,- DEFAULT_MEMORY_SIZE,-} from '../../defaults';-import type {createFunction as original} from '../create-function';-import {addFunction} from '../mock-functions';--export const createFunction: typeof original = (input) => {- if (!input.alreadyCreated) {- addFunction(- {- functionName: input.functionName,- memorySizeInMb: DEFAULT_MEMORY_SIZE,- timeoutInSeconds: input.timeoutInSeconds,- version: VERSION,- diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,- },- input.region,- );- }-- return Promise.resolve({- FunctionName: input.functionName,- });-};diff --git a/packages/lambda/src/api/deploy-function.ts b/packages/lambda/src/api/deploy-function.tsindex 438629c000..dbe68a6495 100644--- a/packages/lambda/src/api/deploy-function.ts+++ b/packages/lambda/src/api/deploy-function.ts@@ -1,9 +1,13 @@import type {LogLevel} from '@remotion/renderer';import {wrapWithErrorHandling} from '@remotion/renderer/error-handling';-import type {CloudProvider, ProviderSpecifics} from '@remotion/serverless';+import type {+ CloudProvider,+ FullClientSpecifics,+ ProviderSpecifics,+} from '@remotion/serverless';import {VERSION} from 'remotion/version';-import {getFunctions} from '../api/get-functions';import {awsImplementation} from '../functions/aws-implementation';+import {awsFullClientSpecifics} from '../functions/full-client-implementation';import type {AwsRegion} from '../regions';import {DEFAULT_CLOUDWATCH_RETENTION_PERIOD,@@ -20,7 +24,6 @@ import {validateDiskSizeInMb} from '../shared/validate-disk-size-in-mb';import {validateMemorySize} from '../shared/validate-memory-size';import {validateCloudWatchRetentionPeriod} from '../shared/validate-retention-period';import {validateTimeout} from '../shared/validate-timeout';-import {createFunction} from './create-function';import {speculateFunctionName} from './speculate-function-name';type MandatoryParameters = {@@ -54,6 +57,7 @@ export const internalDeployFunction = async <Provider extends CloudProvider>(params: MandatoryParameters &OptionalParameters & {providerSpecifics: ProviderSpecifics<Provider>;+ fullClientSpecifics: FullClientSpecifics<Provider>;},): Promise<DeployFunctionOutput> => {validateMemorySize(params.memorySizeInMb);@@ -73,7 +77,7 @@ export const internalDeployFunction = async <Provider extends CloudProvider>(region: params.region,});- const fns = await getFunctions({+ const fns = await params.providerSpecifics.getFunctions({compatibleOnly: true,region: params.region,});@@ -86,7 +90,7 @@ export const internalDeployFunction = async <Provider extends CloudProvider>(f.diskSizeInMb === params.diskSizeInMb,);- const created = await createFunction({+ const created = await params.fullClientSpecifics.createFunction({createCloudWatchLogGroup: params.createCloudWatchLogGroup,region: params.region,zipFile: FUNCTION_ZIP_ARM64,@@ -163,5 +167,6 @@ export const deployFunction = ({vpcSecurityGroupIds,runtimePreference: runtimePreference ?? 'default',providerSpecifics: awsImplementation,+ fullClientSpecifics: awsFullClientSpecifics,});};diff --git a/packages/lambda/src/cli/commands/functions/deploy.ts b/packages/lambda/src/cli/commands/functions/deploy.tsindex c90620a18e..978db98228 100644--- a/packages/lambda/src/cli/commands/functions/deploy.ts+++ b/packages/lambda/src/cli/commands/functions/deploy.ts@@ -3,6 +3,7 @@ import type {LogLevel} from '@remotion/renderer';import {VERSION} from 'remotion/version';import {internalDeployFunction} from '../../../api/deploy-function';import {awsImplementation} from '../../../functions/aws-implementation';+import {awsFullClientSpecifics} from '../../../functions/full-client-implementation';import {DEFAULT_CLOUDWATCH_RETENTION_PERIOD,DEFAULT_EPHEMERAL_STORAGE_IN_MB,@@ -101,6 +102,7 @@ VPC Security Group IDs = ${vpcSecurityGroupIds}vpcSecurityGroupIds,runtimePreference,providerSpecifics: awsImplementation,+ fullClientSpecifics: awsFullClientSpecifics,});if (CliInternals.quietFlagProvided()) {CliInternals.Log.info({indent: false, logLevel}, functionName);diff --git a/packages/lambda/src/client.ts b/packages/lambda/src/client.tsindex b2f6f5ce05..da235e1736 100644--- a/packages/lambda/src/client.ts+++ b/packages/lambda/src/client.ts@@ -26,11 +26,11 @@ import {validateWebhookSignature} from './api/validate-webhook-signature';import type {RenderProgress} from './shared/constants';export type {WebhookPayload} from '@remotion/serverless';-export {CustomCredentials, DeleteAfter} from '@remotion/serverless/client';+export type {CustomCredentials, DeleteAfter} from '@remotion/serverless/client';export {getAwsClient,- GetAwsClientInput,- GetAwsClientOutput,+ type GetAwsClientInput,+ type GetAwsClientOutput,} from './api/get-aws-client';export type {AwsRegion} from './regions';export {diff --git a/packages/lambda/src/functions/aws-implementation.ts b/packages/lambda/src/functions/aws-implementation.tsindex 81d8a0fcae..5fa25f08cc 100644--- a/packages/lambda/src/functions/aws-implementation.ts+++ b/packages/lambda/src/functions/aws-implementation.ts@@ -23,6 +23,7 @@ import {getCloudwatchMethodUrl,getCloudwatchRendererUrl,} from '../shared/get-aws-urls';+import type {RuntimePreference} from '../shared/get-layers';import {isFlakyError} from '../shared/is-flaky-error';import {applyLifeCyleOperation} from '../shared/lifecycle-rules';import {randomHashImplementation} from '../shared/random-hash';@@ -56,6 +57,17 @@ export type AwsProvider = {s3Key: string;s3Url: string;};+ creationFunctionOptions: {+ createCloudWatchLogGroup: boolean;+ accountId: string;+ alreadyCreated: boolean;+ retentionInDays: number;+ customRoleArn: string;+ enableLambdaInsights: boolean;+ vpcSubnetIds: string;+ vpcSecurityGroupIds: string;+ runtimePreference: RuntimePreference;+ };};const validateDeleteAfter = (lifeCycleValue: unknown) => {diff --git a/packages/lambda/src/functions/full-client-implementation.ts b/packages/lambda/src/functions/full-client-implementation.tsindex fa201b583e..320a638521 100644--- a/packages/lambda/src/functions/full-client-implementation.ts+++ b/packages/lambda/src/functions/full-client-implementation.ts@@ -1,5 +1,6 @@import {bundle} from '@remotion/bundler';import type {FullClientSpecifics} from '@remotion/serverless';+import {createFunction} from '../api/create-function';import {uploadDir} from '../api/upload-dir';import {readDirectory} from '../shared/read-dir';import type {AwsProvider} from './aws-implementation';@@ -9,4 +10,5 @@ export const awsFullClientSpecifics: FullClientSpecifics<AwsProvider> = {id: '__remotion_full_client_specifics',readDirectory,uploadDir,+ createFunction,};diff --git a/packages/lambda/src/test/integration/console-hooks.ts b/packages/lambda/src/test/integration/console-hooks.tsindex 9297e73dd1..c61e49592c 100644--- a/packages/lambda/src/test/integration/console-hooks.ts+++ b/packages/lambda/src/test/integration/console-hooks.ts@@ -1,6 +1,6 @@import {NoReactInternals} from 'remotion/no-react';import {afterEach, beforeEach} from 'vitest';-import {cleanFnStore} from '../../api/mock-functions';+import {cleanFnStore} from '../mocks/mock-functions';let stdoutOutput: string[] = [];let stderrOutput: string[] = [];diff --git a/packages/lambda/src/test/integration/deploy-function.test.ts b/packages/lambda/src/test/integration/deploy-function.test.tsindex d761dd2ea9..07aea996a7 100644--- a/packages/lambda/src/test/integration/deploy-function.test.ts+++ b/packages/lambda/src/test/integration/deploy-function.test.ts@@ -1,16 +1,16 @@import {VERSION} from 'remotion/version';import {expect, test} from 'vitest';import {internalDeployFunction} from '../../api/deploy-function';+import {speculateFunctionName} from '../../client';+import {DEFAULT_EPHEMERAL_STORAGE_IN_MB} from '../../shared/constants';+import {+ mockFullClientSpecifics,+ mockImplementation,+} from '../mock-implementation';import {cleanFnStore,markFunctionAsIncompatible,-} from '../../api/mock-functions';-import {DEFAULT_EPHEMERAL_STORAGE_IN_MB} from '../../shared/constants';-import {LAMBDA_VERSION_STRING} from '../../shared/lambda-version-string';-import {mockImplementation} from '../mock-implementation';--const expectedFunctionName = (memory: number, timeout: number, disk: number) =>- `remotion-render-${LAMBDA_VERSION_STRING}-mem${memory}mb-disk${disk}mb-${timeout}sec`;+} from '../mocks/mock-functions';test('Should be able to deploy function', async () => {const {functionName} = await internalDeployFunction({@@ -19,18 +19,23 @@ test('Should be able to deploy function', async () => {timeoutInSeconds: 120,createCloudWatchLogGroup: true,customRoleArn: undefined,- diskSizeInMb: 10240,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,enableLambdaInsights: true,indent: false,logLevel: 'info',providerSpecifics: mockImplementation,+ fullClientSpecifics: mockFullClientSpecifics,runtimePreference: 'default',vpcSecurityGroupIds: undefined,vpcSubnetIds: undefined,cloudWatchLogRetentionPeriodInDays: undefined,});expect(functionName).toBe(- expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),+ speculateFunctionName({+ memorySizeInMb: 2048,+ timeoutInSeconds: 120,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,+ }),);});@@ -43,18 +48,23 @@ test('Should be able to get the function afterwards', async () => {timeoutInSeconds: 120,createCloudWatchLogGroup: true,customRoleArn: undefined,- diskSizeInMb: 10240,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,enableLambdaInsights: true,indent: false,logLevel: 'info',providerSpecifics: mockImplementation,+ fullClientSpecifics: mockFullClientSpecifics,runtimePreference: 'default',vpcSecurityGroupIds: undefined,vpcSubnetIds: undefined,cloudWatchLogRetentionPeriodInDays: undefined,});expect(functionName).toBe(- expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),+ speculateFunctionName({+ memorySizeInMb: 2048,+ timeoutInSeconds: 120,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,+ }),);const fns = await mockImplementation.getFunctions({region: 'us-east-1',@@ -62,16 +72,16 @@ test('Should be able to get the function afterwards', async () => {});expect(fns).toEqual([{- functionName: expectedFunctionName(- 2048,- 120,- DEFAULT_EPHEMERAL_STORAGE_IN_MB,- ),+ functionName: speculateFunctionName({+ memorySizeInMb: 2048,+ timeoutInSeconds: 120,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,+ }),memorySizeInMb: 2048,timeoutInSeconds: 120,version: VERSION,region: 'us-east-1',- diskSizeInMb: 2048,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,},]);const foreignFunctions = await mockImplementation.getFunctions({@@ -90,26 +100,31 @@ test('Should be able to delete the function', async () => {timeoutInSeconds: 120,createCloudWatchLogGroup: true,customRoleArn: undefined,- diskSizeInMb: 10240,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,enableLambdaInsights: true,indent: false,logLevel: 'info',providerSpecifics: mockImplementation,+ fullClientSpecifics: mockFullClientSpecifics,runtimePreference: 'default',vpcSecurityGroupIds: undefined,vpcSubnetIds: undefined,cloudWatchLogRetentionPeriodInDays: undefined,});expect(functionName).toBe(- expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),+ speculateFunctionName({+ memorySizeInMb: 2048,+ timeoutInSeconds: 120,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,+ }),);mockImplementation.deleteFunction({region: 'us-east-1',- functionName: expectedFunctionName(- 2048,- 120,- DEFAULT_EPHEMERAL_STORAGE_IN_MB,- ),+ functionName: speculateFunctionName({+ memorySizeInMb: 2048,+ timeoutInSeconds: 120,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,+ }),});const fns = await mockImplementation.getFunctions({region: 'us-east-1',@@ -132,13 +147,18 @@ test('Should be able to get the function afterwards', async () => {indent: false,logLevel: 'info',providerSpecifics: mockImplementation,+ fullClientSpecifics: mockFullClientSpecifics,runtimePreference: 'default',vpcSecurityGroupIds: undefined,vpcSubnetIds: undefined,cloudWatchLogRetentionPeriodInDays: undefined,});expect(functionName).toBe(- expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),+ speculateFunctionName({+ memorySizeInMb: 2048,+ timeoutInSeconds: 120,+ diskSizeInMb: 10240,+ }),);const fns = await mockImplementation.getFunctions({region: 'us-east-1',@@ -146,20 +166,24 @@ test('Should be able to get the function afterwards', async () => {});expect(fns).toEqual([{- functionName: expectedFunctionName(- 2048,- 120,- DEFAULT_EPHEMERAL_STORAGE_IN_MB,- ),+ functionName: speculateFunctionName({+ memorySizeInMb: 2048,+ timeoutInSeconds: 120,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,+ }),memorySizeInMb: 2048,timeoutInSeconds: 120,version: VERSION,region: 'us-east-1',- diskSizeInMb: 2048,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,},]);markFunctionAsIncompatible(- expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),+ speculateFunctionName({+ memorySizeInMb: 2048,+ timeoutInSeconds: 120,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,+ }),);const compatibleFns = await mockImplementation.getFunctions({region: 'us-east-1',@@ -172,16 +196,16 @@ test('Should be able to get the function afterwards', async () => {expect(compatibleFns).toEqual([]);expect(incompatibleFns).toEqual([{- functionName: expectedFunctionName(- 2048,- 120,- DEFAULT_EPHEMERAL_STORAGE_IN_MB,- ),+ functionName: speculateFunctionName({+ memorySizeInMb: 2048,+ timeoutInSeconds: 120,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,+ }),memorySizeInMb: 2048,timeoutInSeconds: 120,version: '2021-06-23',region: 'us-east-1',- diskSizeInMb: 2048,+ diskSizeInMb: DEFAULT_EPHEMERAL_STORAGE_IN_MB,},]);});diff --git a/packages/lambda/src/test/mock-implementation.ts b/packages/lambda/src/test/mock-implementation.tsindex b0f0a13e01..e1deb27b3c 100644--- a/packages/lambda/src/test/mock-implementation.ts+++ b/packages/lambda/src/test/mock-implementation.ts@@ -7,7 +7,6 @@ import type {} from '@remotion/serverless';import {Readable} from 'stream';import {estimatePrice} from '../api/estimate-price';-import {deleteMockFunction, getAllMockFunctions} from '../api/mock-functions';import {speculateFunctionName} from '../api/speculate-function-name';import {MAX_EPHEMERAL_STORAGE_IN_MB} from '../defaults';import type {AwsProvider} from '../functions/aws-implementation';@@ -24,6 +23,8 @@ import {getMockCallFunctionSync,} from './mocks/aws-clients';import {mockBundleSite} from './mocks/mock-bundle-site';+import {mockCreateFunction} from './mocks/mock-create-function';+import {deleteMockFunction, getAllMockFunctions} from './mocks/mock-functions';import {mockReadDirectory} from './mocks/mock-read-dir';import {addMockBucket,@@ -199,4 +200,5 @@ export const mockFullClientSpecifics: FullClientSpecifics<AwsProvider> = {id: '__remotion_full_client_specifics',readDirectory: mockReadDirectory,uploadDir: mockUploadDir,+ createFunction: mockCreateFunction,};diff --git a/packages/lambda/src/test/mocks/mock-create-function.ts b/packages/lambda/src/test/mocks/mock-create-function.tsnew file mode 100644index 0000000000..6a8e91ff75--- /dev/null+++ b/packages/lambda/src/test/mocks/mock-create-function.ts@@ -0,0 +1,23 @@+import type {CreateFunction} from '@remotion/serverless';+import {VERSION} from 'remotion/version';+import type {AwsProvider} from '../../functions/aws-implementation';+import {addFunction} from './mock-functions';++export const mockCreateFunction: CreateFunction<AwsProvider> = (input) => {+ if (!input.alreadyCreated) {+ addFunction(+ {+ functionName: input.functionName,+ memorySizeInMb: input.memorySizeInMb,+ timeoutInSeconds: input.timeoutInSeconds,+ version: VERSION,+ diskSizeInMb: input.ephemerealStorageInMb,+ },+ input.region,+ );+ }++ return Promise.resolve({+ FunctionName: input.functionName,+ });+};diff --git a/packages/lambda/src/api/mock-functions.ts b/packages/lambda/src/test/mocks/mock-functions.tssimilarity index 91%rename from packages/lambda/src/api/mock-functions.tsrename to packages/lambda/src/test/mocks/mock-functions.tsindex 563b473166..c0c53de240 100644--- a/packages/lambda/src/api/mock-functions.ts+++ b/packages/lambda/src/test/mocks/mock-functions.ts@@ -4,8 +4,8 @@ import type {GetFunctions,} from '@remotion/serverless';import {VERSION} from 'remotion/version';-import type {AwsProvider} from '../functions/aws-implementation';-import type {AwsRegion} from '../regions';+import type {AwsProvider} from '../../functions/aws-implementation';+import type {AwsRegion} from '../../regions';export let mockFunctionsStore: (FunctionInfo & {region: AwsRegion;diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.tsindex 36c4066dac..b2b28a08fb 100644--- a/packages/renderer/src/index.ts+++ b/packages/renderer/src/index.ts@@ -95,7 +95,7 @@ export {CancelSignal, makeCancelSignal} from './make-cancel-signal';export {openBrowser} from './open-browser';export type {ChromiumOptions} from './open-browser';export {ColorSpace} from './options/color-space';-export {DeleteAfter} from './options/delete-after';+export type {DeleteAfter} from './options/delete-after';export {OpenGlRenderer} from './options/gl';export {NumberOfGifLoops} from './options/number-of-gif-loops';export {diff --git a/packages/serverless/src/provider-implementation.ts b/packages/serverless/src/provider-implementation.tsindex 0b64521614..0ce21e9a7a 100644--- a/packages/serverless/src/provider-implementation.ts+++ b/packages/serverless/src/provider-implementation.ts@@ -299,6 +299,20 @@ export type UploadDir<Provider extends CloudProvider> = (options: {forcePathStyle: boolean;}) => Promise<void>;+type CreateFunctionOptions<Provider extends CloudProvider> = {+ region: Provider['region'];+ logLevel: LogLevel;+ ephemerealStorageInMb: number;+ timeoutInSeconds: number;+ memorySizeInMb: number;+ functionName: string;+ zipFile: string;+} & Provider['creationFunctionOptions'];++export type CreateFunction<Provider extends CloudProvider> = (+ options: CreateFunctionOptions<Provider>,+) => Promise<{FunctionName: string}>;+export type InsideFunctionSpecifics = {getBrowserInstance: GetBrowserInstance;forgetBrowserEventLoop: ForgetBrowserEventLoop;@@ -314,6 +328,7 @@ export type FullClientSpecifics<Provider extends CloudProvider> = {bundleSite: typeof bundle;readDirectory: ReadDir;uploadDir: UploadDir<Provider>;+ createFunction: CreateFunction<Provider>;};export type ProviderSpecifics<Provider extends CloudProvider> = {diff --git a/packages/serverless/src/test/expected-out-name.test.ts b/packages/serverless/src/test/expected-out-name.test.tsindex 43c9e3e9df..79edb89ec8 100644--- a/packages/serverless/src/test/expected-out-name.test.ts+++ b/packages/serverless/src/test/expected-out-name.test.ts@@ -11,6 +11,7 @@ type MockProvider = {s3Key: string;s3Url: string;};+ creationFunctionOptions: {};};const testRenderMetadata: RenderMetadata<MockProvider> = {diff --git a/packages/serverless/src/types.ts b/packages/serverless/src/types.tsindex 7d878baa79..3bb0be40b6 100644--- a/packages/serverless/src/types.ts+++ b/packages/serverless/src/types.ts@@ -6,10 +6,15 @@ export interface CloudProvider<string,unknown>,+ CreateFunctionSpecifics extends Record<string, unknown> = Record<+ string,+ unknown+ >,> {type: string;region: Region;receivedArtifactType: ReceivedArtifactType;+ creationFunctionOptions: CreateFunctionSpecifics;}export type ReceivedArtifact<Provider extends CloudProvider> = {