Skip to content

Commit

Permalink
Auto-fix config.dirs of /trigger and /src/trigger (#1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericallam authored Feb 5, 2025
1 parent e35b6f5 commit 99d3815
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
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

0 comments on commit 99d3815

Please sign in to comment.