diff --git a/packages/platform/src/lib/options.ts b/packages/platform/src/lib/options.ts index c338c82b9..64dfb570b 100644 --- a/packages/platform/src/lib/options.ts +++ b/packages/platform/src/lib/options.ts @@ -30,4 +30,5 @@ export interface Options { nitro?: NitroConfig; apiPrefix?: string; jit?: boolean; + workspaceRoot?: string; } diff --git a/packages/platform/src/lib/platform-plugin.ts b/packages/platform/src/lib/platform-plugin.ts index e9c0b8844..fac8863ae 100644 --- a/packages/platform/src/lib/platform-plugin.ts +++ b/packages/platform/src/lib/platform-plugin.ts @@ -30,7 +30,11 @@ export function platformPlugin(opts: Options = {}): Plugin[] { (platformOptions.ssr ? ssrBuildPlugin() : false) as Plugin, ...routerPlugin(), ...contentPlugin(), - ...angular({ jit: platformOptions.jit, ...(opts?.vite ?? {}) }), + ...angular({ + jit: platformOptions.jit, + workspaceRoot: platformOptions.workspaceRoot, + ...(opts?.vite ?? {}), + }), ssrXhrBuildPlugin(), clearClientPageEndpointsPlugin(), ]; diff --git a/packages/vite-plugin-nitro/src/lib/options.ts b/packages/vite-plugin-nitro/src/lib/options.ts index 34cbd328d..14ff4dda2 100644 --- a/packages/vite-plugin-nitro/src/lib/options.ts +++ b/packages/vite-plugin-nitro/src/lib/options.ts @@ -10,6 +10,7 @@ export interface Options { prerender?: PrerenderOptions; entryServer?: string; index?: string; + workspaceRoot?: string; } export interface PrerenderOptions { diff --git a/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.spec.ts b/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.spec.ts index 381c51804..6e72692a7 100644 --- a/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.spec.ts +++ b/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.spec.ts @@ -205,6 +205,29 @@ describe('nitro', () => { ); }); + it('should use the workspace root option when it is set', async () => { + // Arrange + vi.mock('process'); + process.cwd = vi.fn().mockReturnValue('/some-other-root-directory'); + const { buildServerImportSpy } = await mockBuildFunctions(); + + const plugin = nitro({ workspaceRoot: '/custom-root-directory' }, {}); + + // Act + await runConfigAndCloseBundle(plugin); + + // Assert + expect(buildServerImportSpy).toHaveBeenCalledWith( + { workspaceRoot: '/custom-root-directory' }, + expect.objectContaining({ + output: { + dir: '/custom-root-directory/dist/analog', + publicDir: '/custom-root-directory/dist/analog/public', + }, + }) + ); + }); + it('should use the .vercel output paths when preset is vercel', async () => { // Arrange vi.mock('process'); diff --git a/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts b/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts index 5fe023243..2bae357a6 100644 --- a/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts +++ b/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts @@ -17,7 +17,7 @@ import { loadEsmModule } from './utils/load-esm'; let clientOutputPath = ''; export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] { - const workspaceRoot = process.cwd(); + const workspaceRoot = options?.workspaceRoot ?? process.cwd(); const isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST']; const apiPrefix = `/${nitroOptions?.runtimeConfig?.['apiPrefix'] ?? 'api'}`;