Skip to content

Commit 8c68e83

Browse files
committed
chore(build): add esbuild minify validation check
Add validation script to ensure esbuild config maintains minify: false. Minification breaks ESM/CJS interop and makes debugging harder.
1 parent 06029e4 commit 8c68e83

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

scripts/check.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,27 @@ async function main() {
242242
}
243243
}
244244

245+
// Run esbuild minify validation check
246+
if (runAll) {
247+
if (!quiet) {
248+
logger.progress('Validating esbuild minify setting')
249+
}
250+
exitCode = await runCommandQuiet('node', [
251+
'scripts/validate-esbuild-minify.mjs',
252+
]).then(r => r.exitCode)
253+
if (exitCode !== 0) {
254+
if (!quiet) {
255+
logger.error('esbuild minify validation failed')
256+
}
257+
process.exitCode = exitCode
258+
return
259+
}
260+
if (!quiet) {
261+
logger.clearLine().done('esbuild minify validated')
262+
logger.error('')
263+
}
264+
}
265+
245266
if (!quiet) {
246267
logger.success('All checks passed')
247268
printFooter()
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

Comments
 (0)