Skip to content

Commit

Permalink
feat(vite-plugin-nitro): add workspaceRoot option to override `proc…
Browse files Browse the repository at this point in the history
…ess.cwd` (#764)
  • Loading branch information
ocombe authored Nov 21, 2023
1 parent 342c1ef commit 90cac1c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/platform/src/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export interface Options {
nitro?: NitroConfig;
apiPrefix?: string;
jit?: boolean;
workspaceRoot?: string;
}
6 changes: 5 additions & 1 deletion packages/platform/src/lib/platform-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
Expand Down
1 change: 1 addition & 0 deletions packages/vite-plugin-nitro/src/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Options {
prerender?: PrerenderOptions;
entryServer?: string;
index?: string;
workspaceRoot?: string;
}

export interface PrerenderOptions {
Expand Down
23 changes: 23 additions & 0 deletions packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`;

Expand Down

0 comments on commit 90cac1c

Please sign in to comment.