Skip to content

Commit 8ba859f

Browse files
committed
feat(build): enable validation scripts and improve robustness
Re-enable post-build validation scripts: - scripts/validate/esm-named-exports.mjs - Validates named exports - scripts/validate/dist-exports.mjs - Validates no .default access needed Improve esm-named-exports validation: - Handle require() errors gracefully instead of throwing - Allow empty exports for type-only files (*/types.js) - Better error messages for debugging These validations ensure 100% CJS/ESM compatibility is maintained in the build output, catching any regressions automatically.
1 parent 4a80cd3 commit 8ba859f

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

scripts/fix/main.mjs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ async function main() {
4444
args: ['scripts/fix/commonjs-exports.mjs', ...fixArgs],
4545
command: 'node',
4646
},
47-
// TEMP: Re-enable once export patterns are fixed
48-
// {
49-
// args: ['scripts/validate/esm-named-exports.mjs', ...fixArgs],
50-
// command: 'node',
51-
// },
52-
// {
53-
// args: ['scripts/validate/dist-exports.mjs', ...fixArgs],
54-
// command: 'node',
55-
// },
47+
{
48+
args: ['scripts/validate/esm-named-exports.mjs', ...fixArgs],
49+
command: 'node',
50+
},
51+
{
52+
args: ['scripts/validate/dist-exports.mjs', ...fixArgs],
53+
command: 'node',
54+
},
5655
])
5756

5857
if (!quiet) {

scripts/validate/esm-named-exports.mjs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ function checkEsmNamedExports(filePath) {
6767
const hasNamedExportsObject = /module\.exports\s*=\s*{/.test(source)
6868

6969
// Also check by actually requiring the module
70-
const mod = require(filePath)
70+
let mod
71+
try {
72+
mod = require(filePath)
73+
} catch (requireError) {
74+
return {
75+
path: filePath,
76+
ok: false,
77+
reason: `Failed to require: ${requireError.message}`,
78+
}
79+
}
7180

7281
// If it's a primitive, it can't have named exports
7382
if (typeof mod !== 'object' || mod === null) {
@@ -106,8 +115,14 @@ function checkEsmNamedExports(filePath) {
106115
}
107116
}
108117

109-
// If we have an empty object
118+
// If we have an empty object, check if it's a type-only file
110119
if (keys.length === 0) {
120+
// Type-only files (e.g., cover/types.js, effects/types.js) have no runtime exports
121+
// These are expected and OK
122+
const isTypeOnlyFile = normalizedPath.endsWith('/types.js')
123+
if (isTypeOnlyFile) {
124+
return { path: filePath, ok: true }
125+
}
111126
return {
112127
path: filePath,
113128
ok: false,

0 commit comments

Comments
 (0)