Skip to content

Commit 8d2b150

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 d193200 commit 8d2b150

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

scripts/check.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ async function main() {
4949
...(process.platform === 'win32' && { shell: true }),
5050
},
5151
},
52+
{
53+
args: ['scripts/validate-esbuild-minify.mjs'],
54+
command: 'node',
55+
options: {
56+
...(process.platform === 'win32' && { shell: true }),
57+
},
58+
},
5259
]
5360

5461
const exitCodes = await runParallel(checks)
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}:242`,
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}:270`,
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)