Skip to content

Commit aedc4c8

Browse files
committed
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.
1 parent 8690878 commit aedc4c8

File tree

11 files changed

+365
-4
lines changed

11 files changed

+365
-4
lines changed

.changeset/beige-horses-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
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.

packages/cli-v3/src/dev/devSupervisor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,24 @@ class DevSupervisor implements WorkerRuntime {
353353
continue;
354354
}
355355

356+
logger.debug("[DevSupervisor] dequeueRuns. Creating run controller", {
357+
run: message.run.friendlyId,
358+
worker,
359+
config: this.options.config,
360+
});
361+
362+
const cwd = this.options.config.experimental_devProcessCwdInBuildDir
363+
? worker.build.outputPath
364+
: undefined;
365+
356366
//new run
357367
runController = new DevRunController({
358368
runFriendlyId: message.run.friendlyId,
359369
worker: worker,
360370
httpClient: this.options.client,
361371
logLevel: this.options.args.logLevel,
362372
taskRunProcessPool: this.taskRunProcessPool,
373+
cwd,
363374
onFinished: () => {
364375
logger.debug("[DevSupervisor] Run finished", { runId: message.run.friendlyId });
365376

packages/cli-v3/src/dev/taskRunProcessPool.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export class TaskRunProcessPool {
4747
workerManifest: WorkerManifest,
4848
serverWorker: ServerBackgroundWorker,
4949
machineResources: MachinePresetResources,
50-
env?: Record<string, string>
50+
env?: Record<string, string>,
51+
cwd?: string
5152
): Promise<{ taskRunProcess: TaskRunProcess; isReused: boolean }> {
5253
const version = serverWorker.version || "unknown";
5354

@@ -97,6 +98,7 @@ export class TaskRunProcessPool {
9798
version,
9899
availableCount,
99100
busyCount,
101+
workerManifest,
100102
});
101103

102104
const newProcess = new TaskRunProcess({
@@ -107,7 +109,7 @@ export class TaskRunProcessPool {
107109
},
108110
serverWorker,
109111
machineResources,
110-
cwd: this.options.cwd,
112+
cwd: cwd ?? this.options.cwd,
111113
}).initialize();
112114

113115
// Add to busy processes for this version

packages/cli-v3/src/entryPoints/dev-run-controller.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type DevRunControllerOptions = {
3131
onSubscribeToRunNotifications: (run: Run, snapshot: Snapshot) => void;
3232
onUnsubscribeFromRunNotifications: (run: Run, snapshot: Snapshot) => void;
3333
onFinished: () => void;
34+
cwd?: string;
3435
};
3536

3637
type Run = {
@@ -50,6 +51,7 @@ export class DevRunController {
5051
private readonly heartbeatIntervalSeconds: number;
5152
private readonly snapshotPoller: IntervalService;
5253
private readonly snapshotPollIntervalSeconds: number;
54+
private readonly cwd?: string;
5355

5456
private state:
5557
| {
@@ -77,7 +79,7 @@ export class DevRunController {
7779
this.worker = opts.worker;
7880
this.heartbeatIntervalSeconds = opts.heartbeatIntervalSeconds || 20;
7981
this.snapshotPollIntervalSeconds = 5;
80-
82+
this.cwd = opts.cwd;
8183
this.httpClient = opts.httpClient;
8284

8385
this.snapshotPoller = new IntervalService({
@@ -607,6 +609,10 @@ export class DevRunController {
607609

608610
this.snapshotPoller.start();
609611

612+
logger.debug("getProcess", {
613+
build: this.opts.worker.build,
614+
});
615+
610616
// Get process from pool instead of creating new one
611617
const { taskRunProcess, isReused } = await this.opts.taskRunProcessPool.getProcess(
612618
this.opts.worker.manifest,
@@ -621,7 +627,8 @@ export class DevRunController {
621627
TRIGGER_WORKER_MANIFEST_PATH: join(this.opts.worker.build.outputPath, "index.json"),
622628
RUN_WORKER_SHOW_LOGS: this.opts.logLevel === "debug" ? "true" : "false",
623629
TRIGGER_WORKER_VERSION: this.opts.worker.serverWorker?.version,
624-
}
630+
},
631+
this.cwd
625632
);
626633

627634
this.taskRunProcess = taskRunProcess;

packages/core/src/v3/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ export type TriggerConfig = {
259259
devMaxPoolSize?: number;
260260
};
261261

262+
/**
263+
* @default false
264+
* @description When running the dev CLI, set the current working directory to the build directory.
265+
*
266+
* Currently, the process.cwd() is set to the root of the project.
267+
*/
268+
experimental_devProcessCwdInBuildDir?: boolean;
269+
262270
/**
263271
* @deprecated Use `dirs` instead
264272
*/

pnpm-lock.yaml

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"model": "claude-3-5-sonnet-20240620"
3+
}

references/claude-code/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "references-claude-code",
3+
"private": true,
4+
"type": "module",
5+
"devDependencies": {
6+
"trigger.dev": "workspace:*"
7+
},
8+
"dependencies": {
9+
"@trigger.dev/build": "workspace:*",
10+
"@trigger.dev/sdk": "workspace:*",
11+
"@anthropic-ai/claude-code": "^1.0.31",
12+
"zod": "3.23.8",
13+
"ai": "4.3.16"
14+
},
15+
"scripts": {
16+
"dev": "trigger dev",
17+
"deploy": "trigger deploy"
18+
}
19+
}

0 commit comments

Comments
 (0)