Skip to content

🎥 Make videos programmatically with React

installable packages

Jonny Burger35b1c999ec5b
diff --git a/packages/studio-server/src/preview-server/routes/install-dependency.ts b/packages/studio-server/src/preview-server/routes/install-dependency.ts
index 8be5f05a31..34d81d313b 100644
--- a/packages/studio-server/src/preview-server/routes/install-dependency.ts
+++ b/packages/studio-server/src/preview-server/routes/install-dependency.ts
@@ -1,8 +1,9 @@
import {RenderInternals} from '@remotion/renderer';
-import type {
- InstallPackageRequest,
- InstallPackageResponse,
- PackageManager,
+import {
+ listOfInstallableRemotionPackages,
+ type InstallPackageRequest,
+ type InstallPackageResponse,
+ type PackageManager,
} from '@remotion/studio-shared';
import {spawn} from 'node:child_process';
import {VERSION} from 'remotion/version';
@@ -33,7 +34,13 @@ const getInstallCommand = ({
export const handleInstallPackage: ApiHandler<
InstallPackageRequest,
InstallPackageResponse
-> = async ({logLevel, remotionRoot}) => {
+> = async ({logLevel, remotionRoot, input: {packageName}}) => {
+ if (listOfInstallableRemotionPackages.includes(packageName) === false) {
+ return Promise.reject(
+ new Error(`Package ${packageName} is not allowed to be installed.`),
+ );
+ }
+
// TODO: Should set this to "undefined" if not in development
const manager = getPackageManager(remotionRoot, 'pnpm');
if (manager === 'unknown') {
@@ -46,7 +53,7 @@ export const handleInstallPackage: ApiHandler<
const command = getInstallCommand({
manager: manager.manager,
- packages: ['@remotion/tailwind'],
+ packages: [packageName],
version: VERSION,
});
diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.ts
index 60ebb98e4b..77b928b3e0 100644
--- a/packages/studio-shared/src/api-requests.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -10,6 +10,7 @@ import type {
X264Preset,
} from '@remotion/renderer';
import type {RecastCodemod} from './codemods';
+import type {InstallablePackage} from './installable-packages';
import type {PackageManager} from './package-manager';
import type {ProjectInfo} from './project-info';
import type {RequiredChromiumOptions} from './render-job';
@@ -190,7 +191,9 @@ export type ProjectInfoResponse = {
export type RestartStudioRequest = {};
export type RestartStudioResponse = {};
-export type InstallPackageRequest = {};
+export type InstallPackageRequest = {
+ packageName: InstallablePackage;
+};
export type InstallPackageResponse = {};
export type ApiRoutes = {
diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.ts
index 5e4b275d64..ef7247851c 100644
--- a/packages/studio-shared/src/index.ts
+++ b/packages/studio-shared/src/index.ts
@@ -45,6 +45,10 @@ export {
ModuleMap,
hotMiddlewareOptions,
} from './hot-middleware';
+export {
+ InstallablePackage,
+ listOfInstallableRemotionPackages,
+} from './installable-packages';
export {DEFAULT_TIMELINE_TRACKS} from './max-timeline-tracks';
export {PackageManager} from './package-manager';
export {ProjectInfo} from './project-info';
diff --git a/packages/studio-shared/src/installable-packages.ts b/packages/studio-shared/src/installable-packages.ts
new file mode 100644
index 0000000000..505413528f
--- /dev/null
+++ b/packages/studio-shared/src/installable-packages.ts
@@ -0,0 +1,28 @@
+// Keep in sync with cli
+export const listOfInstallableRemotionPackages = [
+ '@remotion/animated-emoji',
+ '@remotion/animation-utils',
+ '@remotion/cloudrun',
+ '@remotion/enable-scss',
+ '@remotion/gif',
+ '@remotion/google-fonts',
+ '@remotion/lambda',
+ '@remotion/layout-utils',
+ '@remotion/lottie',
+ '@remotion/media-parser',
+ '@remotion/media-utils',
+ '@remotion/motion-blur',
+ '@remotion/noise',
+ '@remotion/paths',
+ '@remotion/rive',
+ '@remotion/shapes',
+ '@remotion/skia',
+ '@remotion/studio',
+ '@remotion/tailwind',
+ '@remotion/three',
+ '@remotion/transitions',
+ '@remotion/zod-types',
+] as const;
+
+export type InstallablePackage =
+ (typeof listOfInstallableRemotionPackages)[number];
diff --git a/packages/studio/src/api/install-package.ts b/packages/studio/src/api/install-package.ts
index a58173efda..3e532e190d 100644
--- a/packages/studio/src/api/install-package.ts
+++ b/packages/studio/src/api/install-package.ts
@@ -1,6 +1,11 @@
-import type {InstallPackageResponse} from '@remotion/studio-shared';
+import type {
+ InstallPackageResponse,
+ InstallablePackage,
+} from '@remotion/studio-shared';
import {callApi} from '../components/call-api';
-export const installPackage = (): Promise<InstallPackageResponse> => {
- return callApi('/api/install-package', {});
+export const installPackage = (
+ packageName: InstallablePackage,
+): Promise<InstallPackageResponse> => {
+ return callApi('/api/install-package', {packageName});
};
diff --git a/packages/studio/src/components/UpdateModal/UpdateModal.tsx b/packages/studio/src/components/UpdateModal/UpdateModal.tsx
index 07ecf8057d..436e3c8484 100644
--- a/packages/studio/src/components/UpdateModal/UpdateModal.tsx
+++ b/packages/studio/src/components/UpdateModal/UpdateModal.tsx
@@ -48,8 +48,8 @@ const commands: {[key in UpdateInfo['packageManager']]: string} = {
};
export const UpdateModal: React.FC<{
- info: UpdateInfo;
- knownBugs: Bug[];
+ readonly info: UpdateInfo;
+ readonly knownBugs: Bug[];
}> = ({info, knownBugs}) => {
const hasKnownBugs = useMemo(() => {
return knownBugs && knownBugs?.length > 0;
diff --git a/packages/studio/src/helpers/use-menu-structure.tsx b/packages/studio/src/helpers/use-menu-structure.tsx
index 2aa917f827..ba90ab15fb 100644
--- a/packages/studio/src/helpers/use-menu-structure.tsx
+++ b/packages/studio/src/helpers/use-menu-structure.tsx
@@ -1,3 +1,4 @@
+import {listOfInstallableRemotionPackages} from '@remotion/studio-shared';
import {useContext, useMemo} from 'react';
import {Internals} from 'remotion';
import {NoReactInternals} from 'remotion/no-react';
@@ -658,22 +659,20 @@ export const useMenuStructure = (
id: 'install' as const,
label: 'Install',
leaveLeftPadding: false,
- items: [
- {
- id: 'install-dependency',
- value: 'install-dependency',
- label: 'Install dependency',
- onClick: () => {
- closeMenu();
- installPackage();
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- quickSwitcherLabel: 'Install dependency',
+ items: listOfInstallableRemotionPackages.map((pkg) => ({
+ id: pkg,
+ value: pkg,
+ label: pkg,
+ onClick: () => {
+ closeMenu();
+ installPackage(pkg);
},
- ],
+ type: 'item' as const,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: null,
+ })),
},
{
id: 'help' as const,