fix(companion): resolve fixtures path correctly for both dev and built modes

This commit is contained in:
2025-11-22 17:31:21 +01:00
parent 515aef71bb
commit 99fa06e12b
2 changed files with 116 additions and 61 deletions

View File

@@ -20,29 +20,30 @@ import type { IFixtureServerService } from '@/packages/infrastructure/adapters/a
/**
* Resolve the fixtures path relative to the monorepo root.
* In Electron, app.getAppPath() returns the path to the app's main directory
* (e.g., apps/companion/dist/main in development, or the asar in production).
* We navigate up to find the monorepo root and then join with the resources path.
* Uses __dirname to determine the navigation depth based on whether we're
* running from source (dev mode) or built output (dist mode).
*
* Path breakdown from apps/companion/dist/main:
* - Level 1: apps/companion/dist (../)
* - Level 2: apps/companion (../../)
* - Level 3: apps (../../../)
* - Level 4: gridpilot (monorepo root) (../../../../)
* Path breakdown:
* - Dev mode: apps/companion/main → 3 levels to root
* - Built mode: apps/companion/dist/main → 4 levels to root
*
* @param configuredPath - The path configured (may be relative or absolute)
* @param appPath - The app path from electron (app.getAppPath())
* @param dirname - The directory name (__dirname) of the calling module
* @returns Resolved absolute path
*/
export function resolveFixturesPath(configuredPath: string, appPath: string): string {
export function resolveFixturesPath(configuredPath: string, dirname: string): string {
if (path.isAbsolute(configuredPath)) {
return configuredPath;
}
const projectRoot = path.resolve(appPath, '../../../../');
const resolvedPath = path.join(projectRoot, configuredPath);
// Determine navigation depth based on whether we're in dist/ or source
// Dev mode: apps/companion/main → 3 levels to root
// Built mode: apps/companion/dist/main → 4 levels to root
const isBuiltMode = dirname.includes(`${path.sep}dist${path.sep}`);
const levelsUp = isBuiltMode ? '../../../../' : '../../../';
const projectRoot = path.resolve(dirname, levelsUp);
return resolvedPath;
return path.join(projectRoot, configuredPath);
}
export interface BrowserConnectionResult {
@@ -196,10 +197,10 @@ export class DIContainer {
/**
* Resolve the fixtures path relative to the monorepo root.
* Uses the exported resolveFixturesPath function with app.getAppPath().
* Uses the exported resolveFixturesPath function with __dirname.
*/
private resolveFixturesPathInternal(configuredPath: string): string {
return resolveFixturesPath(configuredPath, app.getAppPath());
return resolveFixturesPath(configuredPath, __dirname);
}
/**
@@ -226,7 +227,7 @@ export class DIContainer {
this.logger.debug('Fixture server path resolution', {
configuredPath: config.fixtureServer.fixturesPath,
appPath: app.getAppPath(),
dirname: __dirname,
resolvedPath: fixturesPath
});