diff --git a/services/pascal-editor/apps/editor/next.config.ts b/services/pascal-editor/apps/editor/next.config.ts index 7e7ede40c..dd253c9bc 100644 --- a/services/pascal-editor/apps/editor/next.config.ts +++ b/services/pascal-editor/apps/editor/next.config.ts @@ -1,3 +1,5 @@ +import { existsSync } from 'node:fs' +import { createRequire } from 'node:module' import path from 'node:path' import { fileURLToPath } from 'node:url' import type { NextConfig } from 'next' @@ -5,7 +7,16 @@ import type { NextConfig } from 'next' const configuredBasePath = process.env.NEXT_PUBLIC_PASCAL_BASE_PATH?.trim() ?? '' const basePath = configuredBasePath ? `/${configuredBasePath.replace(/^\/+|\/+$/g, '')}` : undefined const pascalRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..') -const workspaceModule = (name: string) => path.resolve(pascalRoot, 'node_modules', name) +const resolveFromEditor = createRequire(import.meta.url).resolve + +function workspaceModule(name: string) { + let directory = path.dirname(resolveFromEditor(name)) + while (directory !== path.dirname(directory)) { + if (existsSync(path.join(directory, 'package.json'))) return directory + directory = path.dirname(directory) + } + throw new Error(`Could not resolve package root for ${name}`) +} const nextConfig: NextConfig = { basePath,