Skip to content

Commit 8a1fd9b

Browse files
committed
Enhance fix script to generate exports and fix imports
Integrates generate-package-exports and fix-default-imports into the fix script workflow. Export generation is conditional on dist/ existing. Removes fix:exports and fix:imports npm scripts as they're now integrated.
1 parent 410144e commit 8a1fd9b

File tree

1 file changed

+66
-27
lines changed

1 file changed

+66
-27
lines changed

scripts/fix.mjs

Lines changed: 66 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
2-
* @fileoverview Fix script that runs Biome with auto-fix enabled.
2+
* @fileoverview Fix script that runs package export generation and Biome with auto-fix enabled.
33
*/
44

5+
import { existsSync } from 'node:fs'
56
import { spawn } from 'node:child_process'
67
import path from 'node:path'
78
import { fileURLToPath } from 'node:url'
@@ -11,29 +12,67 @@ import { printError, printHeader } from './utils/cli-helpers.mjs'
1112
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1213
const rootPath = path.join(__dirname, '..')
1314

14-
printHeader('Running Auto-fix')
15-
16-
const args = [
17-
'exec',
18-
'biome',
19-
'check',
20-
'--write',
21-
'--unsafe',
22-
'.',
23-
...process.argv.slice(2),
24-
]
25-
26-
const child = spawn('pnpm', args, {
27-
stdio: 'inherit',
28-
cwd: rootPath,
29-
...(process.platform === 'win32' && { shell: true }),
30-
})
31-
32-
child.on('exit', code => {
33-
process.exitCode = code || 0
34-
})
35-
36-
child.on('error', error => {
37-
printError(`Fix script failed: ${error.message}`)
38-
process.exitCode = 1
39-
})
15+
/**
16+
* Run a command and return a promise that resolves when it completes.
17+
*/
18+
function runCommand(command, args, label) {
19+
return new Promise((resolve, reject) => {
20+
printHeader(label)
21+
const child = spawn(command, args, {
22+
stdio: 'inherit',
23+
cwd: rootPath,
24+
...(process.platform === 'win32' && { shell: true }),
25+
})
26+
27+
child.on('exit', code => {
28+
if (code === 0) {
29+
resolve()
30+
} else {
31+
reject(new Error(`${label} exited with code ${code}`))
32+
}
33+
})
34+
35+
child.on('error', error => {
36+
printError(`${label} failed: ${error.message}`)
37+
reject(error)
38+
})
39+
})
40+
}
41+
42+
// Run tasks sequentially
43+
async function main() {
44+
try {
45+
// Step 1: Generate package exports (only if dist/ exists)
46+
const distPath = path.join(rootPath, 'dist')
47+
if (existsSync(distPath)) {
48+
await runCommand(
49+
'node',
50+
[path.join(__dirname, 'generate-package-exports.mjs')],
51+
'Generating Package Exports',
52+
)
53+
} else {
54+
printHeader('Skipping Package Exports (dist/ not found)')
55+
}
56+
57+
// Step 2: Fix default imports
58+
await runCommand(
59+
'node',
60+
[path.join(__dirname, 'fix-default-imports.mjs')],
61+
'Fixing Default Imports',
62+
)
63+
64+
// Step 3: Run Biome auto-fix
65+
await runCommand(
66+
'pnpm',
67+
['exec', 'biome', 'check', '--write', '--unsafe', '.', ...process.argv.slice(2)],
68+
'Running Auto-fix',
69+
)
70+
71+
process.exitCode = 0
72+
} catch (error) {
73+
printError(`Fix script failed: ${error.message}`)
74+
process.exitCode = 1
75+
}
76+
}
77+
78+
main()

0 commit comments

Comments
 (0)