Skip to content

🎥 Make videos programmatically with React

tried without prettier but doesn't work

Jonny Burger6b7a8c626b57
diff --git a/packages/studio-server/package.json b/packages/studio-server/package.json
index 783a9d3ab2..17bdb2bce0 100644
--- a/packages/studio-server/package.json
+++ b/packages/studio-server/package.json
@@ -26,7 +26,7 @@
"@babel/parser": "7.24.1",
"semver": "7.5.3",
"remotion": "workspace:*",
- "recast": "0.23.6",
+ "recast": "0.23.9",
"@remotion/bundler": "workspace:*",
"@remotion/renderer": "workspace:*",
"@remotion/studio-shared": "workspace:*",
diff --git a/packages/studio-server/src/codemods/update-default-props.ts b/packages/studio-server/src/codemods/update-default-props.ts
index 4484efd3a0..29a800de53 100644
--- a/packages/studio-server/src/codemods/update-default-props.ts
+++ b/packages/studio-server/src/codemods/update-default-props.ts
@@ -1,6 +1,6 @@
import {stringifyDefaultProps, type EnumPath} from '@remotion/studio-shared';
import * as recast from 'recast';
-import {parse} from 'recast/parsers/babel-ts';
+import * as tsParser from 'recast/parsers/babel-ts';
export const updateDefaultProps = async ({
input,
@@ -12,53 +12,113 @@ export const updateDefaultProps = async ({
compositionId: string;
newDefaultProps: Record<string, unknown>;
enumPaths: EnumPath[];
-}): Promise<string> => {
+}): Promise<Promise<Promise<Promise<string>>>> => {
const ast = recast.parse(input, {
- parser: {parse},
+ parser: tsParser,
});
recast.types.visit(ast, {
visitJSXElement(path) {
- const openingElement = path.node.openingElement as any;
+ const {openingElement} = path.node;
// 1: ensure its the element we're looking for
+ const openingName = openingElement.name;
if (
- openingElement.name.name === 'Composition' &&
- openingElement.attributes.some(
- (attr: any) =>
- attr.name.name === 'id' && attr.value.value === compositionId,
- )
+ openingName.type !== 'JSXIdentifier' &&
+ openingName.type !== 'JSXNamespacedName'
) {
- // 2: Find the defaultProps attribute and handle related errors
- const defaultPropsAttr = openingElement.attributes.find(
- (attr: any) => attr.name.name === 'defaultProps',
- );
- if (!defaultPropsAttr) {
- throw new Error(
- `No \`defaultProps\` prop found in the <Composition/> tag with the ID "${compositionId}".`,
- );
- }
+ this.traverse(path); // Continue traversing the AST
+ return;
+ }
+
+ if (openingName.name !== 'Composition' && openingName.name !== 'Still') {
+ this.traverse(path); // Continue traversing the AST
+ return;
+ }
+
+ if (
+ !openingElement.attributes?.some((attr) => {
+ if (attr.type === 'JSXSpreadAttribute') {
+ return;
+ }
+
+ if (!attr.value) {
+ return;
+ }
+
+ if (attr.value.type === 'JSXElement') {
+ return;
+ }
+
+ if (attr.value.type === 'JSXExpressionContainer') {
+ return;
+ }
+
+ if (attr.value.type === 'JSXFragment') {
+ return;
+ }
+
+ return attr.name.name === 'id' && attr.value.value === compositionId;
+ })
+ ) {
+ this.traverse(path); // Continue traversing the AST
+ return;
+ }
- // 3: ensure only hardcoded values are provided
-
- const defaultPropsValue = defaultPropsAttr.value.expression; // Get the value of defaultProps
- if (
- defaultPropsValue.type !== 'ObjectExpression' &&
- defaultPropsValue.type !== 'ObjectLiteralExpression' &&
- defaultPropsValue.type !== 'AsExpression' &&
- defaultPropsValue.type !== 'TSAsExpression'
- ) {
- throw new Error(
- `\`defaultProps\` prop does not have a hardcoded value in the <Composition/> tag with the ID "${defaultPropsValue.type}".`,
- );
+ // 2: Find the defaultProps attribute and handle related errors
+ const defaultPropsAttr = openingElement.attributes.find((attr) => {
+ if (attr.type === 'JSXSpreadAttribute') {
+ this.traverse(path); // Continue traversing the AST
+ return;
}
- // 4: modify the code
+ return attr.name.name === 'defaultProps';
+ });
- defaultPropsAttr.value.expression = recast.types.builders.identifier(
- stringifyDefaultProps({props: newDefaultProps, enumPaths}),
+ if (!defaultPropsAttr) {
+ throw new Error(
+ `No \`defaultProps\` prop found in the <Composition/> tag with the ID "${compositionId}".`,
);
}
+ if (defaultPropsAttr.type === 'JSXSpreadAttribute') {
+ this.traverse(path); // Continue traversing the AST
+ return;
+ }
+
+ // 3: ensure only hardcoded values are provided
+ if (
+ !defaultPropsAttr.value ||
+ defaultPropsAttr.value.type === 'JSXElement' ||
+ defaultPropsAttr.value.type === 'JSXText' ||
+ defaultPropsAttr.value.type === 'StringLiteral' ||
+ defaultPropsAttr.value.type === 'NumericLiteral' ||
+ defaultPropsAttr.value.type === 'BigIntLiteral' ||
+ defaultPropsAttr.value.type === 'DecimalLiteral' ||
+ defaultPropsAttr.value.type === 'NullLiteral' ||
+ defaultPropsAttr.value.type === 'BooleanLiteral' ||
+ defaultPropsAttr.value.type === 'RegExpLiteral' ||
+ defaultPropsAttr.value.type === 'JSXFragment' ||
+ defaultPropsAttr.value.type === 'Literal'
+ ) {
+ throw new Error(
+ `\`defaultProps\` prop must be a hardcoded value in the <Composition/> tag, but it is a ${defaultPropsAttr.value?.type}".`,
+ );
+ }
+
+ const defaultPropsValue = defaultPropsAttr.value.expression;
+ if (
+ defaultPropsValue.type !== 'ObjectExpression' &&
+ defaultPropsValue.type !== 'TSAsExpression'
+ ) {
+ throw new Error(
+ `\`defaultProps\` prop must be a hardcoded value in the <Composition/> tag with the ID "${defaultPropsValue.type}".`,
+ );
+ }
+
+ defaultPropsAttr.value.expression = recast.types.builders.identifier(
+ stringifyDefaultProps({props: newDefaultProps, enumPaths}),
+ );
+
this.traverse(path); // Continue traversing the AST
},
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4edf726cfe..3fcca86b22 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1826,8 +1826,8 @@ importers:
specifier: ^8.4.2
version: 8.4.2
recast:
- specifier: 0.23.6
- version: 0.23.6
+ specifier: 0.23.9
+ version: 0.23.9
remotion:
specifier: workspace:*
version: link:../core
@@ -26289,15 +26289,15 @@ packages:
resolution: {integrity: sha512-onYyVhBNr4CmAxFsKS7bz+uTLRakypIe4R+5A824vBSkQy/hB3fZepoVEf8OVAxzLvK+H/jm9TzpI3ETSm64Kg==}
dev: false
- resolution: {integrity: sha512-9FHoNjX1yjuesMwuthAmPKabxYQdOgihFYmT5ebXfYGBcnqXZf3WOVz+5foEZ8Y83P4ZY6yQD5GMmtV+pgCCAQ==}
+ resolution: {integrity: sha512-Hx/BGIbwj+Des3+xy5uAtAbdCyqK9y9wbBcDFDYanLS9JnMqf7OeF87HQwUimE87OEc72mr6tkKUKMBBL+hF9Q==}
engines: {node: '>= 4'}
dependencies:
ast-types: 0.16.1
esprima: 4.0.1
source-map: 0.6.1
tiny-invariant: 1.3.3
- tslib: 2.5.0
+ tslib: 2.6.2
dev: false
@@ -28488,10 +28488,6 @@ packages:
resolution: {integrity: sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==}
dev: false
- resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==}
- dev: false
-
resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==}
dev: false