🎥 Make videos programmatically with React
only call process.chdir if in main thread
Jonny Burger9f755465def3
diff --git a/packages/bundler/src/bundle.ts b/packages/bundler/src/bundle.tsindex 4b502026be..2a155904c4 100644--- a/packages/bundler/src/bundle.ts+++ b/packages/bundler/src/bundle.ts@@ -4,6 +4,7 @@ import path from 'path';import type {WebpackOverrideFn} from 'remotion';import {promisify} from 'util';import webpack from 'webpack';+import {isMainThread} from 'worker_threads';import {copyDir} from './copy-dir';import {indexHtml} from './index-html';import {webpackConfig} from './webpack-config';@@ -84,9 +85,13 @@ export const bundle = async (const outDir = await prepareOutDir(options?.outDir ?? null);// The config might use an override which might use- // `process.cwd()`. The context should always be the Remotion root+ // `process.cwd()`. The context should always be the Remotion root.+ // This is not supported in worker threads (used for tests)const currentCwd = process.cwd();- process.chdir(resolvedRemotionRoot);+ if (isMainThread) {+ process.chdir(resolvedRemotionRoot);+ }+const [, config] = getConfig({outDir,entryPoint,@@ -96,7 +101,10 @@ export const bundle = async (});const output = await promisified([config]);- process.chdir(currentCwd);+ if (isMainThread) {+ process.chdir(currentCwd);+ }+if (!output) {throw new Error('Expected webpack output');}diff --git a/packages/cli/src/load-config.ts b/packages/cli/src/load-config.tsindex 1eebacc96b..7997726934 100644--- a/packages/cli/src/load-config.ts+++ b/packages/cli/src/load-config.ts@@ -2,6 +2,7 @@ import {BundlerInternals} from '@remotion/bundler';import fs from 'fs';import os from 'os';import path from 'path';+import {isMainThread} from 'worker_threads';import {Log} from './log';export const loadConfigFile = async (@@ -56,11 +57,18 @@ export const loadConfigFile = async (const currentCwd = process.cwd();- // The config file is always executed from the Remotion root, if `process.cwd()` is being used- process.chdir(remotionRoot);+ // The config file is always executed from the Remotion root, if `process.cwd()` is being used. We cannot enforce this in worker threads used for testing+ if (isMainThread) {+ process.chdir(remotionRoot);+ }++ // Exectute the contents of the config file// eslint-disable-next-line no-evaleval(file);- process.chdir(currentCwd);++ if (isMainThread) {+ process.chdir(currentCwd);+ }await fs.promises.unlink(out);return resolved;