|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * @fileoverview Validates that esbuild configuration has minify: false. |
| 4 | + * Minification breaks ESM/CJS interop and makes debugging harder. |
| 5 | + */ |
| 6 | + |
| 7 | +import path from 'node:path' |
| 8 | +import { fileURLToPath } from 'node:url' |
| 9 | + |
| 10 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)) |
| 11 | +const rootPath = path.join(__dirname, '..') |
| 12 | + |
| 13 | +/** |
| 14 | + * Validate esbuild configuration has minify: false. |
| 15 | + */ |
| 16 | +async function validateEsbuildMinify() { |
| 17 | + const configPath = path.join(rootPath, '.config/esbuild.config.mjs') |
| 18 | + |
| 19 | + try { |
| 20 | + // Dynamic import of the esbuild config |
| 21 | + const config = await import(configPath) |
| 22 | + |
| 23 | + const violations = [] |
| 24 | + |
| 25 | + // Check buildConfig |
| 26 | + if (config.buildConfig) { |
| 27 | + if (config.buildConfig.minify !== false) { |
| 28 | + violations.push({ |
| 29 | + config: 'buildConfig', |
| 30 | + value: config.buildConfig.minify, |
| 31 | + message: 'buildConfig.minify must be false', |
| 32 | + location: `${configPath}:232`, |
| 33 | + }) |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + // Check watchConfig |
| 38 | + if (config.watchConfig) { |
| 39 | + if (config.watchConfig.minify !== false) { |
| 40 | + violations.push({ |
| 41 | + config: 'watchConfig', |
| 42 | + value: config.watchConfig.minify, |
| 43 | + message: 'watchConfig.minify must be false', |
| 44 | + location: `${configPath}:271`, |
| 45 | + }) |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + return violations |
| 50 | + } catch (error) { |
| 51 | + console.error(`Failed to load esbuild config: ${error.message}`) |
| 52 | + process.exitCode = 1 |
| 53 | + return [] |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +async function main() { |
| 58 | + const violations = await validateEsbuildMinify() |
| 59 | + |
| 60 | + if (violations.length === 0) { |
| 61 | + console.log('✓ esbuild minify validation passed') |
| 62 | + process.exitCode = 0 |
| 63 | + return |
| 64 | + } |
| 65 | + |
| 66 | + console.error('❌ esbuild minify validation failed\n') |
| 67 | + |
| 68 | + for (const violation of violations) { |
| 69 | + console.error(` ${violation.message}`) |
| 70 | + console.error(` Found: minify: ${violation.value}`) |
| 71 | + console.error(` Expected: minify: false`) |
| 72 | + console.error(` Location: ${violation.location}`) |
| 73 | + console.error('') |
| 74 | + } |
| 75 | + |
| 76 | + console.error('Minification breaks ESM/CJS interop and makes debugging harder.') |
| 77 | + console.error('') |
| 78 | + |
| 79 | + process.exitCode = 1 |
| 80 | +} |
| 81 | + |
| 82 | +main().catch(error => { |
| 83 | + console.error('Validation failed:', error) |
| 84 | + process.exitCode = 1 |
| 85 | +}) |
0 commit comments