Skip to content

🎥 Make videos programmatically with React

`@remotion/studio-codemods`: Remove JSX formatter compatibility APIs

Jonny Burger4d13f10cc405
diff --git a/packages/studio-codemods/src/insert-jsx-element.ts b/packages/studio-codemods/src/insert-jsx-element.ts
index 6db3dfef16..2c9ee9af8a 100644
--- a/packages/studio-codemods/src/insert-jsx-element.ts
+++ b/packages/studio-codemods/src/insert-jsx-element.ts
@@ -56,12 +56,6 @@ export type InsertJsxElementCodemodEnvironment = {
dirname: (fileName: string) => string;
extname: (fileName: string) => string;
fileExists: (fileName: string) => boolean;
- // Kept optional for compatibility with callers from before source edits
- // replaced the full-file formatting pass.
- formatFile?: (input: {
- contents: string;
- prettierConfigOverride: Record<string, unknown> | null;
- }) => Promise<{output: string; formatted: boolean}>;
isAbsolute: (fileName: string) => boolean;
join: (...parts: string[]) => string;
pathSeparator: string;
@@ -132,11 +126,9 @@ const relativeVirtualPath = (from: string, to: string) => {
};
export const makeInMemoryInsertJsxElementCodemodEnvironment = ({
- formatFile,
project,
svgMarkupToJsx,
}: {
- formatFile?: InsertJsxElementCodemodEnvironment['formatFile'];
project: {files: Record<string, string>; rootDir: string};
svgMarkupToJsx: InsertJsxElementCodemodEnvironment['svgMarkupToJsx'];
}): InsertJsxElementCodemodEnvironment => {
@@ -156,7 +148,6 @@ export const makeInMemoryInsertJsxElementCodemodEnvironment = ({
},
fileExists: (fileName) =>
filesByNormalizedPath.has(normalizeVirtualPath(fileName)),
- formatFile,
isAbsolute: (fileName) => fileName.startsWith('/'),
join: (...parts) => resolveVirtualPath(...parts),
pathSeparator: '/',
@@ -3109,7 +3100,6 @@ export const insertJsxElementIntoComposition = async ({
source: string;
oldContents: string;
output: string;
- formatted: boolean;
logLine: number;
nodePathRemappings: SequenceNodePathRemapping[];
insertedNodePath: SequenceNodePath | null;
@@ -3244,8 +3234,6 @@ export const insertJsxElementIntoComposition = async ({
],
input,
});
- const formatted = true;
-
const {finalNodePathByNode, nodePathRemappings} = getNodePathRemappings({
ast,
captured: capturedNodePaths,
@@ -3261,7 +3249,6 @@ export const insertJsxElementIntoComposition = async ({
source: location.source,
oldContents: input,
output,
- formatted,
insertedNodePath,
logLine,
nodePathRemappings,
@@ -3273,13 +3260,11 @@ export const insertJsxElementIntoProjectWithNodePathRemappings = async <
>({
project,
request,
- formatFile,
svgMarkupToJsx,
wrapInSequence,
}: {
project: Project;
request: InsertJsxElementRequest;
- formatFile?: InsertJsxElementCodemodEnvironment['formatFile'];
svgMarkupToJsx: InsertJsxElementCodemodEnvironment['svgMarkupToJsx'];
wrapInSequence: {
dimensions: {width: number; height: number} | null;
@@ -3299,7 +3284,6 @@ export const insertJsxElementIntoProjectWithNodePathRemappings = async <
compositionId: request.compositionId,
element: request.element,
environment: makeInMemoryInsertJsxElementCodemodEnvironment({
- formatFile,
project,
svgMarkupToJsx,
}),
diff --git a/packages/studio-codemods/src/split-jsx-sequence.ts b/packages/studio-codemods/src/split-jsx-sequence.ts
index 7ac687ef86..fbb904dd3a 100644
--- a/packages/studio-codemods/src/split-jsx-sequence.ts
+++ b/packages/studio-codemods/src/split-jsx-sequence.ts
@@ -394,16 +394,9 @@ export const splitJsxSequence = ({
nodePath: SequenceNodePath;
sequenceKeys: string[];
splitFrame: number;
- // Kept optional for compatibility with callers from before source edits
- // replaced the full-file formatting pass.
- formatFile?: (input: {
- contents: string;
- prettierConfigOverride: Record<string, unknown> | null;
- }) => Promise<{output: string; formatted: boolean}>;
prettierConfigOverride?: Record<string, unknown> | null;
}): Promise<{
output: string;
- formatted: boolean;
nodeLabel: string;
logLine: number;
nodePathRemappings: SequenceNodePathRemapping[];
@@ -505,7 +498,6 @@ export const splitJsxSequence = ({
return Promise.resolve({
output,
- formatted: true,
nodeLabel: getJsxElementTagLabel(jsxElement),
logLine:
jsxElement.openingElement.loc?.start.line ??
diff --git a/packages/studio-codemods/src/test/insert-solid.test.ts b/packages/studio-codemods/src/test/insert-solid.test.ts
index 1847b18f76..b82ad94e56 100644
--- a/packages/studio-codemods/src/test/insert-solid.test.ts
+++ b/packages/studio-codemods/src/test/insert-solid.test.ts
@@ -76,12 +76,7 @@ export const MyComposition = () => {
export const Root = () => <Composition id = "MyComp" component={MyComposition}/>;
`;
- let formatCalls = 0;
const result = await insertJsxElementIntoProjectWithNodePathRemappings({
- formatFile: () => {
- formatCalls++;
- throw new Error('Prettier should not be called when inserting a Solid');
- },
project: {
files: {'/project/src/index.tsx': source},
rootDir: '/project',
@@ -105,7 +100,6 @@ export const Root = () => <Composition id = "MyComp" component={MyComposition}/>
wrapInSequence: null,
});
- expect(formatCalls).toBe(0);
expect(result.project.files['/project/src/index.tsx'])
.toBe(`import {Composition, AbsoluteFill, Solid} from 'remotion';
@@ -137,12 +131,7 @@ test('asset and component insertions also avoid the full-file formatter', async
export const MyComposition = () => <><AbsoluteFill /></>;
export const Root = () => <Composition id="MyComp" component={MyComposition}/>;
`;
- let formatCalls = 0;
const assetResult = await insertJsxElementIntoProjectWithNodePathRemappings({
- formatFile: () => {
- formatCalls++;
- throw new Error('The full-file formatter should not be called');
- },
project: {
files: {'/project/src/index.tsx': source},
rootDir: '/project',
@@ -168,10 +157,6 @@ export const Root = () => <Composition id="MyComp" component={MyComposition}/>;
});
const componentResult =
await insertJsxElementIntoProjectWithNodePathRemappings({
- formatFile: () => {
- formatCalls++;
- throw new Error('The full-file formatter should not be called');
- },
project: {
files: {'/project/src/index.tsx': source},
rootDir: '/project',
@@ -195,7 +180,6 @@ export const Root = () => <Composition id="MyComp" component={MyComposition}/>;
wrapInSequence: null,
});
- expect(formatCalls).toBe(0);
expect(assetResult.project.files['/project/src/index.tsx']).toContain(
'<CanvasImage\n',
);
diff --git a/packages/studio-server/src/helpers/resolve-composition-component.ts b/packages/studio-server/src/helpers/resolve-composition-component.ts
index 278ffb1f1a..ec87565f3f 100644
--- a/packages/studio-server/src/helpers/resolve-composition-component.ts
+++ b/packages/studio-server/src/helpers/resolve-composition-component.ts
@@ -95,7 +95,6 @@ export const insertJsxElementIntoComposition = ({
source: string;
oldContents: string;
output: string;
- formatted: boolean;
logLine: number;
nodePathRemappings: SequenceNodePathRemapping[];
insertedNodePath: SequenceNodePath | null;
diff --git a/packages/studio-server/src/test/split-jsx-sequence.test.ts b/packages/studio-server/src/test/split-jsx-sequence.test.ts
index 7438f302ec..9b3428719c 100644
--- a/packages/studio-server/src/test/split-jsx-sequence.test.ts
+++ b/packages/studio-server/src/test/split-jsx-sequence.test.ts
@@ -132,19 +132,13 @@ export const Comp = () => {
)
}
`;
- let formatCalls = 0;
const {output} = await splitJsxSequenceCodemod({
input,
nodePath: lineContainingToNodePath(input, '<Sequence'),
sequenceKeys: sequenceTimingKeys,
splitFrame: 30,
- formatFile: () => {
- formatCalls++;
- throw new Error('Prettier should not be called when splitting a clip');
- },
});
- expect(formatCalls).toBe(0);
expect(output).toStartWith(
'const deliberatelyUnformatted = {value : true}\n',
);