diff --git a/apps/desktop/main/protocol.ts b/apps/desktop/main/protocol.ts index 460b153a..cc3c75b9 100644 --- a/apps/desktop/main/protocol.ts +++ b/apps/desktop/main/protocol.ts @@ -59,6 +59,8 @@ let activeThemeId = 'peek'; // Root directory (set during init) let rootDir: string; +// node_modules lives at the repo root (two levels above apps/desktop) +let nodeModulesDir: string; // Bare import map for resolving npm package imports // Maps bare specifiers (e.g., 'lit') to node_modules paths @@ -287,7 +289,7 @@ async function handleProtocolRequest(req: Request): Promise { if (resolvedPath) { DEBUG && console.log(`[protocol] Resolved bare import: ${bareSpecifier} -> ${resolvedPath}`); - const absolutePath = path.resolve(rootDir, resolvedPath); + const absolutePath = path.resolve(nodeModulesDir, resolvedPath); return fetchFile(absolutePath, req.url); } @@ -675,7 +677,9 @@ async function handleProtocolRequest(req: Request): Promise { relativePath = path.join(host, pathname); } - const absolutePath = path.resolve(rootDir, relativePath); + // node_modules are at the repo root, not under apps/desktop + const resolveBase = (host === 'node_modules') ? nodeModulesDir : rootDir; + const absolutePath = path.resolve(resolveBase, relativePath); return fetchFile(absolutePath, req.url); } catch (err) { @@ -701,6 +705,8 @@ async function handleProtocolRequest(req: Request): Promise { */ export function initProtocol(appRootDir: string): void { rootDir = appRootDir; + // node_modules is at the repo root (../../ from apps/desktop) + nodeModulesDir = path.join(rootDir, '../..'); protocol.handle(APP_SCHEME, handleProtocolRequest); } diff --git a/apps/desktop/tests/components/components.spec.ts b/apps/desktop/tests/components/components.spec.ts index 8608efc4..82de72f0 100644 --- a/apps/desktop/tests/components/components.spec.ts +++ b/apps/desktop/tests/components/components.spec.ts @@ -15,7 +15,7 @@ import { readFileSync, existsSync } from 'fs'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -const ROOT = path.join(__dirname, '../..'); +const ROOT = path.join(__dirname, '../../../..'); // Simple static file server let server: ReturnType; @@ -39,7 +39,7 @@ function startServer(): Promise { } // Handle component imports - if (req.url?.startsWith('/app/components/')) { + if (req.url?.startsWith('/apps/desktop/renderer/') || req.url?.startsWith('/app/components/')) { filePath = path.join(ROOT, req.url); } diff --git a/apps/desktop/tests/components/test-page.html b/apps/desktop/tests/components/test-page.html index 6c7ef5c3..0a76d937 100644 --- a/apps/desktop/tests/components/test-page.html +++ b/apps/desktop/tests/components/test-page.html @@ -290,7 +290,7 @@