🎥 Make videos programmatically with React
hmm
Jonny Burger91c193b27fbb
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.tsxindex fabda6ef09..6ac1065d94 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.tsx+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.tsx@@ -1,5 +1,6 @@-import {z} from 'zod';+import type {z} from 'zod';import type {ZodType} from '../../get-zod-if-possible';+import {useZodIfPossible} from '../../get-zod-if-possible';import type {JSONPath} from './zod-types';import {ZonNonEditableValue} from './ZodNonEditableValue';import {ZodOrNullishEditor} from './ZodOrNullishEditor';@@ -58,6 +59,11 @@ export const ZodUnionEditor: React.FC<{}) => {const {options} = schema._def as z.ZodUnionDef;+ const z = useZodIfPossible();+ if (!z) {+ throw new Error('expected zod');+ }+if (options.length > 2) {return (<ZonNonEditableValuediff --git a/packages/cli/src/editor/components/get-zod-if-possible.tsx b/packages/cli/src/editor/components/get-zod-if-possible.tsxindex 794e4902d1..2d866855cf 100644--- a/packages/cli/src/editor/components/get-zod-if-possible.tsx+++ b/packages/cli/src/editor/components/get-zod-if-possible.tsx@@ -13,7 +13,7 @@ export type ZodColorType = Awaited<typeof import('@remotion/z-color')>['zColor'];-const getZodIfPossible = async (): Promise<ZodType | null> => {+export const getZodIfPossible = async (): Promise<ZodType | null> => {try {const {z} = await import('zod');return z;diff --git a/packages/cli/src/test/create-zod-values.test.ts b/packages/cli/src/test/create-zod-values.test.tsindex de6f64ffcf..989b73bc90 100644--- a/packages/cli/src/test/create-zod-values.test.ts+++ b/packages/cli/src/test/create-zod-values.test.ts@@ -1,19 +1,34 @@import {zColor} from '@remotion/z-color';import {expect, test} from 'vitest';-import {z} from 'zod';+import {getZodIfPossible} from '../editor/components/get-zod-if-possible';import {createZodValues} from '../editor/components/RenderModal/SchemaEditor/create-zod-values';-test('Should be able to create a string', () => {+const getZ = async () => {+ const z = await getZodIfPossible();+ if (!z) {+ throw new Error('Zod not found');+ }++ return z;+};++test('Should be able to create a string', async () => {+ const z = await getZ();+const hi = createZodValues(z.string(), z);expect(hi).toBe('');});-test('Should be able to create a number', () => {+test('Should be able to create a number', async () => {+ const z = await getZ();+const hi = createZodValues(z.number(), z);expect(hi).toBe(0);});-test('Should be able to create an object', () => {+test('Should be able to create an object', async () => {+ const z = await getZ();+const hi = createZodValues(z.object({a: z.string(),@@ -24,23 +39,31 @@ test('Should be able to create an object', () => {expect(hi).toEqual({a: '', b: 0});});-test('Should be able to create an array', () => {+test('Should be able to create an array', async () => {+ const z = await getZ();+expect(createZodValues(z.array(z.string()), z)).toEqual(['']);expect(createZodValues(z.array(z.number()), z)).toEqual([0]);});-test('Should be able to create a union', () => {+test('Should be able to create a union', async () => {+ const z = await getZ();+expect(createZodValues(z.union([z.string(), z.number()]), z)).toBe('');expect(createZodValues(z.union([z.number(), z.string()]), z)).toBe(0);// @ts-expect-error unionexpect(createZodValues(z.union([]))).toBe(undefined);});-test('Zod literal', () => {+test('Zod literal', async () => {+ const z = await getZ();+expect(createZodValues(z.literal('hi'), z)).toBe('hi');});-test('Should be able to create a discriminated union', () => {+test('Should be able to create a discriminated union', async () => {+ const z = await getZ();+expect(createZodValues(z.discriminatedUnion('status', [@@ -67,13 +90,17 @@ test('Should be able to create a discriminated union', () => {);});-test('Zod instanceof', () => {+test('Zod instanceof', async () => {+ const z = await getZ();+expect(() => createZodValues(z.instanceof(Error), z)).toThrow(/Cannot create a value for type z.any()/);});-test('Zod intersection', () => {+test('Zod intersection', async () => {+ const z = await getZ();+const Person = z.object({name: z.string(),});@@ -89,56 +116,76 @@ test('Zod intersection', () => {});});-test('Zod tuples', () => {+test('Zod tuples', async () => {+ const z = await getZ();+const Tuple = z.tuple([z.string(), z.number()]);expect(createZodValues(Tuple, z)).toEqual(['', 0]);});-test('Zod record', () => {+test('Zod record', async () => {+ const z = await getZ();+const Record = z.record(z.string());expect(createZodValues(Record, z)).toEqual({key: ''});});-test('Zod map', () => {+test('Zod map', async () => {+ const z = await getZ();+const map = z.map(z.string(), z.number());expect(createZodValues(map, z)).toEqual(new Map([['', 0]]));});-test('Zod lazy', () => {+test('Zod lazy', async () => {+ const z = await getZ();+const Lazy = z.lazy(() => z.string());expect(createZodValues(Lazy, z)).toBe('');});-test('Zod set', () => {+test('Zod set', async () => {+ const z = await getZ();+const set = z.set(z.string());expect(createZodValues(set, z)).toEqual(new Set(['']));const set2 = z.set(z.number());expect(createZodValues(set2, z)).toEqual(new Set([0]));});-test('Zod function', () => {+test('Zod function', async () => {+ const z = await getZ();+const fn = z.function();expect(() => createZodValues(fn, z)).toThrow(/Cannot create a value for type function/);});-test('Zod undefined', () => {+test('Zod undefined', async () => {+ const z = await getZ();+const undef = z.void();expect(createZodValues(undef, z)).toBe(undefined);});-test('Zod null', () => {+test('Zod null', async () => {+ const z = await getZ();+const undef = z.null();expect(createZodValues(undef, z)).toBe(null);});-test('Zod enum', () => {+test('Zod enum', async () => {+ const z = await getZ();+const Enum = z.enum(['a', 'b']);expect(createZodValues(Enum, z)).toBe('a');});-test('Zod nativeEnum', () => {+test('Zod nativeEnum', async () => {+ const z = await getZ();+enum Fruits {Apple,Banana,@@ -147,61 +194,83 @@ test('Zod nativeEnum', () => {expect(createZodValues(Enum, z)).toBe(Fruits.Apple);});-test('Zod optional', () => {+test('Zod optional', async () => {+ const z = await getZ();+const Optional = z.string().optional();expect(createZodValues(Optional, z)).toBe('');});-test('Zod nullable', () => {+test('Zod nullable', async () => {+ const z = await getZ();+const Nullable = z.string().nullable();expect(createZodValues(Nullable, z)).toBe('');});-test('Zod undefined', () => {+test('Zod undefined', async () => {+ const z = await getZ();+const undef = z.string().default('tuna');expect(createZodValues(undef, z)).toBe('tuna');});-test('Zod catch', () => {+test('Zod catch', async () => {+ const z = await getZ();+const undef = z.string().catch('tuna');expect(createZodValues(undef, z)).toBe('');});-test('Zod promise', () => {+test('Zod promise', async () => {+ const z = await getZ();+const undef = z.string().promise();(createZodValues(undef, z) as Promise<unknown>).then((v) => {expect(v).toBe('');});});-test('Zod transform', () => {+test('Zod transform', async () => {+ const z = await getZ();+// Intentional: We don't parse the Zod values, so we should not transform themconst undef = z.literal('abc').transform((v) => v.toUpperCase());expect(createZodValues(undef, z)).toBe('abc');});-test('Zod branded', () => {+test('Zod branded', async () => {+ const z = await getZ();+const Cat = z.object({name: z.string()}).brand<'Cat'>();expect(createZodValues(Cat, z)).toEqual({name: ''});});-test('Zod lazy', () => {+test('Zod lazy', async () => {+ const z = await getZ();+const datelike = z.union([z.number(), z.string(), z.date()]);const datelikeToDate = datelike.pipe(z.coerce.date());expect(createZodValues(datelikeToDate, z)).toBeInstanceOf(Date);});-test('Zod coerce', () => {+test('Zod coerce', async () => {+ const z = await getZ();+const datelike = z.union([z.number(), z.string(), z.date()]);const datelikeToDate = datelike.pipe(z.coerce.date());expect(createZodValues(datelikeToDate, z)).toBeInstanceOf(Date);});-test('Zod strict', () => {+test('Zod strict', async () => {+ const z = await getZ();+const strict = z.strictObject({a: z.string()}).strict();expect(createZodValues(strict, z)).toEqual({a: ''});});-test('Should create a color', () => {+test('Should create a color', async () => {+ const z = await getZ();+expect(createZodValues(zColor(), z)).toBe('#ffffff');});diff --git a/packages/cli/src/test/folder-tree.test.ts b/packages/cli/src/test/folder-tree.test.tsindex 36836f262e..e34fc75b13 100644--- a/packages/cli/src/test/folder-tree.test.ts+++ b/packages/cli/src/test/folder-tree.test.ts@@ -1,7 +1,7 @@import type {ComponentType} from 'react';import React from 'react';import {expect, test} from 'vitest';-import {z} from 'zod';+import {getZodIfPossible} from '../editor/components/get-zod-if-possible';import {createFolderTree} from '../editor/helpers/create-folder-tree';const SampleComp: React.FC<{}> = () => null;@@ -9,9 +9,19 @@ const component = React.lazy(() =>Promise.resolve({default: SampleComp as ComponentType<unknown>}));-const any = z.any();+const getZ = async () => {+ const z = await getZodIfPossible();+ if (!z) {+ throw new Error('Zod not found');+ }-test('Should create a good folder tree with 1 item inside and 1 item outside', () => {+ return z;+};++test('Should create a good folder tree with 1 item inside and 1 item outside', async () => {+ const z = await getZ();++ const any = z.any();const tree = createFolderTree([{@@ -97,7 +107,10 @@ test('Should create a good folder tree with 1 item inside and 1 item outside', (]);});-test('Should handle nested folders well', () => {+test('Should handle nested folders well', async () => {+ const z = await getZ();+ const any = z.any();+const tree = createFolderTree([{diff --git a/packages/player/src/SharedPlayerContext.tsx b/packages/player/src/SharedPlayerContext.tsxindex db0c70b019..025da72951 100644--- a/packages/player/src/SharedPlayerContext.tsx+++ b/packages/player/src/SharedPlayerContext.tsx@@ -9,7 +9,6 @@ import type {TimelineContextValue,} from 'remotion';import {Internals} from 'remotion';-import {z} from 'zod';import {getPreferredVolume, persistVolume} from './volume-persistance.js';export const SharedPlayerContexts: React.FC<{@@ -53,7 +52,7 @@ export const SharedPlayerContexts: React.FC<{folderName: null,defaultProps: undefined,parentFolderName: null,- schema: z.any(),+ schema: null,},],folders: [],