Added experimental_devProcessCwdInBuildDir config option (#2269)

* Added experimental_devProcessCwdInBuildDir config option

Added experimental_devProcessCwdInBuildDir config option to opt-in to new process.cwd behavior when executing tasks in the dev CLI. Currently process.cwd maps to the "root" of your trigger.dev project (the directory that contains your trigger.config.ts file). Setting experimental_devProcessCwdInBuildDir to true changes process.cwd to instead be the temporary build directory inside of the .trigger directory.

This makes it so the files added via the additionalFiles extension can be read using the same path in dev and deployed tasks.

* Remove claude code reference because it breaks windows tests 😡
This commit is contained in:
Eric Allam
2025-07-21 16:06:25 +01:00
committed by GitHub
parent 07980f8ebd
commit ff018718f7
5 changed files with 37 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---
Added experimental_devProcessCwdInBuildDir config option to opt-in to new process.cwd behavior when executing tasks in the dev CLI. Currently process.cwd maps to the "root" of your trigger.dev project (the directory that contains your trigger.config.ts file). Setting experimental_devProcessCwdInBuildDir to true changes process.cwd to instead be the temporary build directory inside of the .trigger directory.
+11
View File
@@ -353,6 +353,16 @@ class DevSupervisor implements WorkerRuntime {
continue;
}
logger.debug("[DevSupervisor] dequeueRuns. Creating run controller", {
run: message.run.friendlyId,
worker,
config: this.options.config,
});
const cwd = this.options.config.experimental_devProcessCwdInBuildDir
? worker.build.outputPath
: undefined;
//new run
runController = new DevRunController({
runFriendlyId: message.run.friendlyId,
@@ -360,6 +370,7 @@ class DevSupervisor implements WorkerRuntime {
httpClient: this.options.client,
logLevel: this.options.args.logLevel,
taskRunProcessPool: this.taskRunProcessPool,
cwd,
onFinished: () => {
logger.debug("[DevSupervisor] Run finished", { runId: message.run.friendlyId });
@@ -47,7 +47,8 @@ export class TaskRunProcessPool {
workerManifest: WorkerManifest,
serverWorker: ServerBackgroundWorker,
machineResources: MachinePresetResources,
env?: Record<string, string>
env?: Record<string, string>,
cwd?: string
): Promise<{ taskRunProcess: TaskRunProcess; isReused: boolean }> {
const version = serverWorker.version || "unknown";
@@ -97,6 +98,7 @@ export class TaskRunProcessPool {
version,
availableCount,
busyCount,
workerManifest,
});
const newProcess = new TaskRunProcess({
@@ -107,7 +109,7 @@ export class TaskRunProcessPool {
},
serverWorker,
machineResources,
cwd: this.options.cwd,
cwd: cwd ?? this.options.cwd,
}).initialize();
// Add to busy processes for this version
@@ -31,6 +31,7 @@ type DevRunControllerOptions = {
onSubscribeToRunNotifications: (run: Run, snapshot: Snapshot) => void;
onUnsubscribeFromRunNotifications: (run: Run, snapshot: Snapshot) => void;
onFinished: () => void;
cwd?: string;
};
type Run = {
@@ -50,6 +51,7 @@ export class DevRunController {
private readonly heartbeatIntervalSeconds: number;
private readonly snapshotPoller: IntervalService;
private readonly snapshotPollIntervalSeconds: number;
private readonly cwd?: string;
private state:
| {
@@ -77,7 +79,7 @@ export class DevRunController {
this.worker = opts.worker;
this.heartbeatIntervalSeconds = opts.heartbeatIntervalSeconds || 20;
this.snapshotPollIntervalSeconds = 5;
this.cwd = opts.cwd;
this.httpClient = opts.httpClient;
this.snapshotPoller = new IntervalService({
@@ -607,6 +609,10 @@ export class DevRunController {
this.snapshotPoller.start();
logger.debug("getProcess", {
build: this.opts.worker.build,
});
// Get process from pool instead of creating new one
const { taskRunProcess, isReused } = await this.opts.taskRunProcessPool.getProcess(
this.opts.worker.manifest,
@@ -621,7 +627,8 @@ export class DevRunController {
TRIGGER_WORKER_MANIFEST_PATH: join(this.opts.worker.build.outputPath, "index.json"),
RUN_WORKER_SHOW_LOGS: this.opts.logLevel === "debug" ? "true" : "false",
TRIGGER_WORKER_VERSION: this.opts.worker.serverWorker?.version,
}
},
this.cwd
);
this.taskRunProcess = taskRunProcess;
+8
View File
@@ -259,6 +259,14 @@ export type TriggerConfig = {
devMaxPoolSize?: number;
};
/**
* @default false
* @description When running the dev CLI, set the current working directory to the build directory.
*
* Currently, the process.cwd() is set to the root of the project.
*/
experimental_devProcessCwdInBuildDir?: boolean;
/**
* @deprecated Use `dirs` instead
*/