@@ -587,17 +587,20 @@ export async function setupVitest(details: TemplateDetails, options: PassedOptio
587587
588588 let fileContent = await readFile ( join ( sandboxDir , configFile ) , 'utf-8' ) ;
589589
590- // Insert resolve: { preserveSymlinks: true } and optionally server.fs.allow as siblings to plugins
591- // Handles both defineConfig({ ... }) and defineWorkspace([ ... , { ... }])
592- fileContent = fileContent . replace ( / ( p l u g i n s \s * : \s * \[ [ ^ \] ] * \] , ? ) / , ( match ) => {
593- let replacement = `${ match } \n resolve: {\n preserveSymlinks: true\n },` ;
590+ // Insert resolve: { preserveSymlinks: true } and optionally server.fs.allow as siblings to
591+ // plugins. Handles both defineConfig({ ... }) and defineWorkspace([ ... , { ... }]). Anchored
592+ // on the `plugins:` key (injecting before it) instead of matching the whole array: plugin code
593+ // may contain `]` (e.g. the regex literal in the sveltekit template), which a bracket-counting
594+ // regex like `\[[^\]]*\]` would cut short, splicing the injection into the middle of it.
595+ fileContent = fileContent . replace ( / ^ ( [ \t ] * ) p l u g i n s \s * : / m, ( match , indent ) => {
596+ let injected = `${ indent } resolve: {\n${ indent } preserveSymlinks: true\n${ indent } },\n` ;
594597
595598 // In linked mode, also add server.fs.allow to allow Vite to serve files from the monorepo root
596599 if ( options . link ) {
597- replacement += `\n server: {\n fs: {\n allow: ['../../..']\n }\n }, ` ;
600+ injected += `${ indent } server: {\n${ indent } fs: {\n${ indent } allow: ['../../..']\n${ indent } }\n${ indent } },\n ` ;
598601 }
599602
600- return replacement ;
603+ return ` ${ injected } ${ match } ` ;
601604 } ) ;
602605
603606 // search for storybookTest({...}) and place `tags: 'vitest'` into it but tags option doesn't exist yet in the config. Also consider multi line
0 commit comments