Skip to content
Open
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
11 changes: 8 additions & 3 deletions apps/daemon/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ import {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export function resolveProjectRoot(moduleDir: string): string {
const daemonDir = path.basename(moduleDir) === 'dist'
? path.dirname(moduleDir)
: moduleDir;
// When compiled, moduleDir is apps/daemon/dist → daemonDir is apps/daemon → root is ../../
// When tsx runs source, moduleDir is apps/daemon/src → daemonDir is apps/daemon → root is ../../
// In both cases we need to go 2 levels above the daemon package dir.
const basename = path.basename(moduleDir);
const daemonDir =
basename === 'dist' || basename === 'src'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now treats any src basename as apps/daemon/src, but the sidecar build can emit/import this file from apps/daemon/dist/src/server.js (tsconfig.sidecar.json sets rootDir: "." and includes both sidecar/**/*.ts and src/**/*.ts). In that runtime, moduleDir is .../apps/daemon/dist/src, so path.dirname(moduleDir) becomes .../apps/daemon/dist and path.resolve(daemonDir, '../..') resolves to .../apps instead of the repo root. Could you handle dist/src explicitly (or walk upward to the daemon package root/package.json) and add tests for both apps/daemon/src and apps/daemon/dist/src? 🚧

? path.dirname(moduleDir)
: moduleDir;
return path.resolve(daemonDir, '../..');
}

Expand Down