@remotion/studio-server 4.0.527 → 4.0.529

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 (49) hide show
  1. package/dist/codemods/apply-codemod-to-file.d.ts +2 -1
  2. package/dist/codemods/apply-codemod-to-file.js +141 -8
  3. package/dist/codemods/effect-param-expression.d.ts +1 -1
  4. package/dist/codemods/effect-param-expression.js +3 -2
  5. package/dist/codemods/update-effect-props/update-effect-props.d.ts +6 -33
  6. package/dist/codemods/update-effect-props/update-effect-props.js +16 -6
  7. package/dist/codemods/update-keyframes/update-keyframes.d.ts +24 -65
  8. package/dist/codemods/update-keyframes/update-keyframes.js +23 -5
  9. package/dist/codemods/update-sequence-props/update-sequence-props.d.ts +2 -17
  10. package/dist/codemods/update-sequence-props/update-sequence-props.js +15 -8
  11. package/dist/helpers/open-file-for-writing-without-symlinks.d.ts +6 -1
  12. package/dist/helpers/open-file-for-writing-without-symlinks.js +9 -6
  13. package/dist/index.d.ts +0 -22
  14. package/dist/index.js +0 -7
  15. package/dist/preview-server/api-routes.js +4 -0
  16. package/dist/preview-server/hot-middleware/index.js +13 -46
  17. package/dist/preview-server/routes/add-effect.js +16 -8
  18. package/dist/preview-server/routes/apply-codemod.d.ts +0 -19
  19. package/dist/preview-server/routes/apply-codemod.js +22 -25
  20. package/dist/preview-server/routes/apply-visual-control-change.js +12 -65
  21. package/dist/preview-server/routes/can-update-sequence-props.d.ts +0 -10
  22. package/dist/preview-server/routes/can-update-sequence-props.js +52 -511
  23. package/dist/preview-server/routes/delete-effect.js +14 -13
  24. package/dist/preview-server/routes/delete-jsx-nodes.js +15 -4
  25. package/dist/preview-server/routes/download-remote-asset.d.ts +5 -0
  26. package/dist/preview-server/routes/download-remote-asset.js +25 -20
  27. package/dist/preview-server/routes/duplicate-effect.js +11 -4
  28. package/dist/preview-server/routes/duplicate-jsx-node.js +14 -4
  29. package/dist/preview-server/routes/insert-element.js +399 -280
  30. package/dist/preview-server/routes/install-dependency.js +14 -4
  31. package/dist/preview-server/routes/prepare-element-install.js +3 -0
  32. package/dist/preview-server/routes/reorder-effect.js +11 -5
  33. package/dist/preview-server/routes/reorder-sequence.js +9 -5
  34. package/dist/preview-server/routes/replace-video-source.d.ts +3 -0
  35. package/dist/preview-server/routes/replace-video-source.js +81 -0
  36. package/dist/preview-server/routes/save-sequence-props.js +5 -26
  37. package/dist/preview-server/routes/split-jsx-sequence.js +13 -5
  38. package/dist/preview-server/routes/split-video-from-audio.js +8 -4
  39. package/dist/preview-server/routes/subscribe-to-sequence-props.js +6 -10
  40. package/dist/preview-server/routes/update-config.js +38 -2
  41. package/dist/preview-server/routes/update-default-props.js +11 -8
  42. package/dist/preview-server/routes/wrap-jsx-node.d.ts +3 -0
  43. package/dist/preview-server/routes/wrap-jsx-node.js +97 -0
  44. package/dist/preview-server/studio-protocol/handle-discovery.js +1 -1
  45. package/dist/preview-server/studio-protocol/handle-element-library.js +3 -3
  46. package/dist/preview-server/undo-stack.d.ts +2 -1
  47. package/dist/preview-server/undo-stack.js +19 -0
  48. package/dist/routes.js +2 -0
  49. package/package.json +8 -8
@@ -49,52 +49,19 @@ const setupWebpackHmr = (compiler, logLevel, liveEventsServer) => {
49
49
  };
50
50
  exports.setupWebpackHmr = setupWebpackHmr;
51
51
  function publishStats(action, statsResult, publishHmr) {
52
- const stats = statsResult.toJson({
53
- all: false,
54
- cached: true,
55
- children: true,
56
- modules: true,
57
- timings: true,
58
- hash: true,
59
- });
60
- // For multi-compiler, stats will be an object with a 'children' array of stats
61
- const bundles = extractBundles(stats);
62
- bundles.forEach((_stats) => {
63
- let name = _stats.name || '';
64
- // Fallback to compilation name in case of 1 bundle (if it exists)
65
- if (bundles.length === 1 && !name && statsResult.compilation) {
66
- name = statsResult.compilation.name || '';
67
- }
68
- publishHmr({
69
- name,
70
- action,
71
- time: _stats.time,
72
- hash: _stats.hash,
73
- warnings: _stats.warnings || [],
74
- errors: _stats.errors || [],
75
- modules: buildModuleMap(_stats.modules),
76
- });
77
- });
78
- }
79
- function extractBundles(stats) {
80
52
  var _a;
81
- // Stats has modules, single bundle
82
- if (stats.modules)
83
- return [stats];
84
- // Stats has children, multiple bundles
85
- if ((_a = stats.children) === null || _a === void 0 ? void 0 : _a.length)
86
- return stats.children;
87
- // Not sure, assume single
88
- return [stats];
89
- }
90
- function buildModuleMap(modules) {
91
- const map = {};
92
- if (!modules) {
93
- return map;
94
- }
95
- modules.forEach((module) => {
96
- const id = module.id;
97
- map[id] = module.name;
53
+ // Studio uses a single compiler. Child compilations must not replace the
54
+ // parent compilation's hash in the HMR message.
55
+ publishHmr({
56
+ name: (_a = statsResult.compilation.name) !== null && _a !== void 0 ? _a : '',
57
+ action,
58
+ time: statsResult.endTime - statsResult.startTime,
59
+ hash: statsResult.hash,
60
+ // Build diagnostics are printed by the dev middleware.
61
+ warnings: [],
62
+ errors: [],
63
+ // Module names only label browser console messages. The client already
64
+ // falls back to module IDs, which are named in development builds.
65
+ modules: {},
98
66
  });
99
- return map;
100
67
  }
@@ -11,10 +11,12 @@ const undo_stack_1 = require("../undo-stack");
11
11
  const formatting_1 = require("./log-updates/formatting");
12
12
  const log_update_1 = require("./log-updates/log-update");
13
13
  const source_file_write_queue_1 = require("./source-file-write-queue");
14
- const { addEffect } = codemods_1.CodemodsInternals;
15
- const addEffectHandler = ({ input: { fileName, sequenceNodePath, effectName, effectImportPath, effectConfig, clientId, }, remotionRoot, logLevel, }) => {
14
+ const addEffectHandler = ({ input: request, remotionRoot, logLevel }) => {
16
15
  return (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
16
+ var _a;
17
+ var _b;
17
18
  try {
19
+ const { fileName, sequenceNodePath, effectName, effectImportPath, effectConfig, clientId, } = request;
18
20
  renderer_1.RenderInternals.Log.trace({ indent: false, logLevel }, `[add-effect] Received request for fileName="${fileName}" effect="${effectName}"`);
19
21
  const { absolutePath, fileRelativeToRoot } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
20
22
  remotionRoot,
@@ -22,13 +24,15 @@ const addEffectHandler = ({ input: { fileName, sequenceNodePath, effectName, eff
22
24
  action: 'modify',
23
25
  });
24
26
  const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
25
- const { output, formatted, effectLabel, nodeLabel, logLine } = await addEffect({
26
- input: fileContents,
27
- sequenceNodePath: sequenceNodePath.nodePath,
28
- effectName,
29
- effectImportPath,
30
- effectConfig,
27
+ const result = await (0, codemods_1.addEffect)({
28
+ project: { files: { [absolutePath]: fileContents }, rootDir: remotionRoot },
29
+ node: { filePath: absolutePath, nodePath: sequenceNodePath.nodePath },
30
+ importName: effectName,
31
+ importPath: effectImportPath,
32
+ props: effectConfig,
31
33
  });
34
+ const output = (_b = (_a = result.changes[0]) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _b !== void 0 ? _b : fileContents;
35
+ const { formatted, effectLabel, nodeLabel, logLine } = result.editDetails[0];
32
36
  (0, undo_stack_1.pushToUndoStack)({
33
37
  filePath: absolutePath,
34
38
  oldContents: fileContents,
@@ -64,6 +68,10 @@ const addEffectHandler = ({ input: { fileName, sequenceNodePath, effectName, eff
64
68
  (0, undo_stack_1.printUndoHint)(logLevel);
65
69
  return {
66
70
  success: true,
71
+ insertedEffect: {
72
+ effectIndex: result.insertedEffect.effectIndex,
73
+ nodePath: result.insertedEffect.nodePath,
74
+ },
67
75
  };
68
76
  }
69
77
  catch (err) {
@@ -1,23 +1,4 @@
1
1
  import type { ApplyCodemodRequest, ApplyCodemodResponse } from '@remotion/studio-shared';
2
2
  import type { ApiHandler } from '../api-types';
3
- export declare const formatNewCompositionFile: (codemod: {
4
- type: "new-composition";
5
- newId: string;
6
- componentName: string;
7
- componentImportPath: string;
8
- folderName: string | null;
9
- parentName: string | null;
10
- newHeight: number;
11
- newWidth: number;
12
- newFps: number;
13
- newDurationInFrames: number;
14
- canvasCapture: {
15
- readonly videoFileName: string;
16
- readonly videoHeight: number;
17
- readonly videoWidth: number;
18
- readonly keyframeFps: number;
19
- readonly data: import("@remotion/studio-shared").CanvasCaptureData;
20
- } | null;
21
- }) => string;
22
3
  export declare const getCodemodLogMessage: (codemod: import("@remotion/studio-shared").RecastCodemod) => string;
23
4
  export declare const applyCodemodHandler: ApiHandler<ApplyCodemodRequest, ApplyCodemodResponse>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.applyCodemodHandler = exports.getCodemodLogMessage = exports.formatNewCompositionFile = void 0;
6
+ exports.applyCodemodHandler = exports.getCodemodLogMessage = void 0;
7
7
  const node_fs_1 = require("node:fs");
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const codemods_1 = require("@remotion/codemods");
@@ -15,9 +15,7 @@ const project_info_1 = require("../project-info");
15
15
  const undo_stack_1 = require("../undo-stack");
16
16
  const can_update_default_props_1 = require("./can-update-default-props");
17
17
  const source_file_write_queue_1 = require("./source-file-write-queue");
18
- const { makeNewCompositionComponentSource, simpleDiff } = codemods_1.CodemodsInternals;
19
- const formatNewCompositionFile = (codemod) => makeNewCompositionComponentSource(codemod);
20
- exports.formatNewCompositionFile = formatNewCompositionFile;
18
+ const { simpleDiff } = codemods_1.CodemodsInternals;
21
19
  const getFolderPath = (parentName, folderName) => {
22
20
  return parentName ? `${parentName}/${folderName}` : folderName;
23
21
  };
@@ -40,12 +38,6 @@ const getCodemodLogMessage = (codemod) => {
40
38
  if (codemod.type === 'delete-composition') {
41
39
  return `Deleted composition "${codemod.idToDelete}"`;
42
40
  }
43
- if (codemod.type === 'move-composition-to-folder') {
44
- const destination = codemod.folderName
45
- ? `into folder "${getFolderPath(codemod.parentName, codemod.folderName)}"`
46
- : 'to root';
47
- return `Moved composition "${codemod.idToMove}" ${destination}`;
48
- }
49
41
  if (codemod.type === 'move-composition-or-folder') {
50
42
  const source = codemod.source.type === 'composition'
51
43
  ? `composition "${codemod.source.compositionId}"`
@@ -103,17 +95,6 @@ const getCodemodUndoDescription = (codemod) => {
103
95
  entryType: codemod.type,
104
96
  };
105
97
  }
106
- if (codemod.type === 'move-composition-to-folder') {
107
- const destination = codemod.folderName === null
108
- ? 'to root'
109
- : `into folder "${getFolderPath(codemod.parentName, codemod.folderName)}"`;
110
- const label = `composition "${codemod.idToMove}" ${destination}`;
111
- return {
112
- undoMessage: `↩️ Move of ${label}`,
113
- redoMessage: `↪️ Move of ${label}`,
114
- entryType: codemod.type,
115
- };
116
- }
117
98
  if (codemod.type === 'move-composition-or-folder') {
118
99
  const label = codemod.source.type === 'composition'
119
100
  ? `composition "${codemod.source.compositionId}"`
@@ -165,9 +146,10 @@ const getCodemodUndoDescription = (codemod) => {
165
146
  };
166
147
  const applyCodemodHandler = ({ input: { codemod, dryRun, symbolicatedStack, undoRedoNavigation }, logLevel, remotionRoot, entryPoint, }) => {
167
148
  return (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
168
- var _a;
149
+ var _a, _b;
150
+ var _c, _d, _e;
169
151
  try {
170
- const logLine = (_a = symbolicatedStack === null || symbolicatedStack === void 0 ? void 0 : symbolicatedStack.originalLineNumber) !== null && _a !== void 0 ? _a : 1;
152
+ const logLine = (_c = symbolicatedStack === null || symbolicatedStack === void 0 ? void 0 : symbolicatedStack.originalLineNumber) !== null && _c !== void 0 ? _c : 1;
171
153
  const filePath = symbolicatedStack
172
154
  ? (0, apply_codemod_to_file_1.resolveFilePathFromSymbolicatedStack)(remotionRoot, symbolicatedStack)
173
155
  : (await (0, project_info_1.getProjectInfo)(remotionRoot, entryPoint)).rootFile;
@@ -184,15 +166,27 @@ const applyCodemodHandler = ({ input: { codemod, dryRun, symbolicatedStack, undo
184
166
  throw new Error(`Cannot create ${node_path_1.default.relative(remotionRoot, newCompositionComponentFilePath)} because it already exists`);
185
167
  }
186
168
  const input = (0, node_fs_1.readFileSync)(filePath, 'utf-8');
187
- const formatted = await (0, apply_codemod_to_file_1.applyCodemodToFile)({
169
+ const result = await (0, apply_codemod_to_file_1.applyCodemodToFile)({
188
170
  filePath,
189
171
  codeMod: codemod,
190
172
  });
173
+ const formatted = (_d = (_a = result.changes.find((change) => change.filePath === filePath)) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _d !== void 0 ? _d : input;
191
174
  const diff = simpleDiff({
192
175
  oldLines: input.split('\n'),
193
176
  newLines: formatted.split('\n'),
194
177
  });
195
178
  if (!dryRun) {
179
+ if ((0, node_fs_1.readFileSync)(filePath, 'utf-8') !== input) {
180
+ throw new Error(`Source changed before applying codemod: ${filePath}`);
181
+ }
182
+ for (const change of result.changes) {
183
+ const currentContents = (0, node_fs_1.existsSync)(change.filePath)
184
+ ? (0, node_fs_1.readFileSync)(change.filePath, 'utf-8')
185
+ : null;
186
+ if (currentContents !== change.previousContents) {
187
+ throw new Error(`Source changed before applying codemod: ${change.filePath}`);
188
+ }
189
+ }
196
190
  const { entryType, undoMessage, redoMessage } = getCodemodUndoDescription(codemod);
197
191
  const snapshots = [
198
192
  {
@@ -210,7 +204,10 @@ const applyCodemodHandler = ({ input: { codemod, dryRun, symbolicatedStack, undo
210
204
  if (componentFilePath === null) {
211
205
  throw new Error('Could not determine the new component file path');
212
206
  }
213
- componentFileContents = await (0, exports.formatNewCompositionFile)(codemod);
207
+ componentFileContents = (_e = (_b = result.changes.find((change) => change.filePath === componentFilePath)) === null || _b === void 0 ? void 0 : _b.nextContents) !== null && _e !== void 0 ? _e : null;
208
+ if (componentFileContents === null) {
209
+ throw new Error('Could not create the composition component');
210
+ }
214
211
  snapshots.push({
215
212
  filePath: componentFilePath,
216
213
  oldContents: null,
@@ -1,44 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.applyVisualControlHandler = void 0;
37
4
  const node_fs_1 = require("node:fs");
38
5
  const codemods_1 = require("@remotion/codemods");
39
6
  const renderer_1 = require("@remotion/renderer");
40
- const recast = __importStar(require("recast"));
41
- const parse_ast_1 = require("../../codemods/parse-ast");
42
7
  const file_watcher_1 = require("../../file-watcher");
43
8
  const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
44
9
  const format_log_file_location_1 = require("../format-log-file-location");
@@ -46,29 +11,10 @@ const live_events_1 = require("../live-events");
46
11
  const undo_stack_1 = require("../undo-stack");
47
12
  const watch_ignore_next_change_1 = require("../watch-ignore-next-change");
48
13
  const source_file_write_queue_1 = require("./source-file-write-queue");
49
- const { applyVisualControl } = codemods_1.CodemodsInternals;
50
- const getVisualControlChangeLine = (file, changeId) => {
51
- let line = 1;
52
- recast.types.visit(file.program, {
53
- visitCallExpression(callPath) {
54
- var _a;
55
- var _b;
56
- const { node } = callPath;
57
- if (node.callee.type === 'Identifier' &&
58
- node.callee.name === 'visualControl') {
59
- const firstArg = node.arguments[0];
60
- if ((firstArg === null || firstArg === void 0 ? void 0 : firstArg.type) === 'StringLiteral' && firstArg.value === changeId) {
61
- line = (_b = (_a = node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1;
62
- return false;
63
- }
64
- }
65
- this.traverse(callPath);
66
- },
67
- });
68
- return line;
69
- };
70
14
  const applyVisualControlHandler = ({ input: { fileName, changes }, remotionRoot, logLevel }) => {
71
15
  return (0, source_file_write_queue_1.withSourceFileWriteQueue)(() => {
16
+ var _a, _b;
17
+ var _c, _d;
72
18
  renderer_1.RenderInternals.Log.trace({ indent: false, logLevel }, `[apply-visual-control] Received request for ${fileName} with ${changes.length} changes`);
73
19
  const { absolutePath } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
74
20
  remotionRoot,
@@ -76,16 +22,17 @@ const applyVisualControlHandler = ({ input: { fileName, changes }, remotionRoot,
76
22
  action: 'apply visual control change to',
77
23
  });
78
24
  const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
79
- const ast = (0, parse_ast_1.parseAst)(fileContents);
80
- const logLine = changes.length > 0 ? getVisualControlChangeLine(ast, changes[0].id) : 1;
81
- const { newContents: output, changesMade } = applyVisualControl({
82
- input: fileContents,
83
- transformation: {
84
- type: 'apply-visual-control',
85
- changes,
86
- },
25
+ const result = (0, codemods_1.updateVisualControls)({
26
+ project: { rootDir: remotionRoot, files: { [absolutePath]: fileContents } },
27
+ filePath: absolutePath,
28
+ changes,
87
29
  });
88
- if (changesMade.length === 0) {
30
+ const output = (_c = (_a = result.changes[0]) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _c !== void 0 ? _c : fileContents;
31
+ const logLine = (_d = (_b = result.updatedControls.findLast((control) => {
32
+ var _a;
33
+ return control.id === ((_a = changes[0]) === null || _a === void 0 ? void 0 : _a.id);
34
+ })) === null || _b === void 0 ? void 0 : _b.line) !== null && _d !== void 0 ? _d : 1;
35
+ if (result.updatedControls.length === 0) {
89
36
  throw new Error('No changes were made to the file');
90
37
  }
91
38
  (0, undo_stack_1.pushToUndoStack)({
@@ -2,7 +2,6 @@ import type { Expression, File, JSXElement, JSXOpeningElement } from '@babel/typ
2
2
  import type { SubscribeToSequencePropsResponse } from '@remotion/studio-shared';
3
3
  import type { CanUpdateSequencePropsResponseTrue, CanUpdateSequencePropStatus, SequenceNodePath, VideoConfigValues } from 'remotion';
4
4
  import { type VideoConfigIdentifierValues } from '../../helpers/video-config-values';
5
- export declare const takeCachedSequencePropsStatusAst: (fileContents: string) => File | null;
6
5
  type StaticValueOptions = {
7
6
  allowSpecialValues: boolean;
8
7
  };
@@ -41,15 +40,6 @@ export declare const resolveSequencePropsNodePathsFromFilename: ({ fileName, tar
41
40
  }[];
42
41
  remotionRoot: string;
43
42
  }) => (SequenceNodePath | null)[];
44
- export declare const computeSequencePropsStatusFromAst: ({ ast, nodePath, componentIdentity, keys, assetKeys, effects, videoConfigValues, }: {
45
- ast: File;
46
- nodePath: SequenceNodePath;
47
- componentIdentity: string | null;
48
- keys: string[];
49
- assetKeys?: string[] | undefined;
50
- effects: string[][];
51
- videoConfigValues: VideoConfigValues | null;
52
- }) => CanUpdateSequencePropsResponseTrue;
53
43
  export declare const computeSequencePropsStatusFromContent: ({ fileContents, nodePath, componentIdentity, keys, assetKeys, effects, videoConfigValues, }: {
54
44
  fileContents: string;
55
45
  nodePath: SequenceNodePath;