Skip to content

Commit 071ea22

Browse files
jonphippsclaude
andcommitted
fix: implement pre-commit hook optimization with separate test targets
- Add test:unit and test:integration targets to @ifla/theme project - Update test:pre-commit to use test:unit instead of full test suite - Fix path calculation issues in CLI integration tests - Exclude integration tests from pre-commit for faster feedback - Keep integration tests available for comprehensive testing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 0a39791 commit 071ea22

File tree

15 files changed

+1039
-114
lines changed

15 files changed

+1039
-114
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ jobs:
4545
- run: pnpm install --frozen-lockfile
4646
- uses: nrwl/nx-set-shas@v4
4747

48-
# Minimal CI - just build affected projects for deployment
49-
# Tests run locally via pre-commit/pre-push hooks
48+
# Run CI-focused tests (Group 5: Environment/Infrastructure focus)
49+
# Development tool tests run locally via pre-commit/pre-push hooks
50+
- name: Run CI tests
51+
run: pnpm test:ci
52+
53+
# Build affected projects for deployment
5054
- run: pnpm exec nx affected -t build --parallel=6

.husky/pre-commit

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
#!/usr/bin/env sh
2-
# NX-optimized pre-commit hook for IFLA Standards project
3-
# Runs essential checks on affected projects only
2+
# Group 3: Pre-commit tests (Fast feedback for commits)
3+
# Uses the new organized test structure
44

5-
echo "🔍 Running NX-optimized pre-commit checks..."
5+
echo "🔍 Running Group 3: Pre-commit tests..."
66

7-
# Run affected checks in parallel for maximum efficiency
8-
echo "⚡ Running affected typecheck, lint, and test in parallel..."
9-
{
10-
nx affected --target=typecheck --parallel=3 &
11-
nx affected --target=lint --parallel=3 &
12-
nx affected --target=test --parallel=3 &
13-
wait
14-
} || {
15-
echo "❌ Pre-commit checks failed. Please fix and try again."
16-
exit 1
17-
}
7+
# Use the optimized pre-commit command from package.json
8+
pnpm test:pre-commit
189

19-
# Quick configuration validation for affected sites only
20-
echo "⚙️ Validating affected site configurations..."
21-
node scripts/test-site-builds-affected.js --env local --skip-build
2210
if [ $? -ne 0 ]; then
23-
echo "Site configuration validation failed."
11+
echo "Pre-commit tests failed. Please fix and try again."
2412
exit 1
2513
fi
2614

27-
echo "All NX-optimized pre-commit checks passed!"
15+
echo "Group 3 pre-commit tests passed!"

CLAUDE.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,54 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
3535
- **Build validation**: `nx run standards-dev:validate:builds`
3636

3737
#### Comprehensive Test Suites
38-
- **Pre-commit**: `pnpm test:pre-commit` (typecheck + lint + test + config)
39-
- **Regression**: `nx run standards-dev:regression:full`
40-
- **Fast regression**: `nx run standards-dev:regression:fast`
38+
### Testing Commands (5 Organized Groups)
39+
40+
The project uses a 5-group testing strategy optimized for efficiency and cost management:
41+
42+
#### Group 1: Selective Tests (On-Demand Development)
43+
- **Individual unit tests**: `nx test portal`, `nx test @ifla/theme`, `nx test isbdm`
44+
- **Affected tests**: `pnpm test` (now Nx-optimized: `nx affected --target=test --parallel=3`)
45+
- **All unit tests**: `pnpm test:all` (parallel across all projects)
46+
- **E2E by browser**: `pnpm test:e2e:chromium`, `pnpm test:e2e:firefox`, `pnpm test:e2e:mobile`
47+
- **Debug E2E**: `pnpm test:e2e:debug`, `pnpm test:e2e:ui`
48+
- **Visual regression**: `pnpm test:regression:visual`
49+
50+
#### Group 2: Comprehensive Tests (Test Everything)
51+
- **Full suite**: `pnpm test:comprehensive` (typecheck + lint + test + build + E2E)
52+
- **All unit tests**: `pnpm test:comprehensive:unit`
53+
- **All E2E tests**: `pnpm test:comprehensive:e2e`
54+
- **All builds**: `pnpm test:comprehensive:builds`
55+
56+
#### Group 3: Pre-Commit Tests (Git Hook - Fast Feedback)
57+
- **Automatic**: Runs on `git commit`
58+
- **Manual**: `pnpm test:pre-commit`
59+
- **What runs**: `nx affected --targets=typecheck,lint,test --parallel=3` + config validation
60+
- **Target**: < 60 seconds
61+
62+
#### Group 4: Pre-Push Tests (Git Hook - Deployment Focus)
63+
- **Automatic**: Runs on `git push` (branch-aware)
64+
- **Manual**: `pnpm test:pre-push`
65+
- **Feature branch**: Fast validation only
66+
- **Protected branch**: Full affected testing + builds
67+
- **Target**: < 180 seconds
68+
69+
#### Group 5: CI Tests (Environment/Infrastructure Focus)
70+
- **CI suite**: `pnpm test:ci` (deployment-critical tests only)
71+
- **Connectivity**: `pnpm test:ci:connectivity` (external services)
72+
- **Config validation**: `pnpm test:ci:config` (production environment)
73+
- **Focus**: Environment-specific issues, not development tools
74+
75+
#### Core Development Commands (Nx-Optimized)
76+
- **Lint**: `pnpm lint` (now: `nx affected --target=lint --parallel=3`)
77+
- **TypeCheck**: `pnpm typecheck` (now: `nx affected --target=typecheck --parallel=3`)
78+
- **Build affected**: `pnpm build:affected` (now: `nx affected --target=build --parallel=3`)
79+
80+
#### Performance Targets
81+
- **Selective**: < 30s
82+
- **Comprehensive**: < 300s
83+
- **Pre-commit**: < 60s
84+
- **Pre-push**: < 180s
85+
- **CI**: < 180s
4186

4287
### Build System Architecture
4388
- **Nx monorepo** with workspace-level coordination

NX_OPTIMIZATIONS_APPLIED.md

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# Nx Optimizations Applied
2+
3+
## Summary
4+
5+
Based on Perplexity's advice, we've implemented comprehensive Nx optimizations for the IFLA Standards Docusaurus monorepo. These optimizations significantly improve build performance, caching efficiency, and task orchestration.
6+
7+
## **Optimizations Implemented**
8+
9+
### 1. **Task Dependency Orchestration (`dependsOn` rules)**
10+
11+
#### **Global Configuration (nx.json)**
12+
```json
13+
{
14+
"build": {
15+
"dependsOn": ["^build"], // Dependencies build first
16+
"outputs": ["{projectRoot}/build", "{projectRoot}/dist", "{projectRoot}/.docusaurus"],
17+
"cache": true
18+
},
19+
"test": {
20+
"dependsOn": ["^build"], // Tests run after dependencies are built
21+
"outputs": ["{projectRoot}/coverage", "{projectRoot}/test-results"]
22+
},
23+
"typecheck": {
24+
"dependsOn": ["^build"], // TypeCheck after dependencies built
25+
"cache": true
26+
}
27+
}
28+
```
29+
30+
#### **Project-Specific Dependencies**
31+
- **Theme Package**: `typecheck` depends on `^build`
32+
- **Portal**: `typecheck` depends on `^build`, ensuring theme is built first
33+
- **Standards Sites**: `typecheck` depends on `^build`
34+
35+
**Result**: Theme library always builds before dependent Docusaurus sites.
36+
37+
### 2. **Explicit Outputs Configuration**
38+
39+
#### **Before**
40+
```json
41+
// Missing outputs led to poor caching
42+
"build": {
43+
"cache": true
44+
}
45+
```
46+
47+
#### **After**
48+
```json
49+
// Explicit outputs enable remote caching and artifact sharing
50+
"build": {
51+
"outputs": ["{projectRoot}/build", "{projectRoot}/dist", "{projectRoot}/.docusaurus"],
52+
"cache": true
53+
}
54+
```
55+
56+
**Applied to**:
57+
- Global build target
58+
- Global test target (coverage, test-results)
59+
- Project-specific E2E targets
60+
61+
### 3. **Enhanced Input Specifications**
62+
63+
#### **Test Targets**
64+
```json
65+
"test": {
66+
"inputs": [
67+
"default",
68+
"{projectRoot}/src/**/*.{test,spec}.{js,ts,jsx,tsx}",
69+
"{workspaceRoot}/vite.config.ts",
70+
"{workspaceRoot}/vitest.config.*"
71+
]
72+
}
73+
```
74+
75+
#### **TypeCheck Targets**
76+
```json
77+
"typecheck": {
78+
"inputs": [
79+
"default",
80+
"{projectRoot}/tsconfig.json",
81+
"{workspaceRoot}/tsconfig.json"
82+
]
83+
}
84+
```
85+
86+
**Result**: More precise cache invalidation and better caching efficiency.
87+
88+
### 4. **Missing TypeCheck Targets Added**
89+
90+
Added `typecheck` targets to projects that were missing them:
91+
- **Portal** (`portal/project.json`)
92+
- **ISBDM** (`standards/ISBDM/project.json`)
93+
94+
Pattern can be replicated to other standards sites:
95+
```json
96+
"typecheck": {
97+
"executor": "nx:run-commands",
98+
"options": {
99+
"command": "tsc --noEmit",
100+
"cwd": "{projectRoot}"
101+
},
102+
"cache": true,
103+
"dependsOn": ["^build"],
104+
"inputs": [
105+
"default",
106+
"{projectRoot}/tsconfig.json",
107+
"{workspaceRoot}/tsconfig.json"
108+
]
109+
}
110+
```
111+
112+
### 5. **Improved Caching Configuration**
113+
114+
#### **Global Named Inputs**
115+
Already excellent configuration with:
116+
- `docusaurus`: Includes theme dependency
117+
- `docusaurus-no-theme`: For projects not using theme
118+
- `production`: Excludes test files appropriately
119+
120+
#### **Enhanced Test Caching**
121+
```json
122+
"test": {
123+
"dependsOn": ["^build"],
124+
"cache": true,
125+
"outputs": ["{projectRoot}/coverage", "{projectRoot}/test-results"],
126+
"inputs": [
127+
"default",
128+
"{projectRoot}/test/**/*",
129+
"{projectRoot}/**/*.test.{js,ts,jsx,tsx}",
130+
"{projectRoot}/**/*.spec.{js,ts,jsx,tsx}",
131+
"{workspaceRoot}/vite.config.ts",
132+
"{workspaceRoot}/vitest.config.*"
133+
]
134+
}
135+
```
136+
137+
## 🚀 **Performance Benefits**
138+
139+
### **Build Sequence Optimization**
140+
```mermaid
141+
graph LR
142+
A[@ifla/theme:build] --> B[portal:typecheck]
143+
A --> C[isbdm:typecheck]
144+
A --> D[Other sites:typecheck]
145+
E[parallel execution] --> B & C & D
146+
```
147+
148+
### **Caching Improvements**
149+
- **Input-based cache invalidation**: Only affected projects rebuild
150+
- **Output caching**: Built artifacts shared across environments
151+
- **Remote caching ready**: Nx Cloud optimization enabled
152+
153+
### **Dependency Management**
154+
- **Automatic orchestration**: Theme builds before sites
155+
- **Parallel execution**: Independent tasks run simultaneously
156+
- **Smart scheduling**: Nx optimizes resource utilization
157+
158+
## 📊 **Expected Performance Gains**
159+
160+
### **Build Times**
161+
- **Theme changes**: All sites rebuild (necessary)
162+
- **Site-specific changes**: Only affected sites rebuild
163+
- **Configuration changes**: Smart invalidation based on inputs
164+
165+
### **Development Workflow**
166+
- **`pnpm typecheck`**: Now orchestrates dependencies properly
167+
- **`pnpm test`**: Ensures dependencies built before testing
168+
- **`pnpm build:affected`**: Optimal build order automatically
169+
170+
### **CI Performance**
171+
- **Better caching**: Explicit outputs enable artifact reuse
172+
- **Reduced redundancy**: Smart dependency management
173+
- **Parallel optimization**: Maximum resource utilization
174+
175+
## 🔧 **Technical Implementation**
176+
177+
### **Key Nx Features Leveraged**
178+
179+
1. **Task Pipeline Configuration**: `dependsOn` rules ensure correct build order
180+
2. **Input/Output Specification**: Precise caching and invalidation
181+
3. **Named Inputs**: Reusable input patterns across projects
182+
4. **Implicit Dependencies**: Theme package dependency management
183+
5. **Affected Detection**: Only build/test what changed
184+
185+
### **Docusaurus-Specific Optimizations**
186+
187+
1. **Theme Dependency**: All sites depend on `@ifla/theme` build
188+
2. **Docusaurus Inputs**: Include `.docusaurus`, `build`, `static` directories
189+
3. **Port Management**: Each site has unique port configuration
190+
4. **Configuration Isolation**: `docusaurus-no-theme` for self-contained sites
191+
192+
## 🏗️ **Monorepo Architecture Benefits**
193+
194+
### **Shared Theme Package**
195+
- **Single build**: Theme builds once, used by all sites
196+
- **Dependency management**: Automatic rebuild when theme changes
197+
- **Version consistency**: All sites use same theme version
198+
199+
### **Independent Sites**
200+
- **Isolated builds**: Each site builds independently when possible
201+
- **Shared dependencies**: Common packages cached and reused
202+
- **Parallel execution**: Sites build simultaneously when dependencies met
203+
204+
## 📋 **Next Steps for Full Optimization**
205+
206+
### **Apply to All Standards Sites**
207+
Replicate the optimizations applied to ISBDM to:
208+
- `standards/LRM/project.json`
209+
- `standards/FRBR/project.json`
210+
- `standards/isbd/project.json`
211+
- `standards/muldicat/project.json`
212+
- `standards/unimarc/project.json`
213+
214+
### **Template Pattern**
215+
Consider creating a project template for standards sites to reduce duplication:
216+
```bash
217+
nx g @nx/workspace:lib-executors standards-template
218+
```
219+
220+
### **Remote Caching**
221+
Your Nx Cloud is already configured (`nxCloudId: "6857fccbb755d4191ce6fbe4"`):
222+
- Enables artifact sharing across team/CI
223+
- Speeds up builds through remote cache hits
224+
- Reduces CI compute costs
225+
226+
## **Verification**
227+
228+
The optimizations are working correctly as demonstrated by:
229+
230+
```bash
231+
pnpm typecheck
232+
# Result:
233+
# 1. @ifla/theme:build runs first
234+
# 2. portal:typecheck, isbdm:typecheck run in parallel after theme builds
235+
# 3. Proper dependency orchestration achieved
236+
```
237+
238+
These optimizations align perfectly with Perplexity's recommendations and leverage Nx's advanced features for optimal Docusaurus monorepo performance.

0 commit comments

Comments
 (0)