Skip to content

Commit 2d1cd26

Browse files
committed
fix link override
1 parent 12fa278 commit 2d1cd26

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

scripts/tasks/sandbox-parts.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -537,20 +537,19 @@ export async function setupVitest(details: TemplateDetails, options: PassedOptio
537537
}
538538

539539
let fileContent = await readFile(join(sandboxDir, configFile), 'utf-8');
540-
// Insert resolve: { preserveSymlinks: true } as a sibling to plugins in the top-level config object
540+
541+
// Insert resolve: { preserveSymlinks: true } and optionally server.fs.allow as siblings to plugins
541542
// Handles both defineConfig({ ... }) and defineWorkspace([ ... , { ... }])
542543
fileContent = fileContent.replace(/(plugins\s*:\s*\[[^\]]*\],?)/, (match) => {
543-
// Insert resolve after plugins
544-
return `${match}\n resolve: {\n preserveSymlinks: true\n },`;
545-
});
544+
let replacement = `${match}\n resolve: {\n preserveSymlinks: true\n },`;
546545

547-
// In linked mode, add server.fs.allow to allow Vite to serve files from the monorepo root
548-
if (options.link) {
549-
fileContent = fileContent.replace(/(plugins\s*:\s*\[[^\]]*\],?)/, (match) => {
550-
// Insert server.fs.allow after plugins (alongside resolve)
551-
return `${match}\n server: {\n fs: {\n allow: ['../../..']\n }\n },`;
552-
});
553-
}
546+
// In linked mode, also add server.fs.allow to allow Vite to serve files from the monorepo root
547+
if (options.link) {
548+
replacement += `\n server: {\n fs: {\n allow: ['../../..']\n }\n },`;
549+
}
550+
551+
return replacement;
552+
});
554553

555554
// search for storybookTest({...}) and place `tags: 'vitest'` into it but tags option doesn't exist yet in the config. Also consider multi line
556555
const storybookTestRegex = /storybookTest\((\{[\s\S]*?\})\)/g;

0 commit comments

Comments
 (0)