@remotion/studio-server 4.0.529 → 4.0.530

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/codemods/add-composition-to-file.d.ts +7 -0
  2. package/dist/codemods/add-composition-to-file.js +63 -0
  3. package/dist/codemods/apply-codemod-to-file.js +6 -1
  4. package/dist/codemods/update-keyframes/update-keyframes.d.ts +3 -3
  5. package/dist/codemods/update-keyframes/update-keyframes.js +1 -1
  6. package/dist/codemods/update-sequence-props/update-sequence-props.js +1 -1
  7. package/dist/helpers/get-local-package-override.d.ts +5 -0
  8. package/dist/helpers/get-local-package-override.js +39 -0
  9. package/dist/helpers/resolve-composition-component.d.ts +2 -1
  10. package/dist/helpers/resolve-composition-component.js +66 -15
  11. package/dist/index.d.ts +5 -0
  12. package/dist/index.js +3 -0
  13. package/dist/preview-server/api-routes.js +32 -12
  14. package/dist/preview-server/element-install-state.js +10 -2
  15. package/dist/preview-server/routes/add-composition.d.ts +3 -0
  16. package/dist/preview-server/routes/add-composition.js +97 -0
  17. package/dist/preview-server/routes/add-folder.d.ts +3 -0
  18. package/dist/preview-server/routes/add-folder.js +107 -0
  19. package/dist/preview-server/routes/add-keyframes.d.ts +2 -2
  20. package/dist/preview-server/routes/add-keyframes.js +49 -6
  21. package/dist/preview-server/routes/can-update-sequence-props.js +27 -5
  22. package/dist/preview-server/routes/delete-composition.d.ts +3 -0
  23. package/dist/preview-server/routes/delete-composition.js +104 -0
  24. package/dist/preview-server/routes/delete-nodes.d.ts +3 -0
  25. package/dist/preview-server/routes/delete-nodes.js +142 -0
  26. package/dist/preview-server/routes/duplicate-composition.d.ts +3 -0
  27. package/dist/preview-server/routes/duplicate-composition.js +114 -0
  28. package/dist/preview-server/routes/duplicate-nodes.d.ts +3 -0
  29. package/dist/preview-server/routes/duplicate-nodes.js +123 -0
  30. package/dist/preview-server/routes/insert-basic-captions.js +2 -1
  31. package/dist/preview-server/routes/insert-composition-element.d.ts +3 -0
  32. package/dist/preview-server/routes/insert-composition-element.js +236 -0
  33. package/dist/preview-server/routes/insert-element.js +26 -19
  34. package/dist/preview-server/routes/install-dependency.js +10 -1
  35. package/dist/preview-server/routes/move-composition.d.ts +3 -0
  36. package/dist/preview-server/routes/move-composition.js +148 -0
  37. package/dist/preview-server/routes/move-folder.d.ts +3 -0
  38. package/dist/preview-server/routes/move-folder.js +151 -0
  39. package/dist/preview-server/routes/precompose-jsx-nodes.d.ts +3 -0
  40. package/dist/preview-server/routes/precompose-jsx-nodes.js +209 -0
  41. package/dist/preview-server/routes/rename-composition.d.ts +3 -0
  42. package/dist/preview-server/routes/rename-composition.js +105 -0
  43. package/dist/preview-server/routes/rename-folder.d.ts +3 -0
  44. package/dist/preview-server/routes/rename-folder.js +111 -0
  45. package/dist/preview-server/routes/reorder-sequence.js +7 -2
  46. package/dist/preview-server/routes/replace-video-source.js +7 -2
  47. package/dist/preview-server/routes/save-sequence-props.js +6 -3
  48. package/dist/preview-server/routes/split-sequences.d.ts +3 -0
  49. package/dist/preview-server/routes/split-sequences.js +122 -0
  50. package/dist/preview-server/routes/split-video-from-audio.js +6 -1
  51. package/dist/preview-server/routes/unwrap-folder.d.ts +3 -0
  52. package/dist/preview-server/routes/unwrap-folder.js +107 -0
  53. package/dist/preview-server/routes/update-composition-metadata.d.ts +3 -0
  54. package/dist/preview-server/routes/update-composition-metadata.js +110 -0
  55. package/dist/preview-server/routes/wrap-node.d.ts +3 -0
  56. package/dist/preview-server/routes/wrap-node.js +108 -0
  57. package/dist/preview-server/studio-protocol/handle-discovery.js +3 -10
  58. package/dist/preview-server/studio-protocol/handle-install.js +0 -3
  59. package/dist/preview-server/undo-stack.d.ts +1 -1
  60. package/dist/preview-server/undo-stack.js +6 -0
  61. package/dist/start-studio.js +1 -1
  62. package/package.json +8 -8
@@ -5,6 +5,7 @@ const node_child_process_1 = require("node:child_process");
5
5
  const renderer_1 = require("@remotion/renderer");
6
6
  const studio_shared_1 = require("@remotion/studio-shared");
7
7
  const version_1 = require("remotion/version");
8
+ const get_local_package_override_1 = require("../../helpers/get-local-package-override");
8
9
  const install_command_1 = require("../../helpers/install-command");
9
10
  const package_manager_spawn_options_1 = require("../../helpers/package-manager-spawn-options");
10
11
  const get_package_manager_1 = require("../get-package-manager");
@@ -53,7 +54,15 @@ const handleInstallPackage = async ({ logLevel, remotionRoot, input: { dependenc
53
54
  additionalArgs[0] = '--mode=skip-build';
54
55
  }
55
56
  }
56
- const packagesWithVersions = dependencies.map(exports.getPackageInstallSpec);
57
+ const packagesWithVersions = dependencies.map((dependency) => {
58
+ const localPackageOverride = (0, get_local_package_override_1.getLocalPackageOverride)({
59
+ remotionRoot,
60
+ packageName: dependency.name,
61
+ });
62
+ return localPackageOverride === null
63
+ ? (0, exports.getPackageInstallSpec)(dependency)
64
+ : `${dependency.name}@${localPackageOverride}`;
65
+ });
57
66
  const command = (0, install_command_1.getInstallCommand)({
58
67
  manager: manager.manager,
59
68
  packages: packagesWithVersions,
@@ -0,0 +1,3 @@
1
+ import type { CompositionEditResponse, MoveCompositionRequest } from '@remotion/studio-shared';
2
+ import type { ApiHandler } from '../api-types';
3
+ export declare const moveCompositionHandler: ApiHandler<MoveCompositionRequest, CompositionEditResponse>;
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.moveCompositionHandler = void 0;
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const codemods_1 = require("@remotion/codemods");
10
+ const renderer_1 = require("@remotion/renderer");
11
+ const file_watcher_1 = require("../../file-watcher");
12
+ const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
13
+ const format_log_file_location_1 = require("../format-log-file-location");
14
+ const project_info_1 = require("../project-info");
15
+ const sequence_node_path_mutation_1 = require("../sequence-node-path-mutation");
16
+ const undo_stack_1 = require("../undo-stack");
17
+ const can_update_default_props_1 = require("./can-update-default-props");
18
+ const source_file_write_queue_1 = require("./source-file-write-queue");
19
+ const moveCompositionHandler = ({ input: request, logLevel, remotionRoot, entryPoint }) => (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
20
+ var _a, _b;
21
+ var _c, _d;
22
+ try {
23
+ let filePath;
24
+ if ((_a = request.symbolicatedStack) === null || _a === void 0 ? void 0 : _a.originalFileName) {
25
+ filePath = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
26
+ remotionRoot,
27
+ fileName: request.symbolicatedStack.originalFileName,
28
+ action: 'move a composition in',
29
+ }).absolutePath;
30
+ }
31
+ else {
32
+ const { rootFile } = await (0, project_info_1.getProjectInfo)(remotionRoot, entryPoint);
33
+ if (rootFile === null) {
34
+ throw new Error('Cannot find the Remotion root file');
35
+ }
36
+ filePath = rootFile;
37
+ }
38
+ (0, can_update_default_props_1.checkIfTypeScriptFile)(filePath);
39
+ const destination = request.destination.type === 'folder'
40
+ ? {
41
+ type: 'folder',
42
+ folder: {
43
+ name: request.destination.folderName,
44
+ parentName: request.destination.parentName,
45
+ },
46
+ }
47
+ : request.destination.type === 'root'
48
+ ? request.destination
49
+ : {
50
+ type: request.destination.type,
51
+ target: request.destination.target.type === 'composition'
52
+ ? request.destination.target
53
+ : {
54
+ type: 'folder',
55
+ name: request.destination.target.folderName,
56
+ parentName: request.destination.target.parentName,
57
+ },
58
+ };
59
+ const result = (0, codemods_1.moveComposition)({
60
+ project: {
61
+ files: { [filePath]: (0, node_fs_1.readFileSync)(filePath, 'utf-8') },
62
+ rootDir: node_path_1.default.dirname(filePath),
63
+ },
64
+ compositionFile: filePath,
65
+ compositionId: request.compositionId,
66
+ destination,
67
+ });
68
+ for (const change of result.changes) {
69
+ const currentContents = (0, node_fs_1.existsSync)(change.filePath)
70
+ ? (0, node_fs_1.readFileSync)(change.filePath, 'utf-8')
71
+ : null;
72
+ if (currentContents !== change.previousContents) {
73
+ throw new Error(`Source changed before moving composition: ${change.filePath}`);
74
+ }
75
+ }
76
+ const mutationFiles = [
77
+ ...new Set(result.nodePathRemappings.map((remapping) => remapping.filePath)),
78
+ ].map((absolutePath) => ({
79
+ absolutePath,
80
+ remappings: result.nodePathRemappings
81
+ .filter((remapping) => remapping.filePath === absolutePath)
82
+ .map(({ oldNodePath, newNodePath, oldJsxName, newJsxName }) => ({
83
+ oldNodePath,
84
+ newNodePath,
85
+ oldJsxName,
86
+ newJsxName,
87
+ })),
88
+ }));
89
+ const nodePathMutation = mutationFiles.length === 0
90
+ ? null
91
+ : (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)(mutationFiles, null);
92
+ if (result.changes.length > 0) {
93
+ const logLine = (_c = (_b = request.symbolicatedStack) === null || _b === void 0 ? void 0 : _b.originalLineNumber) !== null && _c !== void 0 ? _c : 1;
94
+ (0, undo_stack_1.pushTransactionToUndoStack)({
95
+ snapshots: result.changes.map((change) => {
96
+ var _a;
97
+ var _b;
98
+ return ({
99
+ filePath: change.filePath,
100
+ oldContents: change.previousContents,
101
+ newContents: change.nextContents,
102
+ logLine: change.filePath === filePath ? logLine : 1,
103
+ nodePathRemappings: (_b = (_a = mutationFiles.find((mutation) => mutation.absolutePath === change.filePath)) === null || _a === void 0 ? void 0 : _a.remappings) !== null && _b !== void 0 ? _b : null,
104
+ });
105
+ }),
106
+ logLevel,
107
+ remotionRoot,
108
+ description: {
109
+ undoMessage: `↩️ Move of composition "${request.compositionId}"`,
110
+ redoMessage: `↪️ Move of composition "${request.compositionId}"`,
111
+ },
112
+ entryType: 'move-composition-or-folder',
113
+ suppressHmrOnFileRestore: false,
114
+ undoRedoNavigation: request.undoRedoNavigation,
115
+ });
116
+ for (const change of result.changes) {
117
+ if (change.nextContents === null) {
118
+ throw new Error('Moving a composition cannot remove source files');
119
+ }
120
+ (0, undo_stack_1.suppressUndoStackInvalidation)(change.filePath);
121
+ (0, file_watcher_1.writeFileAndNotifyFileWatchers)({
122
+ file: change.filePath,
123
+ content: change.nextContents,
124
+ originatorClientId: undefined,
125
+ metadata: mutationFiles.some((mutation) => mutation.absolutePath === change.filePath)
126
+ ? { skipSequencePropsUpdate: true }
127
+ : null,
128
+ });
129
+ }
130
+ const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
131
+ remotionRoot,
132
+ absolutePath: filePath,
133
+ line: logLine,
134
+ });
135
+ renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(locationLabel)} Moved composition "${request.compositionId}"`);
136
+ (0, undo_stack_1.printUndoHint)(logLevel);
137
+ }
138
+ return { success: true, nodePathMutation };
139
+ }
140
+ catch (error) {
141
+ return {
142
+ success: false,
143
+ reason: error instanceof Error ? error.message : String(error),
144
+ stack: error instanceof Error ? ((_d = error.stack) !== null && _d !== void 0 ? _d : '') : '',
145
+ };
146
+ }
147
+ });
148
+ exports.moveCompositionHandler = moveCompositionHandler;
@@ -0,0 +1,3 @@
1
+ import type { CompositionEditResponse, MoveFolderRequest } from '@remotion/studio-shared';
2
+ import type { ApiHandler } from '../api-types';
3
+ export declare const moveFolderHandler: ApiHandler<MoveFolderRequest, CompositionEditResponse>;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.moveFolderHandler = void 0;
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const codemods_1 = require("@remotion/codemods");
10
+ const renderer_1 = require("@remotion/renderer");
11
+ const file_watcher_1 = require("../../file-watcher");
12
+ const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
13
+ const format_log_file_location_1 = require("../format-log-file-location");
14
+ const project_info_1 = require("../project-info");
15
+ const sequence_node_path_mutation_1 = require("../sequence-node-path-mutation");
16
+ const undo_stack_1 = require("../undo-stack");
17
+ const can_update_default_props_1 = require("./can-update-default-props");
18
+ const source_file_write_queue_1 = require("./source-file-write-queue");
19
+ const moveFolderHandler = ({ input: request, logLevel, remotionRoot, entryPoint }) => (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
20
+ var _a, _b;
21
+ var _c, _d;
22
+ try {
23
+ let filePath;
24
+ if ((_a = request.symbolicatedStack) === null || _a === void 0 ? void 0 : _a.originalFileName) {
25
+ filePath = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
26
+ remotionRoot,
27
+ fileName: request.symbolicatedStack.originalFileName,
28
+ action: 'move a folder in',
29
+ }).absolutePath;
30
+ }
31
+ else {
32
+ const { rootFile } = await (0, project_info_1.getProjectInfo)(remotionRoot, entryPoint);
33
+ if (rootFile === null) {
34
+ throw new Error('Cannot find the Remotion root file');
35
+ }
36
+ filePath = rootFile;
37
+ }
38
+ (0, can_update_default_props_1.checkIfTypeScriptFile)(filePath);
39
+ const destination = request.destination.type === 'folder'
40
+ ? {
41
+ type: 'folder',
42
+ folder: {
43
+ name: request.destination.folderName,
44
+ parentName: request.destination.parentName,
45
+ },
46
+ }
47
+ : request.destination.type === 'root'
48
+ ? request.destination
49
+ : {
50
+ type: request.destination.type,
51
+ target: request.destination.target.type === 'composition'
52
+ ? request.destination.target
53
+ : {
54
+ type: 'folder',
55
+ name: request.destination.target.folderName,
56
+ parentName: request.destination.target.parentName,
57
+ },
58
+ };
59
+ const result = (0, codemods_1.moveFolder)({
60
+ project: {
61
+ files: { [filePath]: (0, node_fs_1.readFileSync)(filePath, 'utf-8') },
62
+ rootDir: node_path_1.default.dirname(filePath),
63
+ },
64
+ compositionFile: filePath,
65
+ folder: { name: request.folderName, parentName: request.parentName },
66
+ destination,
67
+ });
68
+ for (const change of result.changes) {
69
+ const currentContents = (0, node_fs_1.existsSync)(change.filePath)
70
+ ? (0, node_fs_1.readFileSync)(change.filePath, 'utf-8')
71
+ : null;
72
+ if (currentContents !== change.previousContents) {
73
+ throw new Error(`Source changed before moving folder: ${change.filePath}`);
74
+ }
75
+ }
76
+ const mutationFiles = [
77
+ ...new Set(result.nodePathRemappings.map((remapping) => remapping.filePath)),
78
+ ].map((absolutePath) => ({
79
+ absolutePath,
80
+ remappings: result.nodePathRemappings
81
+ .filter((remapping) => remapping.filePath === absolutePath)
82
+ .map(({ oldNodePath, newNodePath, oldJsxName, newJsxName }) => ({
83
+ oldNodePath,
84
+ newNodePath,
85
+ oldJsxName,
86
+ newJsxName,
87
+ })),
88
+ }));
89
+ const nodePathMutation = mutationFiles.length === 0
90
+ ? null
91
+ : (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)(mutationFiles, null);
92
+ if (result.changes.length > 0) {
93
+ const logLine = (_c = (_b = request.symbolicatedStack) === null || _b === void 0 ? void 0 : _b.originalLineNumber) !== null && _c !== void 0 ? _c : 1;
94
+ const folderPath = request.parentName
95
+ ? `${request.parentName}/${request.folderName}`
96
+ : request.folderName;
97
+ (0, undo_stack_1.pushTransactionToUndoStack)({
98
+ snapshots: result.changes.map((change) => {
99
+ var _a;
100
+ var _b;
101
+ return ({
102
+ filePath: change.filePath,
103
+ oldContents: change.previousContents,
104
+ newContents: change.nextContents,
105
+ logLine: change.filePath === filePath ? logLine : 1,
106
+ nodePathRemappings: (_b = (_a = mutationFiles.find((mutation) => mutation.absolutePath === change.filePath)) === null || _a === void 0 ? void 0 : _a.remappings) !== null && _b !== void 0 ? _b : null,
107
+ });
108
+ }),
109
+ logLevel,
110
+ remotionRoot,
111
+ description: {
112
+ undoMessage: `↩️ Move of folder "${folderPath}"`,
113
+ redoMessage: `↪️ Move of folder "${folderPath}"`,
114
+ },
115
+ entryType: 'move-composition-or-folder',
116
+ suppressHmrOnFileRestore: false,
117
+ undoRedoNavigation: request.undoRedoNavigation,
118
+ });
119
+ for (const change of result.changes) {
120
+ if (change.nextContents === null) {
121
+ throw new Error('Moving a folder cannot remove source files');
122
+ }
123
+ (0, undo_stack_1.suppressUndoStackInvalidation)(change.filePath);
124
+ (0, file_watcher_1.writeFileAndNotifyFileWatchers)({
125
+ file: change.filePath,
126
+ content: change.nextContents,
127
+ originatorClientId: undefined,
128
+ metadata: mutationFiles.some((mutation) => mutation.absolutePath === change.filePath)
129
+ ? { skipSequencePropsUpdate: true }
130
+ : null,
131
+ });
132
+ }
133
+ const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
134
+ remotionRoot,
135
+ absolutePath: filePath,
136
+ line: logLine,
137
+ });
138
+ renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(locationLabel)} Moved folder "${folderPath}"`);
139
+ (0, undo_stack_1.printUndoHint)(logLevel);
140
+ }
141
+ return { success: true, nodePathMutation };
142
+ }
143
+ catch (error) {
144
+ return {
145
+ success: false,
146
+ reason: error instanceof Error ? error.message : String(error),
147
+ stack: error instanceof Error ? ((_d = error.stack) !== null && _d !== void 0 ? _d : '') : '',
148
+ };
149
+ }
150
+ });
151
+ exports.moveFolderHandler = moveFolderHandler;
@@ -0,0 +1,3 @@
1
+ import type { PrecomposeJsxNodesRequest, PrecomposeJsxNodesResponse } from '@remotion/studio-shared';
2
+ import type { ApiHandler } from '../api-types';
3
+ export declare const precomposeJsxNodesHandler: ApiHandler<PrecomposeJsxNodesRequest, PrecomposeJsxNodesResponse>;
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.precomposeJsxNodesHandler = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const codemods_1 = require("@remotion/codemods");
6
+ const renderer_1 = require("@remotion/renderer");
7
+ const file_watcher_1 = require("../../file-watcher");
8
+ const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
9
+ const format_log_file_location_1 = require("../format-log-file-location");
10
+ const sequence_node_path_mutation_1 = require("../sequence-node-path-mutation");
11
+ const undo_stack_1 = require("../undo-stack");
12
+ const source_file_write_queue_1 = require("./source-file-write-queue");
13
+ const precomposeJsxNodesHandler = ({ input: { nodes, dryRun, compositionFile, compositionId, metadata, existingCompositionIds, }, remotionRoot, logLevel, }) => (0, source_file_write_queue_1.withSourceFileWriteQueue)(() => {
14
+ var _a;
15
+ const attemptedWrites = [];
16
+ let undoEntryPushed = false;
17
+ try {
18
+ if (nodes.length === 0) {
19
+ throw new Error('No JSX sequences were selected');
20
+ }
21
+ const resolved = nodes.map(({ fileName, nodePath }) => ({
22
+ ...(0, resolve_file_inside_project_1.resolveFileInsideProject)({
23
+ remotionRoot,
24
+ fileName,
25
+ action: 'modify',
26
+ }),
27
+ nodePath,
28
+ }));
29
+ const { absolutePath } = resolved[0];
30
+ if (resolved.some((node) => node.absolutePath !== absolutePath)) {
31
+ throw new Error('Selected sequences must be in the same source file');
32
+ }
33
+ const registration = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
34
+ remotionRoot,
35
+ fileName: compositionFile,
36
+ action: 'modify',
37
+ });
38
+ const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
39
+ const registrationContents = registration.absolutePath === absolutePath
40
+ ? fileContents
41
+ : (0, node_fs_1.readFileSync)(registration.absolutePath, 'utf-8');
42
+ const files = {
43
+ [absolutePath]: fileContents,
44
+ [registration.absolutePath]: registrationContents,
45
+ };
46
+ const project = { files, rootDir: remotionRoot };
47
+ const codemodInput = {
48
+ project,
49
+ nodes: resolved.map(({ nodePath }) => ({
50
+ filePath: absolutePath,
51
+ nodePath,
52
+ })),
53
+ compositionFile: registration.absolutePath,
54
+ compositionId,
55
+ metadata,
56
+ existingCompositionIds,
57
+ };
58
+ if (dryRun) {
59
+ const eligibility = (0, codemods_1.canPrecomposeJsxNodes)(codemodInput);
60
+ return Promise.resolve({
61
+ success: true,
62
+ ...eligibility,
63
+ nodePathMutation: null,
64
+ newCompositionId: null,
65
+ });
66
+ }
67
+ let result;
68
+ try {
69
+ result = (0, codemods_1.precomposeJsxNodes)(codemodInput);
70
+ }
71
+ catch (error) {
72
+ return Promise.resolve({
73
+ success: true,
74
+ canPrecompose: false,
75
+ reason: error instanceof Error ? error.message : String(error),
76
+ nodePathMutation: null,
77
+ newCompositionId: null,
78
+ });
79
+ }
80
+ const changes = [...result.changes].sort((a, b) => Number(b.filePath === absolutePath) -
81
+ Number(a.filePath === absolutePath));
82
+ if (!changes.some(({ filePath }) => filePath === absolutePath) ||
83
+ !changes.some(({ filePath }) => filePath === registration.absolutePath)) {
84
+ throw new Error('Could not pre-compose selected sequences');
85
+ }
86
+ for (const change of changes) {
87
+ if (!Object.hasOwn(files, change.filePath) ||
88
+ change.previousContents !== files[change.filePath] ||
89
+ change.nextContents === null ||
90
+ (0, node_fs_1.readFileSync)(change.filePath, 'utf-8') !== change.previousContents) {
91
+ throw new Error('Source changed before applying pre-compose');
92
+ }
93
+ }
94
+ const remappingsByFile = changes.map(({ filePath }) => ({
95
+ absolutePath: filePath,
96
+ remappings: result.nodePathRemappings
97
+ .filter((remapping) => remapping.filePath === filePath)
98
+ .map(({ oldNodePath, newNodePath, oldJsxName, newJsxName }) => ({
99
+ oldNodePath,
100
+ newNodePath,
101
+ oldJsxName,
102
+ newJsxName,
103
+ })),
104
+ }));
105
+ const mutationFiles = remappingsByFile.filter(({ remappings }) => remappings.length > 0);
106
+ (0, undo_stack_1.pushTransactionToUndoStack)({
107
+ snapshots: changes.map((change) => {
108
+ var _a;
109
+ const remappings = (_a = remappingsByFile.find(({ absolutePath: filePath }) => filePath === change.filePath)) === null || _a === void 0 ? void 0 : _a.remappings;
110
+ return {
111
+ filePath: change.filePath,
112
+ oldContents: change.previousContents,
113
+ newContents: change.nextContents,
114
+ logLine: change.filePath === absolutePath ? result.logLine : 1,
115
+ nodePathRemappings: remappings && remappings.length > 0 ? remappings : null,
116
+ };
117
+ }),
118
+ logLevel,
119
+ remotionRoot,
120
+ description: {
121
+ undoMessage: '↩️ Pre-compose sequences',
122
+ redoMessage: '↪️ Pre-compose sequences',
123
+ },
124
+ entryType: 'precompose-jsx-nodes',
125
+ suppressHmrOnFileRestore: false,
126
+ undoRedoNavigation: {
127
+ undoRoute: `/${compositionId}`,
128
+ redoRoute: `/${result.newCompositionId}`,
129
+ },
130
+ });
131
+ undoEntryPushed = true;
132
+ for (const change of changes) {
133
+ const { nextContents: output, previousContents } = change;
134
+ if (output === null || previousContents === null) {
135
+ throw new Error('Could not write a pre-composed source file');
136
+ }
137
+ const skipSequencePropsUpdate = remappingsByFile.some(({ absolutePath: filePath, remappings }) => filePath === change.filePath && remappings.length > 0);
138
+ attemptedWrites.push({
139
+ filePath: change.filePath,
140
+ previousContents,
141
+ nextContents: output,
142
+ skipSequencePropsUpdate,
143
+ });
144
+ (0, undo_stack_1.suppressUndoStackInvalidation)(change.filePath);
145
+ (0, file_watcher_1.writeFileAndNotifyFileWatchers)({
146
+ file: change.filePath,
147
+ content: output,
148
+ originatorClientId: undefined,
149
+ metadata: skipSequencePropsUpdate
150
+ ? { skipSequencePropsUpdate: true }
151
+ : null,
152
+ });
153
+ }
154
+ const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
155
+ remotionRoot,
156
+ absolutePath,
157
+ line: result.logLine,
158
+ });
159
+ renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(locationLabel)} Pre-composed ${nodes.length} sequence${nodes.length === 1 ? '' : 's'}`);
160
+ for (const change of changes) {
161
+ renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `[precompose-jsx-nodes] Wrote ${(0, resolve_file_inside_project_1.resolveFileInsideProject)({
162
+ remotionRoot,
163
+ fileName: change.filePath,
164
+ action: 'modify',
165
+ }).fileRelativeToRoot}`);
166
+ }
167
+ (0, undo_stack_1.printUndoHint)(logLevel);
168
+ const nodePathMutation = mutationFiles.length === 0
169
+ ? null
170
+ : (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)(mutationFiles, null);
171
+ return Promise.resolve({
172
+ success: true,
173
+ canPrecompose: true,
174
+ reason: null,
175
+ nodePathMutation,
176
+ newCompositionId: result.newCompositionId,
177
+ });
178
+ }
179
+ catch (err) {
180
+ for (const change of attemptedWrites.reverse()) {
181
+ try {
182
+ if ((0, node_fs_1.readFileSync)(change.filePath, 'utf-8') !== change.nextContents) {
183
+ continue;
184
+ }
185
+ (0, undo_stack_1.suppressUndoStackInvalidation)(change.filePath);
186
+ (0, file_watcher_1.writeFileAndNotifyFileWatchers)({
187
+ file: change.filePath,
188
+ content: change.previousContents,
189
+ originatorClientId: undefined,
190
+ metadata: change.skipSequencePropsUpdate
191
+ ? { skipSequencePropsUpdate: true }
192
+ : null,
193
+ });
194
+ }
195
+ catch (_b) {
196
+ // Preserve subsequent edits and the original pre-compose error.
197
+ }
198
+ }
199
+ if (undoEntryPushed) {
200
+ (0, undo_stack_1.discardLastUndoEntryAfterFailedCommit)();
201
+ }
202
+ return Promise.resolve({
203
+ success: false,
204
+ reason: err.message,
205
+ stack: (_a = err.stack) !== null && _a !== void 0 ? _a : '',
206
+ });
207
+ }
208
+ });
209
+ exports.precomposeJsxNodesHandler = precomposeJsxNodesHandler;
@@ -0,0 +1,3 @@
1
+ import type { CompositionEditResponse, RenameCompositionRequest } from '@remotion/studio-shared';
2
+ import type { ApiHandler } from '../api-types';
3
+ export declare const renameCompositionHandler: ApiHandler<RenameCompositionRequest, CompositionEditResponse>;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.renameCompositionHandler = void 0;
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const codemods_1 = require("@remotion/codemods");
10
+ const renderer_1 = require("@remotion/renderer");
11
+ const file_watcher_1 = require("../../file-watcher");
12
+ const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
13
+ const format_log_file_location_1 = require("../format-log-file-location");
14
+ const project_info_1 = require("../project-info");
15
+ const undo_stack_1 = require("../undo-stack");
16
+ const can_update_default_props_1 = require("./can-update-default-props");
17
+ const source_file_write_queue_1 = require("./source-file-write-queue");
18
+ const renameCompositionHandler = ({ input: request, logLevel, remotionRoot, entryPoint }) => (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
19
+ var _a, _b;
20
+ var _c, _d;
21
+ try {
22
+ let filePath;
23
+ if ((_a = request.symbolicatedStack) === null || _a === void 0 ? void 0 : _a.originalFileName) {
24
+ filePath = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
25
+ remotionRoot,
26
+ fileName: request.symbolicatedStack.originalFileName,
27
+ action: 'rename a composition in',
28
+ }).absolutePath;
29
+ }
30
+ else {
31
+ const { rootFile } = await (0, project_info_1.getProjectInfo)(remotionRoot, entryPoint);
32
+ if (rootFile === null) {
33
+ throw new Error('Cannot find the Remotion root file');
34
+ }
35
+ filePath = rootFile;
36
+ }
37
+ (0, can_update_default_props_1.checkIfTypeScriptFile)(filePath);
38
+ const result = (0, codemods_1.renameComposition)({
39
+ project: {
40
+ files: { [filePath]: (0, node_fs_1.readFileSync)(filePath, 'utf-8') },
41
+ rootDir: node_path_1.default.dirname(filePath),
42
+ },
43
+ compositionFile: filePath,
44
+ compositionId: request.idToRename,
45
+ newId: request.newId,
46
+ });
47
+ for (const change of result.changes) {
48
+ const currentContents = (0, node_fs_1.existsSync)(change.filePath)
49
+ ? (0, node_fs_1.readFileSync)(change.filePath, 'utf-8')
50
+ : null;
51
+ if (currentContents !== change.previousContents) {
52
+ throw new Error(`Source changed before renaming composition: ${change.filePath}`);
53
+ }
54
+ }
55
+ if (result.changes.length > 0) {
56
+ const logLine = (_c = (_b = request.symbolicatedStack) === null || _b === void 0 ? void 0 : _b.originalLineNumber) !== null && _c !== void 0 ? _c : 1;
57
+ (0, undo_stack_1.pushTransactionToUndoStack)({
58
+ snapshots: result.changes.map((change) => ({
59
+ filePath: change.filePath,
60
+ oldContents: change.previousContents,
61
+ newContents: change.nextContents,
62
+ logLine: change.filePath === filePath ? logLine : 1,
63
+ nodePathRemappings: null,
64
+ })),
65
+ logLevel,
66
+ remotionRoot,
67
+ description: {
68
+ undoMessage: `↩️ Rename of composition "${request.idToRename}" to "${request.newId}"`,
69
+ redoMessage: `↪️ Rename of composition "${request.idToRename}" to "${request.newId}"`,
70
+ },
71
+ entryType: 'rename-composition',
72
+ suppressHmrOnFileRestore: false,
73
+ undoRedoNavigation: request.undoRedoNavigation,
74
+ });
75
+ for (const change of result.changes) {
76
+ if (change.nextContents === null) {
77
+ throw new Error('Renaming a composition cannot remove source files');
78
+ }
79
+ (0, undo_stack_1.suppressUndoStackInvalidation)(change.filePath);
80
+ (0, file_watcher_1.writeFileAndNotifyFileWatchers)({
81
+ file: change.filePath,
82
+ content: change.nextContents,
83
+ originatorClientId: undefined,
84
+ metadata: null,
85
+ });
86
+ }
87
+ const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
88
+ remotionRoot,
89
+ absolutePath: filePath,
90
+ line: logLine,
91
+ });
92
+ renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(locationLabel)} Renamed composition "${request.idToRename}" to "${request.newId}"`);
93
+ (0, undo_stack_1.printUndoHint)(logLevel);
94
+ }
95
+ return { success: true, nodePathMutation: null };
96
+ }
97
+ catch (error) {
98
+ return {
99
+ success: false,
100
+ reason: error instanceof Error ? error.message : String(error),
101
+ stack: error instanceof Error ? ((_d = error.stack) !== null && _d !== void 0 ? _d : '') : '',
102
+ };
103
+ }
104
+ });
105
+ exports.renameCompositionHandler = renameCompositionHandler;
@@ -0,0 +1,3 @@
1
+ import type { CompositionEditResponse, RenameFolderRequest } from '@remotion/studio-shared';
2
+ import type { ApiHandler } from '../api-types';
3
+ export declare const renameFolderHandler: ApiHandler<RenameFolderRequest, CompositionEditResponse>;