@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
@@ -0,0 +1,111 @@
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.renameFolderHandler = 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 renameFolderHandler = ({ 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 folder 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.renameFolder)({
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
+ folder: { name: request.folderName, parentName: request.parentName },
45
+ newName: request.newName,
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 folder: ${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
+ const oldPath = request.parentName
58
+ ? `${request.parentName}/${request.folderName}`
59
+ : request.folderName;
60
+ const newPath = request.parentName
61
+ ? `${request.parentName}/${request.newName}`
62
+ : request.newName;
63
+ (0, undo_stack_1.pushTransactionToUndoStack)({
64
+ snapshots: result.changes.map((change) => ({
65
+ filePath: change.filePath,
66
+ oldContents: change.previousContents,
67
+ newContents: change.nextContents,
68
+ logLine: change.filePath === filePath ? logLine : 1,
69
+ nodePathRemappings: null,
70
+ })),
71
+ logLevel,
72
+ remotionRoot,
73
+ description: {
74
+ undoMessage: `↩️ Rename of folder "${oldPath}" to "${newPath}"`,
75
+ redoMessage: `↪️ Rename of folder "${oldPath}" to "${newPath}"`,
76
+ },
77
+ entryType: 'rename-folder',
78
+ suppressHmrOnFileRestore: false,
79
+ undoRedoNavigation: request.undoRedoNavigation,
80
+ });
81
+ for (const change of result.changes) {
82
+ if (change.nextContents === null) {
83
+ throw new Error('Renaming a folder cannot remove source files');
84
+ }
85
+ (0, undo_stack_1.suppressUndoStackInvalidation)(change.filePath);
86
+ (0, file_watcher_1.writeFileAndNotifyFileWatchers)({
87
+ file: change.filePath,
88
+ content: change.nextContents,
89
+ originatorClientId: undefined,
90
+ metadata: null,
91
+ });
92
+ }
93
+ const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
94
+ remotionRoot,
95
+ absolutePath: filePath,
96
+ line: logLine,
97
+ });
98
+ renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(locationLabel)} Renamed folder "${oldPath}"`);
99
+ (0, undo_stack_1.printUndoHint)(logLevel);
100
+ }
101
+ return { success: true, nodePathMutation: null };
102
+ }
103
+ catch (error) {
104
+ return {
105
+ success: false,
106
+ reason: error instanceof Error ? error.message : String(error),
107
+ stack: error instanceof Error ? ((_d = error.stack) !== null && _d !== void 0 ? _d : '') : '',
108
+ };
109
+ }
110
+ });
111
+ exports.renameFolderHandler = renameFolderHandler;
@@ -23,7 +23,7 @@ const reorderSequenceHandler = ({ input: { fileName, sourceNodePath, targetNodeP
23
23
  action: 'modify',
24
24
  });
25
25
  const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
26
- const result = await (0, codemods_1.reorderJsxNode)({
26
+ const result = await (0, codemods_1.reorderNode)({
27
27
  project: { files: { [absolutePath]: fileContents }, rootDir: remotionRoot },
28
28
  node: { filePath: absolutePath, nodePath: sourceNodePath.nodePath },
29
29
  target: { filePath: absolutePath, nodePath: targetNodePath.nodePath },
@@ -31,7 +31,12 @@ const reorderSequenceHandler = ({ input: { fileName, sourceNodePath, targetNodeP
31
31
  });
32
32
  const output = (_b = (_a = result.changes[0]) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _b !== void 0 ? _b : fileContents;
33
33
  const { sequenceLabel, logLine } = result.editDetails[0];
34
- const nodePathRemappings = result.nodePathRemappings.map(({ oldNodePath, newNodePath }) => ({ oldNodePath, newNodePath }));
34
+ const nodePathRemappings = result.nodePathRemappings.map(({ oldNodePath, newNodePath, oldJsxName, newJsxName }) => ({
35
+ oldNodePath,
36
+ newNodePath,
37
+ oldJsxName,
38
+ newJsxName,
39
+ }));
35
40
  const nodePathMutation = (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)([
36
41
  {
37
42
  absolutePath,
@@ -21,7 +21,7 @@ const replaceVideoSourceHandler = ({ input: { fileName, nodePath, src }, remotio
21
21
  action: 'modify',
22
22
  });
23
23
  const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
24
- const result = (0, codemods_1.updateJsxNodeProps)({
24
+ const result = (0, codemods_1.updateNodeProps)({
25
25
  project: {
26
26
  files: { [absolutePath]: fileContents },
27
27
  rootDir: remotionRoot,
@@ -37,7 +37,12 @@ const replaceVideoSourceHandler = ({ input: { fileName, nodePath, src }, remotio
37
37
  });
38
38
  const output = (_b = (_a = result.changes[0]) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _b !== void 0 ? _b : fileContents;
39
39
  const { logLine } = result;
40
- const nodePathRemappings = result.nodePathRemappings.map(({ oldNodePath, newNodePath }) => ({ oldNodePath, newNodePath }));
40
+ const nodePathRemappings = result.nodePathRemappings.map(({ oldNodePath, newNodePath, oldJsxName, newJsxName }) => ({
41
+ oldNodePath,
42
+ newNodePath,
43
+ oldJsxName,
44
+ newJsxName,
45
+ }));
41
46
  const nodePathMutation = (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)([{ absolutePath, remappings: nodePathRemappings }], null);
42
47
  (0, undo_stack_1.pushToUndoStack)({
43
48
  filePath: absolutePath,
@@ -49,7 +49,7 @@ const groupBy = (items, getKey) => {
49
49
  return [...groups.values()];
50
50
  };
51
51
  const convertSequencePropEditToCodemodChange = (edit) => {
52
- var _a, _b;
52
+ var _a, _b, _c;
53
53
  return {
54
54
  nodePath: edit.nodePath.nodePath,
55
55
  updates: [
@@ -57,8 +57,11 @@ const convertSequencePropEditToCodemodChange = (edit) => {
57
57
  key: edit.key,
58
58
  value: edit.value,
59
59
  defaultValue: edit.defaultValue,
60
- googleFont: ((_a = edit.sourceEdit) === null || _a === void 0 ? void 0 : _a.type) === 'google-font' ? edit.sourceEdit.font : null,
61
- clipboardParam: ((_b = edit.sourceEdit) === null || _b === void 0 ? void 0 : _b.type) === 'clipboard-param'
60
+ ...(((_a = edit.sourceEdit) === null || _a === void 0 ? void 0 : _a.type) === 'playback-rate'
61
+ ? { retimeKeyframes: true }
62
+ : {}),
63
+ googleFont: ((_b = edit.sourceEdit) === null || _b === void 0 ? void 0 : _b.type) === 'google-font' ? edit.sourceEdit.font : null,
64
+ clipboardParam: ((_c = edit.sourceEdit) === null || _c === void 0 ? void 0 : _c.type) === 'clipboard-param'
62
65
  ? edit.sourceEdit.param
63
66
  : null,
64
67
  },
@@ -0,0 +1,3 @@
1
+ import type { SplitSequencesRequest, SplitSequencesResponse } from '@remotion/studio-shared';
2
+ import type { ApiHandler } from '../api-types';
3
+ export declare const splitSequencesHandler: ApiHandler<SplitSequencesRequest, SplitSequencesResponse>;
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitSequencesHandler = 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 splitSequencesHandler = ({ input: { sequences }, remotionRoot, logLevel }) => (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
14
+ var _a;
15
+ try {
16
+ if (sequences.length === 0) {
17
+ throw new Error('No JSX sequences were specified for splitting');
18
+ }
19
+ renderer_1.RenderInternals.Log.trace({ indent: false, logLevel }, `[split-sequences] Received request to split ${sequences.length} JSX sequence${sequences.length === 1 ? '' : 's'}`);
20
+ const sequencesByFileName = new Map();
21
+ for (const sequence of sequences) {
22
+ const fileSequences = (_a = sequencesByFileName.get(sequence.fileName)) !== null && _a !== void 0 ? _a : [];
23
+ fileSequences.push(sequence);
24
+ sequencesByFileName.set(sequence.fileName, fileSequences);
25
+ }
26
+ const updates = await Promise.all([...sequencesByFileName].map(async ([fileName, fileSequences]) => {
27
+ var _a;
28
+ var _b;
29
+ const { absolutePath, fileRelativeToRoot } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
30
+ remotionRoot,
31
+ fileName,
32
+ action: 'modify',
33
+ });
34
+ const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
35
+ const result = await (0, codemods_1.splitSequences)({
36
+ project: {
37
+ files: { [absolutePath]: fileContents },
38
+ rootDir: remotionRoot,
39
+ },
40
+ splits: fileSequences.map(({ nodePath, sequenceKeys, splitFrame }) => ({
41
+ node: { filePath: absolutePath, nodePath },
42
+ sequenceKeys,
43
+ frame: splitFrame,
44
+ })),
45
+ });
46
+ const output = (_b = (_a = result.changes[0]) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _b !== void 0 ? _b : fileContents;
47
+ const { nodeLabels, logLines } = result.editDetails[0];
48
+ const nodePathRemappings = result.nodePathRemappings.map(({ oldNodePath, newNodePath, oldJsxName, newJsxName }) => ({
49
+ oldNodePath,
50
+ newNodePath,
51
+ oldJsxName,
52
+ newJsxName,
53
+ }));
54
+ return {
55
+ absolutePath,
56
+ fileContents,
57
+ fileRelativeToRoot,
58
+ logLine: Math.min(...logLines),
59
+ nodeLabels,
60
+ nodePathRemappings,
61
+ output,
62
+ };
63
+ }));
64
+ const nodePathMutation = (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)(updates.map((update) => ({
65
+ absolutePath: update.absolutePath,
66
+ remappings: update.nodePathRemappings,
67
+ })), null);
68
+ const splitDescription = sequences.length === 1
69
+ ? updates[0].nodeLabels[0]
70
+ : `${sequences.length} JSX sequences`;
71
+ (0, undo_stack_1.pushTransactionToUndoStack)({
72
+ snapshots: updates.map((update) => ({
73
+ filePath: update.absolutePath,
74
+ oldContents: update.fileContents,
75
+ newContents: null,
76
+ logLine: update.logLine,
77
+ nodePathRemappings: update.nodePathRemappings,
78
+ })),
79
+ logLevel,
80
+ remotionRoot,
81
+ description: {
82
+ undoMessage: `↩️ Split of ${splitDescription}`,
83
+ redoMessage: `↪️ Split of ${splitDescription}`,
84
+ },
85
+ entryType: 'split-sequences',
86
+ suppressHmrOnFileRestore: false,
87
+ undoRedoNavigation: null,
88
+ });
89
+ for (const update of updates) {
90
+ (0, undo_stack_1.suppressUndoStackInvalidation)(update.absolutePath);
91
+ (0, file_watcher_1.writeFileAndNotifyFileWatchers)({
92
+ file: update.absolutePath,
93
+ content: update.output,
94
+ originatorClientId: undefined,
95
+ metadata: { skipSequencePropsUpdate: true },
96
+ });
97
+ const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
98
+ remotionRoot,
99
+ absolutePath: update.absolutePath,
100
+ line: update.logLine,
101
+ });
102
+ const fileDescription = update.nodeLabels.length === 1
103
+ ? update.nodeLabels[0]
104
+ : `${update.nodeLabels.length} JSX sequences`;
105
+ renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(`${locationLabel}`)} Split ${fileDescription}`);
106
+ renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `[split-sequences] Wrote ${update.fileRelativeToRoot}`);
107
+ }
108
+ (0, undo_stack_1.printUndoHint)(logLevel);
109
+ return {
110
+ success: true,
111
+ nodePathMutation,
112
+ };
113
+ }
114
+ catch (err) {
115
+ return {
116
+ success: false,
117
+ reason: err.message,
118
+ stack: err.stack,
119
+ };
120
+ }
121
+ });
122
+ exports.splitSequencesHandler = splitSequencesHandler;
@@ -28,7 +28,12 @@ const splitVideoFromAudioHandler = ({ input: { fileName, nodePath }, remotionRoo
28
28
  });
29
29
  const output = (_b = (_a = result.changes[0]) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _b !== void 0 ? _b : fileContents;
30
30
  const { formatted, nodeLabel, logLine } = result.editDetails[0];
31
- const nodePathRemappings = result.nodePathRemappings.map(({ oldNodePath, newNodePath }) => ({ oldNodePath, newNodePath }));
31
+ const nodePathRemappings = result.nodePathRemappings.map(({ oldNodePath, newNodePath, oldJsxName, newJsxName }) => ({
32
+ oldNodePath,
33
+ newNodePath,
34
+ oldJsxName,
35
+ newJsxName,
36
+ }));
32
37
  const nodePathMutation = (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)([
33
38
  {
34
39
  absolutePath,
@@ -0,0 +1,3 @@
1
+ import type { CompositionEditResponse, UnwrapFolderRequest } from '@remotion/studio-shared';
2
+ import type { ApiHandler } from '../api-types';
3
+ export declare const unwrapFolderHandler: ApiHandler<UnwrapFolderRequest, CompositionEditResponse>;
@@ -0,0 +1,107 @@
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.unwrapFolderHandler = 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 unwrapFolderHandler = ({ 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: 'delete a folder from',
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.unwrapFolder)({
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
+ folder: { name: request.folderName, parentName: request.parentName },
45
+ });
46
+ for (const change of result.changes) {
47
+ const currentContents = (0, node_fs_1.existsSync)(change.filePath)
48
+ ? (0, node_fs_1.readFileSync)(change.filePath, 'utf-8')
49
+ : null;
50
+ if (currentContents !== change.previousContents) {
51
+ throw new Error(`Source changed before deleting folder: ${change.filePath}`);
52
+ }
53
+ }
54
+ if (result.changes.length > 0) {
55
+ const logLine = (_c = (_b = request.symbolicatedStack) === null || _b === void 0 ? void 0 : _b.originalLineNumber) !== null && _c !== void 0 ? _c : 1;
56
+ const folderPath = request.parentName
57
+ ? `${request.parentName}/${request.folderName}`
58
+ : request.folderName;
59
+ (0, undo_stack_1.pushTransactionToUndoStack)({
60
+ snapshots: result.changes.map((change) => ({
61
+ filePath: change.filePath,
62
+ oldContents: change.previousContents,
63
+ newContents: change.nextContents,
64
+ logLine: change.filePath === filePath ? logLine : 1,
65
+ nodePathRemappings: null,
66
+ })),
67
+ logLevel,
68
+ remotionRoot,
69
+ description: {
70
+ undoMessage: `↩️ Deletion of folder "${folderPath}"`,
71
+ redoMessage: `↪️ Deletion of folder "${folderPath}"`,
72
+ },
73
+ entryType: 'delete-folder',
74
+ suppressHmrOnFileRestore: false,
75
+ undoRedoNavigation: request.undoRedoNavigation,
76
+ });
77
+ for (const change of result.changes) {
78
+ if (change.nextContents === null) {
79
+ throw new Error('Deleting a folder cannot remove source files');
80
+ }
81
+ (0, undo_stack_1.suppressUndoStackInvalidation)(change.filePath);
82
+ (0, file_watcher_1.writeFileAndNotifyFileWatchers)({
83
+ file: change.filePath,
84
+ content: change.nextContents,
85
+ originatorClientId: undefined,
86
+ metadata: null,
87
+ });
88
+ }
89
+ const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
90
+ remotionRoot,
91
+ absolutePath: filePath,
92
+ line: logLine,
93
+ });
94
+ renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(locationLabel)} Deleted folder "${folderPath}"`);
95
+ (0, undo_stack_1.printUndoHint)(logLevel);
96
+ }
97
+ return { success: true, nodePathMutation: null };
98
+ }
99
+ catch (error) {
100
+ return {
101
+ success: false,
102
+ reason: error instanceof Error ? error.message : String(error),
103
+ stack: error instanceof Error ? ((_d = error.stack) !== null && _d !== void 0 ? _d : '') : '',
104
+ };
105
+ }
106
+ });
107
+ exports.unwrapFolderHandler = unwrapFolderHandler;
@@ -0,0 +1,3 @@
1
+ import type { CompositionEditResponse, UpdateCompositionMetadataRequest } from '@remotion/studio-shared';
2
+ import type { ApiHandler } from '../api-types';
3
+ export declare const updateCompositionMetadataHandler: ApiHandler<UpdateCompositionMetadataRequest, CompositionEditResponse>;
@@ -0,0 +1,110 @@
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.updateCompositionMetadataHandler = 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 updateCompositionMetadataHandler = ({ input: request, logLevel, remotionRoot, entryPoint }) => (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
19
+ var _a, _b;
20
+ var _c, _d, _e, _f, _g, _h;
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: 'update composition metadata 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.updateCompositionMetadata)({
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.idToUpdate,
45
+ metadata: {
46
+ width: (_c = request.newWidth) !== null && _c !== void 0 ? _c : undefined,
47
+ height: (_d = request.newHeight) !== null && _d !== void 0 ? _d : undefined,
48
+ fps: (_e = request.newFps) !== null && _e !== void 0 ? _e : undefined,
49
+ durationInFrames: (_f = request.newDurationInFrames) !== null && _f !== void 0 ? _f : undefined,
50
+ },
51
+ });
52
+ for (const change of result.changes) {
53
+ const currentContents = (0, node_fs_1.existsSync)(change.filePath)
54
+ ? (0, node_fs_1.readFileSync)(change.filePath, 'utf-8')
55
+ : null;
56
+ if (currentContents !== change.previousContents) {
57
+ throw new Error(`Source changed before updating composition metadata: ${change.filePath}`);
58
+ }
59
+ }
60
+ if (result.changes.length > 0) {
61
+ const logLine = (_g = (_b = request.symbolicatedStack) === null || _b === void 0 ? void 0 : _b.originalLineNumber) !== null && _g !== void 0 ? _g : 1;
62
+ (0, undo_stack_1.pushTransactionToUndoStack)({
63
+ snapshots: result.changes.map((change) => ({
64
+ filePath: change.filePath,
65
+ oldContents: change.previousContents,
66
+ newContents: change.nextContents,
67
+ logLine: change.filePath === filePath ? logLine : 1,
68
+ nodePathRemappings: null,
69
+ })),
70
+ logLevel,
71
+ remotionRoot,
72
+ description: {
73
+ undoMessage: `↩️ Update of metadata of composition "${request.idToUpdate}"`,
74
+ redoMessage: `↪️ Update of metadata of composition "${request.idToUpdate}"`,
75
+ },
76
+ entryType: 'update-composition-metadata',
77
+ suppressHmrOnFileRestore: false,
78
+ undoRedoNavigation: request.undoRedoNavigation,
79
+ });
80
+ for (const change of result.changes) {
81
+ if (change.nextContents === null) {
82
+ throw new Error('Updating composition metadata cannot remove source files');
83
+ }
84
+ (0, undo_stack_1.suppressUndoStackInvalidation)(change.filePath);
85
+ (0, file_watcher_1.writeFileAndNotifyFileWatchers)({
86
+ file: change.filePath,
87
+ content: change.nextContents,
88
+ originatorClientId: undefined,
89
+ metadata: null,
90
+ });
91
+ }
92
+ const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
93
+ remotionRoot,
94
+ absolutePath: filePath,
95
+ line: logLine,
96
+ });
97
+ renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(locationLabel)} Updated metadata of composition "${request.idToUpdate}"`);
98
+ (0, undo_stack_1.printUndoHint)(logLevel);
99
+ }
100
+ return { success: true, nodePathMutation: null };
101
+ }
102
+ catch (error) {
103
+ return {
104
+ success: false,
105
+ reason: error instanceof Error ? error.message : String(error),
106
+ stack: error instanceof Error ? ((_h = error.stack) !== null && _h !== void 0 ? _h : '') : '',
107
+ };
108
+ }
109
+ });
110
+ exports.updateCompositionMetadataHandler = updateCompositionMetadataHandler;
@@ -0,0 +1,3 @@
1
+ import type { WrapNodeRequest, WrapNodeResponse } from '@remotion/studio-shared';
2
+ import type { ApiHandler } from '../api-types';
3
+ export declare const wrapNodeHandler: ApiHandler<WrapNodeRequest, WrapNodeResponse>;