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'
56import { spawn } from 'node:child_process'
67import path from 'node:path'
78import { fileURLToPath } from 'node:url'
@@ -11,29 +12,67 @@ import { printError, printHeader } from './utils/cli-helpers.mjs'
1112const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
1213const 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