Skip to content

🎥 Make videos programmatically with React

Npx support support Mediabunny and Zod

Ayushmand3d80b1eab89
diff --git a/packages/cli/src/add.ts b/packages/cli/src/add.ts
index b55cbc8ac2..2d306f4dc9 100644
--- a/packages/cli/src/add.ts
+++ b/packages/cli/src/add.ts
@@ -4,6 +4,10 @@ import {spawn} from 'node:child_process';
import {chalk} from './chalk';
import {listOfRemotionPackages} from './list-of-remotion-packages';
import {Log} from './log';
+const EXTRA_PACKAGES: Record<string, string> = {
+ zod: '3.22.2',
+ mediabunny: '1.29.0',
+};
export const addCommand = async ({
remotionRoot,
@@ -20,11 +24,11 @@ export const addCommand = async ({
}) => {
// Validate that all package names are Remotion packages
const invalidPackages = packageNames.filter(
- (pkg) => !listOfRemotionPackages.includes(pkg),
+ (pkg) => !listOfRemotionPackages.includes(pkg) && !EXTRA_PACKAGES[pkg],
);
if (invalidPackages.length > 0) {
throw new Error(
- `The following packages are not Remotion packages: ${invalidPackages.join(', ')}. Must be one of the Remotion packages.`,
+ `The following packages are not Remotion packages: ${invalidPackages.join(', ')}. Must be one of the Remotion packages or one of the supported extra packages: ${Object.keys(EXTRA_PACKAGES).join(', ')}.`,
);
}
@@ -59,36 +63,40 @@ export const addCommand = async ({
return;
}
- // Find the version of installed Remotion packages
const installedRemotionPackages = listOfRemotionPackages.filter((pkg) =>
allDeps.includes(pkg),
);
- if (installedRemotionPackages.length === 0) {
- throw new Error(
- 'No Remotion packages found in your project. Install Remotion first.',
- );
- }
// Get the version from the first installed Remotion package
const packageJsonPath = `${remotionRoot}/node_modules/${installedRemotionPackages[0]}/package.json`;
- let targetVersion: string;
-
- try {
- const packageJson = require(packageJsonPath);
- targetVersion = packageJson.version;
- const packageList =
- toInstall.length === 1
- ? toInstall[0]
- : `${toInstall.length} packages (${toInstall.join(', ')})`;
- Log.info(
- {indent: false, logLevel},
- `Installing ${packageList}@${targetVersion} to match your other Remotion packages`,
- );
- } catch (err) {
- throw new Error(
- `Could not determine version of installed Remotion packages: ${(err as Error).message}`,
- );
+ let targetVersion: string | null = null;
+
+ if (installedRemotionPackages.length > 0) {
+ try {
+ const packageJson = require(packageJsonPath);
+ targetVersion = packageJson.version;
+ const packageList =
+ toInstall.length === 1
+ ? toInstall[0]
+ : `${toInstall.length} packages (${toInstall.join(', ')})`;
+ Log.info(
+ {indent: false, logLevel},
+ `Installing ${packageList} to match your other Remotion packages (zod and mediabunny exception)`,
+ );
+ } catch (err) {
+ throw new Error(
+ `Could not determine version of installed Remotion packages: ${(err as Error).message}`,
+ );
+ }
+ } else {
+ // If no Remotion packages are installed, we can only install extra packages
+ const notExtraPackages = toInstall.filter((pkg) => !EXTRA_PACKAGES[pkg]);
+ if (notExtraPackages.length > 0) {
+ throw new Error(
+ 'No Remotion packages found in your project. Install Remotion first.',
+ );
+ }
}
const manager = StudioServerInternals.getPackageManager(
@@ -105,10 +113,17 @@ export const addCommand = async ({
);
}
+ const packagesWithVersions = toInstall.map((pkg) => {
+ if (EXTRA_PACKAGES[pkg]) {
+ return `${pkg}@${EXTRA_PACKAGES[pkg]}`;
+ }
+ return `${pkg}@${targetVersion}`;
+ });
+
const command = StudioServerInternals.getInstallCommand({
manager: manager.manager,
- packages: toInstall,
- version: targetVersion,
+ packages: packagesWithVersions,
+ version: '',
additionalArgs: args,
});
@@ -150,6 +165,10 @@ export const addCommand = async ({
}
for (const pkg of toInstall) {
- Log.info({indent: false, logLevel}, `+ ${pkg}@${targetVersion}`);
+ if (EXTRA_PACKAGES[pkg]) {
+ Log.info({indent: false, logLevel}, `+ ${pkg}@${EXTRA_PACKAGES[pkg]}`);
+ } else {
+ Log.info({indent: false, logLevel}, `+ ${pkg}@${targetVersion}`);
+ }
}
};
diff --git a/packages/studio-server/src/helpers/install-command.ts b/packages/studio-server/src/helpers/install-command.ts
index 2c4b698c15..691f22a342 100644
--- a/packages/studio-server/src/helpers/install-command.ts
+++ b/packages/studio-server/src/helpers/install-command.ts
@@ -11,7 +11,7 @@ export const getInstallCommand = ({
version: string;
additionalArgs: string[];
}): string[] => {
- const pkgList = packages.map((p) => `${p}@${version}`);
+ const pkgList = packages.map((p) => (version ? `${p}@${version}` : p));
const commands: {[key in PackageManager]: string[]} = {
npm: [