Skip to content

πŸŽ₯ Make videos programmatically with React

`@remotion/studio-server`: Use bunx to install skills in Bun projects

Jonny Burger3ff7290e8bee
diff --git a/packages/studio-server/src/preview-server/routes/install-remotion-skill.ts b/packages/studio-server/src/preview-server/routes/install-remotion-skill.ts
index 3a3235a62c..6dd23824f7 100644
--- a/packages/studio-server/src/preview-server/routes/install-remotion-skill.ts
+++ b/packages/studio-server/src/preview-server/routes/install-remotion-skill.ts
@@ -7,6 +7,7 @@ import type {
import {getPackageManagerSpawnOptions} from '../../helpers/package-manager-spawn-options';
import {remotionSkillNames} from '../../remotion-skill-names';
import type {ApiHandler} from '../api-types';
+import {getPackageManager} from '../get-package-manager';
import {getRemotionSkillsInfo} from './remotion-skills-info';
const installingInProjects = new Set<string>();
@@ -26,31 +27,48 @@ export const installRemotionSkillHandler: ApiHandler<
}
installingInProjects.add(remotionRoot);
- const args = [
- '--yes',
- '--loglevel=error',
- 'add',
- `remotion-dev/skills@${skill}`,
- '--yes',
- ];
+ const packageManager = getPackageManager({
+ remotionRoot,
+ packageManager: undefined,
+ dirUp: 0,
+ logLevel,
+ });
+ const useBunx =
+ packageManager !== 'unknown' && packageManager.manager === 'bun';
+ const executable = useBunx
+ ? 'bunx'
+ : process.platform === 'win32'
+ ? 'npx.cmd'
+ : 'npx';
+ const args = useBunx
+ ? [
+ '--silent',
+ 'add',
+ `remotion-dev/skills@${skill}`,
+ '--yes',
+ ]
+ : [
+ '--yes',
+ '--loglevel=error',
+ 'add',
+ `remotion-dev/skills@${skill}`,
+ '--yes',
+ ];
RenderInternals.Log.info(
{indent: false, logLevel},
- RenderInternals.chalk.gray(`╭─ npx ${args.join(' ')}`),
+ RenderInternals.chalk.gray(`╭─ ${executable} ${args.join(' ')}`),
);
const time = Date.now();
try {
await new Promise<void>((resolve, reject) => {
- const child = spawn(
- process.platform === 'win32' ? 'npx.cmd' : 'npx',
- args,
- {
- cwd: remotionRoot,
- env: {...process.env, DISABLE_TELEMETRY: '1'},
- stdio: ['ignore', 'pipe', 'pipe'],
- ...getPackageManagerSpawnOptions(),
- },
- );
+ const child = spawn(executable, args, {
+ cwd: remotionRoot,
+ env: {...process.env, DISABLE_TELEMETRY: '1'},
+ stdio: ['ignore', 'pipe', 'pipe'],
+ ...getPackageManagerSpawnOptions(),
+ });
let output = '';
const onData = (data: Buffer) => {
output = (output + data.toString()).slice(-8000);
diff --git a/packages/studio-server/src/test/install-remotion-skill.test.ts b/packages/studio-server/src/test/install-remotion-skill.test.ts
index 766e5bd147..14fad6e223 100644
--- a/packages/studio-server/src/test/install-remotion-skill.test.ts
+++ b/packages/studio-server/src/test/install-remotion-skill.test.ts
@@ -14,16 +14,21 @@ test.skipIf(process.platform === 'win32')(
const previousPath = process.env.PATH;
const bin = path.join(root, 'bin');
await mkdir(bin);
- const npx = path.join(bin, 'npx');
+ await writeFile(path.join(root, 'bun.lock'), '');
+ const bunx = path.join(bin, 'bunx');
await writeFile(
- npx,
+ bunx,
`#!${process.execPath}
const fs = require('node:fs');
const path = require('node:path');
const args = process.argv.slice(2);
fs.writeFileSync(
'install-call.json',
- JSON.stringify({args, disableTelemetry: process.env.DISABLE_TELEMETRY}),
+ JSON.stringify({
+ args,
+ disableTelemetry: process.env.DISABLE_TELEMETRY,
+ launcher: path.basename(process.argv[1]),
+ }),
);
if (fs.existsSync('fail')) {
process.stderr.write('Could not download skills');
@@ -36,6 +41,15 @@ if (fs.existsSync('fail')) {
fs.mkdirSync(directory, {recursive: true});
fs.writeFileSync(path.join(directory, 'SKILL.md'), '# Installed skill');
}
+`,
+ );
+ await chmod(bunx, 0o755);
+ const npx = path.join(bin, 'npx');
+ await writeFile(
+ npx,
+ `#!${process.execPath}
+process.stderr.write('npx should not be used for a Bun project');
+process.exit(1);
`,
);
await chmod(npx, 0o755);
@@ -107,14 +121,14 @@ if (fs.existsSync('fail')) {
),
).toEqual({
args: [
- '--yes',
- '--loglevel=error',
+ '--silent',
'add',
'remotion-dev/skills@remotion-interactivity',
'--yes',
],
disableTelemetry: '1',
+ launcher: 'bunx',
});
} finally {
process.env.PATH = previousPath;