Skip to content

Commit 124e99c

Browse files
committed
fix(transform,nuxt): use project rootDir for .domscribe/ artifacts in Nuxt
In Nuxt projects with a custom srcDir (e.g. srcDir: 'app/'), Vite's config.root is set to the source directory. The Vite plugin used this as the root for .domscribe/ artifacts, while the Nuxt module started the relay with nuxt.options.rootDir. This split the .domscribe/ directory across two locations, breaking relay/manifest coordination. Add a rootDir option to VitePluginOptions that overrides config.root for .domscribe/ path resolution. The Nuxt module passes nuxt.options.rootDir so all components write to the same project-level .domscribe/ directory.
1 parent 781171a commit 124e99c

5 files changed

Lines changed: 29 additions & 1 deletion

File tree

packages/domscribe-nuxt/src/module.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ describe('domscribeModule', () => {
342342
expect.objectContaining({
343343
debug: true,
344344
overlay: true,
345+
rootDir: '/test/project',
345346
relay: { port: 3001, autoStart: false },
346347
}),
347348
);

packages/domscribe-nuxt/src/module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export const domscribeModule = defineNuxtModule<DomscribeNuxtOptions>({
113113
() => {
114114
const plugin = domscribe({
115115
...options,
116+
rootDir: nuxt.options.rootDir,
116117
relay: { ...options.relay, autoStart: false },
117118
});
118119
// The Vite plugin defaults to `apply: 'serve'` (dev-only). During

packages/domscribe-transform/src/plugins/vite/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,13 @@ export interface VitePluginOptions {
4545
* @default true
4646
*/
4747
overlay?: boolean | OverlayPluginOptions;
48+
49+
/**
50+
* Override the root directory for `.domscribe/` artifacts (manifest,
51+
* transform cache, relay lock).
52+
*
53+
* When omitted, defaults to Vite's `config.root`. Needed when the Vite
54+
* root differs from the project root (e.g., Nuxt with a custom `srcDir`).
55+
*/
56+
rootDir?: string;
4857
}

packages/domscribe-transform/src/plugins/vite/vite.plugin.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,22 @@ describe('domscribe Vite plugin', () => {
317317
}).not.toThrow();
318318
});
319319

320+
it('should use rootDir option over config.root when provided', async () => {
321+
// Arrange — Nuxt sets config.root to srcDir, but rootDir points to project root
322+
const plugin = domscribe({ rootDir: '/project/root' });
323+
const config = createMockResolvedConfig({ root: '/project/root/app' });
324+
325+
// Act
326+
callHook(plugin.configResolved, {}, config);
327+
await callHook(plugin.buildStart);
328+
329+
// Assert — ManifestWriter should be initialized with the project root
330+
expect(mockWriterGetInstance).toHaveBeenCalledWith(
331+
'/project/root',
332+
expect.any(Object),
333+
);
334+
});
335+
320336
it('should handle being called multiple times', () => {
321337
// Arrange
322338
const plugin = domscribe();

packages/domscribe-transform/src/plugins/vite/vite.plugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function domscribe(options: VitePluginOptions = {}): Plugin {
3636
debug = false,
3737
relay: relayOptions = {},
3838
overlay: overlayOption = true,
39+
rootDir,
3940
} = options;
4041
const filter = createFilter(include, exclude);
4142

@@ -106,7 +107,7 @@ export function domscribe(options: VitePluginOptions = {}): Plugin {
106107
apply: 'serve', // Only run in development mode
107108

108109
configResolved(config) {
109-
rootContext = config.root;
110+
rootContext = rootDir ?? config.root;
110111
},
111112

112113
async buildStart() {

0 commit comments

Comments
 (0)