Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ coverage
.phpunit.result.cache
.reassure
.dev-ready
.dev-head


# Directories/files that may appear in your environment
Expand Down
53 changes: 53 additions & 0 deletions bin/dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,45 @@ const readyMarkerFile = {
},
};

/**
* Track the git HEAD to detect branch switches.
* Stale TypeScript declaration files from a previous branch cause build
* errors, so we clean them automatically when the HEAD changes.
*/
const headTracker = {
markerPath: path.join( ROOT_DIR, '.dev-head' ),
getCurrentHead() {
try {
return fs
.readFileSync( path.join( ROOT_DIR, '.git', 'HEAD' ), 'utf8' )
.trim();
} catch {
return null;
}
},
hasChanged() {
const currentHead = this.getCurrentHead();
if ( ! currentHead ) {
return false;
}
try {
const previousHead = fs
.readFileSync( this.markerPath, 'utf8' )
.trim();
return currentHead !== previousHead;
} catch {
// No marker file means first run — no need to clean.
return false;
}
},
save() {
const currentHead = this.getCurrentHead();
if ( currentHead ) {
fs.writeFileSync( this.markerPath, currentHead );
}
},
};

/**
* Main dev orchestration function.
*/
Expand All @@ -126,6 +165,17 @@ async function dev() {
console.log( '🧹 Cleaning packages...' );
await exec( 'npm', [ 'run', 'clean:packages' ], { silent: true } );

// Step 1.5: Clean TypeScript types if git HEAD changed (e.g. branch switch).
// Stale build-types from a previous branch cause compilation errors.
if ( headTracker.hasChanged() ) {
console.log(
'\n🔄 Branch change detected — cleaning TypeScript types...'
);
await exec( 'npm', [ 'run', 'clean:package-types' ], {
silent: true,
} );
}

// Step 2: Build workspaces
console.log( '\n📦 Building workspaces...' );
await exec(
Expand Down Expand Up @@ -156,6 +206,9 @@ async function dev() {
throw new Error( 'TypeScript compilation failed' );
} );

// Save current HEAD so next run can detect branch switches.
headTracker.save();

// Step 5: Check build type declaration files
console.log( '\n✅ Checking type declaration files...' );
await exec( 'node', [
Expand Down
Loading