(
fixture: string,
options: Options = {}
)
| 22 | // ─── Vite ───────────────────────────────────────────────────────────────────── |
| 23 | |
| 24 | async function buildWithVite( |
| 25 | fixture: string, |
| 26 | options: Options = {} |
| 27 | ): Promise<string> { |
| 28 | const outDir = mkdtempSync(join(tmpdir(), 'unplugin-vite-')) |
| 29 | const result = await viteBuild({ |
| 30 | root: import.meta.dirname, |
| 31 | mode: 'production', |
| 32 | logLevel: 'silent', |
| 33 | build: { |
| 34 | write: false, |
| 35 | lib: { |
| 36 | entry: fixturePath(fixture), |
| 37 | formats: ['es'], |
| 38 | }, |
| 39 | rolldownOptions: { |
| 40 | external: [ |
| 41 | 'react', |
| 42 | 'react/jsx-runtime', |
| 43 | 'react/jsx-dev-runtime', |
| 44 | 'react-intl', |
| 45 | ], |
| 46 | }, |
| 47 | minify: false, |
| 48 | outDir, |
| 49 | }, |
| 50 | plugins: [vitePlugin(options)], |
| 51 | }) |
| 52 | |
| 53 | const output = Array.isArray(result) ? result[0] : result |
| 54 | if ('output' in output) { |
| 55 | const chunk = output.output.find( |
| 56 | (o: any) => o.type === 'chunk' && o.isEntry |
| 57 | ) as any |
| 58 | // Sanitize sandbox-specific paths for stable snapshots |
| 59 | return (chunk?.code ?? '').replace( |
| 60 | /var _jsxFileName = "[^"]*"/g, |
| 61 | 'var _jsxFileName = "<source>"' |
| 62 | ) |
| 63 | } |
| 64 | throw new Error('Unexpected Vite build result') |
| 65 | } |
| 66 | |
| 67 | // ─── Rollup ─────────────────────────────────────────────────────────────────── |
| 68 |
no test coverage detected