Skip to main content

moveFolder()v4.0.528

Moves a folder and its contents within a registration file.

warning

Draft API: This API is experimental and may change.

move-folder.ts
import {moveFolder, type CodemodProject} from '@remotion/codemods'; declare const project: CodemodProject; const result = moveFolder({ project, compositionFile: 'src/Root.tsx', folder: {name: 'Published', parentName: 'Social'}, destination: {type: 'root'}, }); console.log(result);

Moving a folder into itself or a descendant is rejected. A folder with the same name at the destination is also rejected. Update descendant parentName paths after the move.

Options

project

An in-memory CodemodProject. The input project is not mutated.

compositionFile

The project file containing the composition registrations. Registration edits support <Composition>, <Still>, and <Folder> with their original import names and static IDs or folder names.

folder

Identifies a folder in compositionFile.

name

The folder name.

parentName

The slash-separated path of the parent folder, such as Social/Published. Use null for a top-level folder.

destination

Where to move the item within the same file. Use {type: 'root'}, {type: 'folder', folder: {name, parentName}}, or {type: 'before' | 'after', target}. A target is {type: 'composition', compositionId} or {type: 'folder', name, parentName}. Moving an item into its current parent is a no-op.

Return value

Returns an object with the following properties.

project

The updated project. Unchanged files and extra project fields are preserved.

changes

An array of {filePath, previousContents, nextContents} file changes. A null content value indicates a created or deleted file.

Errors

Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.

Compatibility

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

See also