Skip to content

Auto-fix config.dirs of /trigger and /src/trigger #1665

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 1 commit into from
Feb 5, 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/lovely-toys-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Auto-fix /trigger or /src/trigger config.dirs to relative paths to prevent misconfiguration from preventing dev CLI from working
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
"cwd": "${workspaceFolder}/references/init-shell",
"sourceMaps": true
},
{
"type": "node-terminal",
"request": "launch",
"name": "Debug V3 init dev CLI",
"command": "pnpm exec trigger dev",
"cwd": "${workspaceFolder}/references/init-shell",
"sourceMaps": true
},
{
"type": "node-terminal",
"request": "launch",
Expand Down
19 changes: 16 additions & 3 deletions packages/cli-v3/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ async function resolveConfig(

let dirs = config.dirs ? config.dirs : await autoDetectDirs(workingDir);

dirs = dirs.map((dir) => (isAbsolute(dir) ? relative(workingDir, dir) : dir));
dirs = dirs.map((dir) => resolveTriggerDir(dir, workingDir));

const mergedConfig = defu(
{
workingDir: packageJsonPath ? dirname(packageJsonPath) : cwd,
workingDir,
configFile: result.configFile,
packageJsonPath,
tsconfigPath,
Expand Down Expand Up @@ -187,11 +187,24 @@ async function resolveConfig(

return {
...mergedConfig,
dirs: Array.from(new Set(mergedConfig.dirs)),
dirs: Array.from(new Set(dirs)),
instrumentedPackageNames: getInstrumentedPackageNames(mergedConfig),
};
}

function resolveTriggerDir(dir: string, workingDir: string): string {
if (isAbsolute(dir)) {
// If dir is `/trigger` or `/src/trigger`, we should add a `.` to make it relative to the working directory
if (dir === "/trigger" || dir === "/src/trigger") {
return `.${dir}`;
} else {
return relative(workingDir, dir);
}
}

return dir;
}

async function safeResolveTsConfig(cwd: string) {
try {
return await resolveTSConfig(cwd);
Expand Down