import {spawnSync} from 'node:child_process'; import {fileURLToPath} from 'node:url'; const viteCliPath = fileURLToPath(new URL('./vite-cli.mjs', import.meta.url)); const args = [viteCliPath, 'build', ...process.argv.slice(2)]; const result = spawnSync(process.execPath, args, { cwd: process.cwd(), encoding: 'utf8', }); if (result.stdout) { process.stdout.write(result.stdout); } if (result.stderr) { process.stderr.write(result.stderr); } if ((result.status ?? 0) !== 0) { process.exit(result.status ?? 1); } const warningPattern = /\bwarn(?:ing)?\b/i; const ignoredWarningPatterns = [ /ExperimentalWarning/u, ]; const warningLines = `${result.stdout ?? ''}\n${result.stderr ?? ''}` .split(/\r?\n/u) .map(line => line.trim()) .filter(line => line.length > 0) .filter(line => warningPattern.test(line)) .filter(line => !ignoredWarningPatterns.some(pattern => pattern.test(line))); if (warningLines.length > 0) { console.error('Build gate failed because warnings were emitted:'); [...new Set(warningLines)].forEach(line => console.error(`- ${line}`)); process.exit(1); }