Lines 1-72javascript
1/** The Remotion project in a directory: whether it is ready, and its own @remotion/lambda,
2 * which is the version its function must have. When this package runs through npx it sits
3 * outside the project, so Remotion and its AWS SDK are resolved from the project, never from here. */
4import {existsSync, readFileSync} from 'node:fs';
5import {createRequire} from 'node:module';
6import {dirname, join, resolve} from 'node:path';
7import {pathToFileURL} from 'node:url';
8import {execFileSync} from 'node:child_process';
9import {FLOOR, compareVersions} from './version.mjs';
HighChild Process
Package source references child process execution.
src/project.mjsView on unpkg · L7 11const readJson = path => { try { return JSON.parse(readFileSync(path, 'utf8')); } catch { return null; } };
12const dependsOn = (pkg, name) => Boolean(pkg?.dependencies?.[name] ?? pkg?.devDependencies?.[name]);
13const parents = function* (dir) { for (let d = resolve(dir); ; d = dirname(d)) { yield d; if (dirname(d) === d) return; } };
15/** The directory of the nearest package.json at or above dir, as Remotion's own CLI finds its root; dir without one. */
16export function findProject(dir = process.cwd()) {
17 for (const d of parents(dir)) if (existsSync(join(d, 'package.json'))) return d;
21const MANAGERS = [['pnpm-lock.yaml', 'pnpm install', 'pnpm add'], ['yarn.lock', 'yarn install', 'yarn add'],
22 ['bun.lock', 'bun install', 'bun add'], ['bun.lockb', 'bun install', 'bun add'], ['package-lock.json', 'npm install', 'npm install']];
23const EXACT = {'yarn add': 'yarn add --exact', 'bun add': 'bun add --exact'};
25/** Commands of the package manager whose lockfile is nearest, npm without one: install, add at an
26 * exact version as Remotion's packages need, and addRange for a package that may move on. */
27export function packageManager(dir) {
33/** A package resolved from dir's own node_modules, or a workspace root's above it. Node also
34 * walks up into unrelated parents, which would count a project cloned into a directory with
35 * its own Remotion as installed; those are not accepted. */
36function ownPackage(dir, name) {
37 for (const d of parents(dir)) {
38 const file = join(d, 'node_modules', name, 'package.json');
39 if (existsSync(file)) return d === resolve(dir) || readJson(join(d, 'package.json'))?.workspaces ? file : null;
43const installedVersion = (dir, name) => { const file = ownPackage(dir, name); return file ? readJson(file)?.version ?? null : null; };
45// Remotion's common entry points, in its own order. Without @remotion/cli no remotion.config can be in
46// effect, since a config imports from it, and these paths are then all of Remotion's rule.
47const ENTRY_CANDIDATES = ['src', 'remotion', 'src/remotion'].flatMap(d => (d === 'src' ? ['ts', 'tsx', 'js', 'mjs'] : ['tsx',
48const NO_ENTRY = 'no Remotion entry point: none set in remotion.config, and no src/index.ts or other common path';
50/** The project's @remotion/cli: its own, or the one its @remotion/lambda depends on, which strict
51 * layouts such as pnpm do not show from the project root. */
52function cliPath(dir) {
53 if (ownPackage(dir, '@remotion/cli')) return createRequire(join(dir, 'package.json')).resolve('@remotion/cli');
54 const lambda = ownPackage(dir, '@remotion/lambda');
MediumDynamic Require
Package source references dynamic require/import behavior.
src/project.mjsView on unpkg · L52 55 try { return lambda ? createRequire(lambda).resolve('@remotion/cli') : null; } catch { return null; }
58// Runs in a process of its own, in the project: Remotion refuses to load twice into one process, and
59// ours may go on to load another project's version.
61const {CliInternals} = require(process.argv[1]);
62const done = result => process.stdout.write('\\n' + JSON.stringify(result) + '\\n');
63const dir = process.argv[2];
64CliInternals.loadConfig(dir)
65 .then(() => done({file: CliInternals.findEntryPoint({args: [], logLevel: 'error', remotionRoot: dir, allowDirectory: false}).file}))
66 .catch(error => done({error: String(error.message).split('\\n')[0]}));
69/** The entry point as Remotion finds it. With the project's @remotion/cli, that CLI decides: set in
70 * remotion.config, else a common path such as src/index.ts. Without one, the common paths. */
71export function findEntryPoint(dir) {
72 const cli = cliPath(dir);