BUILD SYSTEM COMPREHENSIVE AUDIT
Comprehensive guidelines for AI-assisted development within the Editor platform
Build System Comprehensive Audit & Review
Date: October 20, 2025
Status: 🔴 CRITICAL ISSUES FOUND
Priority: ⚠️ HIGH - IMMEDIATE ACTION REQUIRED
📋 Executive Summary
A comprehensive audit of the monorepo's build system revealed critical path inconsistencies and duplicate build systems that could cause build failures. This document provides a complete analysis, identifies all issues, and provides actionable fixes.
🚨 Critical Issues Found
1. PATH MISMATCH IN PACKAGE.JSON 🔴 BLOCKING
Problem:
// package.json - WRONG PATHS
"build": "node tools/build-scripts/build-all.js",
"build:libs": "node tools/build-scripts/build-libs.js",
"build:apps": "node tools/build-scripts/build-apps.js"
Actual Location:
✅ tools/scripts/build-scripts/build-all.js
✅ tools/scripts/build-scripts/build-libs.js
✅ tools/scripts/build-scripts/build-apps.js
Impact:
- ❌
yarn build,yarn build:libs,yarn build:appswill FAIL - ❌ CI/CD pipelines may break
- ❌ Developers cannot build the project
Fix Priority: 🔴 IMMEDIATE
2. DUPLICATE BUILD SYSTEMS 🟡 HIGH
We have TWO separate build systems doing similar things:
System A: Unified Build (✅ Modern, Feature-Rich)
- Location:
tools/automation/build/unified-build.js - Used by:
build.js(root) - Features:
- ✅ Dependency graph analysis
- ✅ Topological sort for build order
- ✅ Automatic dependency extraction
- ✅ Intelligent error recovery
- ✅ Cross-platform utilities
- ✅ Comprehensive reporting
System B: Legacy Build Scripts (⚠️ Older, Less Features)
- Location:
tools/scripts/build-scripts/build-all.js - Used by:
package.jsonscripts (incorrectly) - Features:
- ❌ No dependency graph
- ❌ Simple delegation to build-libs.js and build-apps.js
- ⚠️ Manual build order maintenance
Problem:
- Confusion about which system to use
- Maintenance burden (two systems to update)
- Risk of divergence
Recommendation:
- 🎯 Standardize on UnifiedBuildSystem (System A)
- 🗑️ Deprecate legacy scripts or refactor them to use UnifiedBuildSystem
3. INCONSISTENT SCRIPT REFERENCES 🟡 MEDIUM
build-all.js Internal Paths:
// Line 122 - ASSUMES scripts are in same directory
const buildLibsScript = path.join(__dirname, 'build-libs.js');
// Line 165
const buildAppsScript = path.join(__dirname, 'build-apps.js');
✅ These paths are actually CORRECT (same directory)
⚠️ But the confusion comes from package.json referencing wrong parent directory
📁 Current Build System Architecture
editor/
├── build.js # ✅ Root entry point (uses UnifiedBuildSystem)
├── fix-imports.js # ✅ Import fixer
├── fix-libs.js # ✅ Library fixer entry point
├── generate-lib.js # ✅ Library generator entry point
│
├── tools/
│ ├── automation/ # ✅ MODERN SYSTEM
│ │ ├── core/
│ │ │ ├── path-resolver.js # ✅ Dependency graph & path management
│ │ │ └── platform-utils.js # ✅ Cross-platform utilities
│ │ ├── build/
│ │ │ └── unified-build.js # ✅ PRIMARY BUILD SYSTEM
│ │ ├── generators/
│ │ │ └── generate-library.js # ✅ Library generator
│ │ └── maintenance/
│ │ └── fix-all-libraries.js # ✅ Library fixer
│ │
│ └── scripts/ # ⚠️ LEGACY/MIXED
│ └── build-scripts/
│ ├── build-all.js # ⚠️ Legacy (delegates)
│ ├── build-libs.js # ⚠️ Legacy (hardcoded order)
│ ├── build-apps.js # ✅ App builder (still useful)
│ └── build-angular-library.js # ✅ Custom Angular builder
🎯 Recommended Architecture
Option 1: Full Modernization (RECOMMENDED)
editor/
├── build.js # Entry point → UnifiedBuildSystem
├── fix-imports.js # Entry point → fix-all-libraries
├── fix-libs.js # Entry point → fix-all-libraries
├── generate-lib.js # Entry point → generate-library
│
└── tools/
└── automation/ # ALL build logic here
├── core/ # Core utilities
├── build/ # Build system
├── generators/ # Code generation
└── maintenance/ # Maintenance tools
Changes Needed:
- Update package.json paths to use root entry points
- Deprecate tools/scripts/build-scripts/build-all.js
- Migrate any useful logic from build-libs.js to UnifiedBuildSystem
Option 2: Hybrid Approach (FASTER)
Keep both systems but fix the paths and clarify usage:
# Root-level commands (use UnifiedBuildSystem)
yarn build:all → node build.js
yarn build:all:clean → node build.js --clean
# Direct build commands (use legacy scripts, fixed paths)
yarn build:libs:direct → node tools/scripts/build-scripts/build-libs.js
yarn build:apps:direct → node tools/scripts/build-scripts/build-apps.js
🔧 Immediate Fixes Required
Fix 1: Update package.json Paths
{
"scripts": {
"//9": "=== BUILD COMMANDS ===",
"build": "NODE_OPTIONS=\"--max-old-space-size=8192\" node tools/scripts/build-scripts/build-all.js",
"build:dev": "NODE_OPTIONS=\"--max-old-space-size=8192\" node tools/scripts/build-scripts/build-all.js --dev",
"build:libs": "NODE_OPTIONS=\"--max-old-space-size=8192\" node tools/scripts/build-scripts/build-libs.js",
"build:apps": "NODE_OPTIONS=\"--max-old-space-size=8192\" node tools/scripts/build-scripts/build-apps.js",
"build:quick": "node tools/scripts/build-scripts/build-all.js --no-clean --skip-nx-cache"
}
}
OR (RECOMMENDED - Use modern system):
{
"scripts": {
"//9": "=== BUILD COMMANDS (MODERN) ===",
"build": "NODE_OPTIONS=\"--max-old-space-size=8192\" node build.js",
"build:dev": "NODE_OPTIONS=\"--max-old-space-size=8192\" node build.js --dev",
"build:libs": "NODE_OPTIONS=\"--max-old-space-size=8192\" node build.js --libs-only",
"build:apps": "NODE_OPTIONS=\"--max-old-space-size=8192\" node build.js --apps-only",
"build:quick": "node build.js --skip-cache",
"//10": "=== BUILD COMMANDS (LEGACY - For compatibility) ===",
"build:libs:legacy": "NODE_OPTIONS=\"--max-old-space-size=8192\" node tools/scripts/build-scripts/build-libs.js",
"build:apps:legacy": "NODE_OPTIONS=\"--max-old-space-size=8192\" node tools/scripts/build-scripts/build-apps.js"
}
}
📊 Script Inventory & Quality Assessment
✅ Root-Level Scripts (EXCELLENT)
| Script | Status | Quality | Purpose |
|---|---|---|---|
build.js |
✅ Perfect | 🟢 Excellent | Main build entry point |
fix-imports.js |
✅ Good | 🟢 Good | Fix literal imports |
fix-libs.js |
✅ Good | 🟢 Good | Fix library entry point |
generate-lib.js |
✅ Good | 🟢 Good | Generate library entry point |
✅ tools/automation/ (MODERN - EXCELLENT)
| Script | Status | Quality | Purpose |
|---|---|---|---|
core/path-resolver.js |
✅ Excellent | 🟢 Excellent | Dependency resolution |
core/platform-utils.js |
✅ Excellent | 🟢 Excellent | Cross-platform utilities |
build/unified-build.js |
✅ Excellent | 🟢 Excellent | PRIMARY BUILD SYSTEM |
generators/generate-library.js |
✅ Excellent | 🟢 Excellent | Library generator |
maintenance/fix-all-libraries.js |
✅ Excellent | 🟢 Excellent | Library fixer |
Strengths:
- ✅ Dependency graph analysis
- ✅ Cross-platform support
- ✅ Modern TypeScript/Node.js patterns
- ✅ Comprehensive error handling
- ✅ Interactive CLI
⚠️ tools/scripts/build-scripts/ (MIXED)
| Script | Status | Quality | Recommendation |
|---|---|---|---|
build-angular-library.js |
✅ Critical | 🟢 Excellent | ✅ KEEP (Updated today) |
build-apps.js |
✅ Useful | 🟡 Good | ✅ KEEP (App-specific logic) |
build-libs.js |
⚠️ Legacy | 🟡 Outdated | 🔄 REFACTOR (Hardcoded order) |
build-all.js |
⚠️ Legacy | 🟡 Outdated | 🔄 DEPRECATE (Use UnifiedBuildSystem) |
clean-dist.js |
✅ Useful | 🟢 Good | ✅ KEEP |
monitor-build-performance.js |
✅ Useful | 🟢 Good | ✅ KEEP |
🔧 tools/scripts/ (UTILITY SCRIPTS)
Build & Performance Scripts
| Script | Purpose | Status |
|---|---|---|
aggressive-cleanup.js |
Nuclear process cleanup | ✅ Keep |
crash-prevention.js |
Process monitoring | ✅ Keep |
simple-crash-fix.js |
Quick cleanup | ✅ Keep |
monorepo-health-check.js |
Health diagnostics | ✅ Keep |
continuous-monitor.js |
Background monitoring | ✅ Keep |
cache-monitor.js |
NX cache monitoring | ✅ Keep |
performance-audit.js |
Performance analysis | ✅ Keep |
Angular Component Scripts
| Script | Purpose | Status |
|---|---|---|
angular-component-separator.js |
Single component | ✅ Keep |
angular-component-separator-batch.js |
Batch processing | ✅ Keep |
angular-component-refactor.js |
Master script | ✅ Keep |
smart-barrel-manager.js |
Intelligent barrel exports | ✅ Keep |
universal-component-manager.js |
Ultimate tool | ✅ Keep |
update-barrel-exports.js |
Export updater | ✅ Keep |
Source Pollution Prevention
| Script | Purpose | Status |
|---|---|---|
cleanup-all-source-pollution.js |
Full cleanup | ✅ Keep |
cleanup-generated-files.js |
Generated files | ✅ Keep |
prevent-source-pollution.js |
Prevention system | ✅ Keep |
fix-tsconfig-source-pollution.js |
TSConfig fixer | ✅ Keep |
enable-declaration-maps.js |
Declaration maps | ✅ Keep (just created today!) |
Migration & Maintenance
| Script | Purpose | Status |
|---|---|---|
migrate-all-to-custom-builder.js |
Migrate to custom builder | ✅ Keep |
fix-commonmodule-imports.js |
Fix CommonModule | ✅ Keep |
fix-scss-imports.js |
Fix SCSS imports | ✅ Keep |
rename-core-models.js |
Rename utility | ✅ Keep |
update-imports.js |
Import updater | ✅ Keep |
🎨 Quality Issues Found in Individual Scripts
1. build-libs.js (Line 16-30)
// ❌ PROBLEM: Hardcoded library list
const config = {
libraries: [
'core-types',
'core',
'theme-runtime',
// ... hardcoded
]
};
Issue: Manual maintenance required when adding libraries
Fix: Use PathResolver.getAllLibraries() + dependency graph
2. fix-imports.js (Line 10-33)
// ❌ PROBLEM: Hardcoded alias map
const aliasMap = {
'libs/storage-system/src': '@storage-system',
'libs/core-models/src/lib/utils/lodash.utils': '@libs-foundational/core-models',
// ... 24 more hardcoded mappings
};
Issue: Manual maintenance required for each library
Fix: Generate dynamically from tsconfig.base.json paths
3. generate-lib.js (Line 23-38)
// ⚠️ WARNING: Outdated default tsconfig settings
tsconfig.compilerOptions = {
declarationMap: false, // ❌ Should be true (we just fixed this!)
sourceMap: false // ❌ Should be true (we just fixed this!)
};
Issue: New libraries will have wrong declaration map settings
Fix: Update defaults to match our new standards
🎯 Action Plan
Phase 1: Immediate Fixes (TODAY)
- ✅ Fix package.json paths
- ✅ Update generate-lib.js defaults
- ✅ Document the dual build system
Phase 2: Short-term Improvements (THIS WEEK)
- 🔄 Make fix-imports.js dynamic
- 🔄 Integrate build-libs.js with dependency graph
- 🔄 Add tests for critical build scripts
Phase 3: Long-term Modernization (THIS MONTH)
- 🎯 Fully migrate to UnifiedBuildSystem
- 🎯 Deprecate legacy scripts
- 🎯 Create comprehensive build system documentation
📚 Documentation Status
Existing Documentation
- ✅
tools/scripts/build-scripts/AGENTS.md- Build system fixes - ✅
tools/scripts/README.md- Component management scripts - ✅
tools/README.md- Tools overview - ✅
tools/executors/backup/README.md- Deprecated executors
Missing Documentation
- ❌ Build System Architecture Guide
- ❌ Script Development Guidelines
- ❌ Dependency Graph Explanation
- ❌ Cross-Platform Build Guide
🔐 Best Practices Validation
✅ What We're Doing Right
- ✅ Separation of Concerns - Build, generation, maintenance are separate
- ✅ Error Recovery - Scripts handle failures gracefully
- ✅ Cross-Platform - Using platform-utils for compatibility
- ✅ Modern Patterns - Signals, standalone components, inject()
- ✅ Process Management - Monitoring and cleanup scripts
- ✅ Source Pollution Prevention - Multiple layers of protection
⚠️ Areas for Improvement
- ⚠️ Too Many Entry Points - Confusing which script to use
- ⚠️ Hardcoded Dependencies - Should use dependency graph
- ⚠️ Inconsistent Paths - package.json vs actual locations
- ⚠️ Duplicate Logic - Two build systems doing similar things
- ⚠️ Missing Tests - Critical scripts lack automated tests
🚀 Recommendations
Immediate (Do Now)
- 🔴 Fix package.json paths - Critical blocker
- 🔴 Update generate-lib.js defaults - Prevent future issues
- 🟡 Document dual build system - Reduce confusion
Short-term (This Week)
- 🟡 Standardize on UnifiedBuildSystem - Reduce maintenance
- 🟡 Add build system tests - Prevent regressions
- 🟢 Create build guide - Help developers
Long-term (This Month)
- 🟢 Deprecate legacy scripts - Technical debt cleanup
- 🟢 Add CI/CD integration tests - Catch issues early
- 🟢 Performance benchmarking - Track build times
📈 Success Metrics
After implementing fixes, we should see:
- ✅ Zero path-related build failures
- ✅ Consistent build times across environments
- ✅ Reduced confusion about which commands to use
- ✅ Easier library addition (auto-discovery)
- ✅ Better developer onboarding experience
🎓 Key Learnings
- Dependency Graphs Matter - Manual build orders don't scale
- Path Consistency is Critical - One wrong path breaks everything
- Consolidation > Duplication - Two build systems = 2x maintenance
- Modern Patterns Win - UnifiedBuildSystem is superior
- Documentation Prevents Confusion - Document the "why" not just "how"
Next Steps:
See BUILD-SYSTEM-IMMEDIATE-FIXES.md for the fix implementation plan.