mirror of
				https://github.com/mastodon/mastodon.git
				synced 2025-10-30 20:51:33 +00:00 
			
		
		
		
	Split vite & vitest configs, because vitest is only in devDependencies, so loading it from the config when yarn uses --production fails the compilation
				
					
				
			This commit is contained in:
		
							parent
							
								
									9dfb9d96be
								
							
						
					
					
						commit
						3d2ec6facd
					
				|  | @ -1,5 +1,3 @@ | |||
| /// <reference types="vitest/config" />
 | ||||
| 
 | ||||
| import fs from 'node:fs/promises'; | ||||
| import path from 'node:path'; | ||||
| 
 | ||||
|  | @ -11,12 +9,7 @@ import { analyzer } from 'vite-bundle-analyzer'; | |||
| import RailsPlugin from 'vite-plugin-rails'; | ||||
| import { VitePWA } from 'vite-plugin-pwa'; | ||||
| 
 | ||||
| import { | ||||
|   configDefaults, | ||||
|   defineConfig, | ||||
|   ViteUserConfig, | ||||
|   UserConfigFnPromise, | ||||
| } from 'vitest/config'; | ||||
| import { defineConfig, UserConfigFnPromise, UserConfig } from 'vite'; | ||||
| import postcssPresetEnv from 'postcss-preset-env'; | ||||
| 
 | ||||
| import { MastodonServiceWorkerLocales } from './config/vite/plugin-sw-locales'; | ||||
|  | @ -24,7 +17,7 @@ import { MastodonServiceWorkerLocales } from './config/vite/plugin-sw-locales'; | |||
| const jsRoot = path.resolve(__dirname, 'app/javascript'); | ||||
| const entrypointRoot = path.resolve(jsRoot, 'entrypoints'); | ||||
| 
 | ||||
| const config: UserConfigFnPromise = async ({ mode, command }) => { | ||||
| export const config: UserConfigFnPromise = async ({ mode, command }) => { | ||||
|   const entrypointFiles = await fs.readdir(entrypointRoot); | ||||
|   const entrypoints: Record<string, string> = entrypointFiles.reduce( | ||||
|     (acc, file) => { | ||||
|  | @ -143,24 +136,7 @@ const config: UserConfigFnPromise = async ({ mode, command }) => { | |||
|       optimizeLodashImports() as PluginOption, | ||||
|       !!process.env.ANALYZE_BUNDLE_SIZE && analyzer({ analyzerMode: 'static' }), | ||||
|     ], | ||||
|     test: { | ||||
|       environment: 'jsdom', | ||||
|       include: [ | ||||
|         ...configDefaults.include, | ||||
|         '**/__tests__/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', | ||||
|       ], | ||||
|       exclude: [ | ||||
|         ...configDefaults.exclude, | ||||
|         '**/node_modules/**', | ||||
|         'vendor/**', | ||||
|         'config/**', | ||||
|         'log/**', | ||||
|         'public/**', | ||||
|         'tmp/**', | ||||
|       ], | ||||
|       globals: true, | ||||
|     }, | ||||
|   } satisfies ViteUserConfig; | ||||
|   } satisfies UserConfig; | ||||
| }; | ||||
| 
 | ||||
| export default defineConfig(config); | ||||
|  |  | |||
							
								
								
									
										26
									
								
								vitest.config.mts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								vitest.config.mts
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| import { configDefaults, defineConfig } from 'vitest/config'; | ||||
| 
 | ||||
| import { config as viteConfig } from './vite.config.mjs'; | ||||
| 
 | ||||
| export default defineConfig(async (context) => { | ||||
|   return { | ||||
|     ...(await viteConfig(context)), | ||||
|     test: { | ||||
|       environment: 'jsdom', | ||||
|       include: [ | ||||
|         ...configDefaults.include, | ||||
|         '**/__tests__/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', | ||||
|       ], | ||||
|       exclude: [ | ||||
|         ...configDefaults.exclude, | ||||
|         '**/node_modules/**', | ||||
|         'vendor/**', | ||||
|         'config/**', | ||||
|         'log/**', | ||||
|         'public/**', | ||||
|         'tmp/**', | ||||
|       ], | ||||
|       globals: true, | ||||
|     }, | ||||
|   }; | ||||
| }); | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Renaud Chaput
						Renaud Chaput