Skip to content

Added experimental_devProcessCwdInBuildDir config option #2269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/beige-horses-juggle.md
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions packages/cli-v3/src/dev/devSupervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,24 @@ 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,
worker: worker,
httpClient: this.options.client,
logLevel: this.options.args.logLevel,
taskRunProcessPool: this.taskRunProcessPool,
cwd,
onFinished: () => {
logger.debug("[DevSupervisor] Run finished", { runId: message.run.friendlyId });

Expand Down
6 changes: 4 additions & 2 deletions packages/cli-v3/src/dev/taskRunProcessPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -97,6 +98,7 @@ export class TaskRunProcessPool {
version,
availableCount,
busyCount,
workerManifest,
});

const newProcess = new TaskRunProcess({
Expand All @@ -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
Expand Down
11 changes: 9 additions & 2 deletions packages/cli-v3/src/entryPoints/dev-run-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type DevRunControllerOptions = {
onSubscribeToRunNotifications: (run: Run, snapshot: Snapshot) => void;
onUnsubscribeFromRunNotifications: (run: Run, snapshot: Snapshot) => void;
onFinished: () => void;
cwd?: string;
};

type Run = {
Expand All @@ -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:
| {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/v3/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down