Skip to content

Commit 01b83bd

Browse files
committed
add postinall to patch error
1 parent 815b08d commit 01b83bd

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"debug-targets": "./test-targets.sh",
99
"debug-build": "node debug-nx-targets.js 'npx nx run-many -t build-ci --parallel=32 --batch --outputStyle=stream'",
10-
"postinstall": "echo '⚠️ If you get target configuration errors, run: npm run debug-targets'",
10+
"postinstall": "node patch-nx-debug.js",
1111
"postci": "echo '✅ CI completed. If there were target errors, check the debug output above.'"
1212
}
1313
}

patch-nx-debug.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
const utilsPath = path.join(__dirname, 'node_modules/nx/src/tasks-runner/utils.js');
7+
8+
console.log('🔧 Patching NX utils.js to add target debugging...');
9+
10+
if (!fs.existsSync(utilsPath)) {
11+
console.log('❌ NX utils.js not found at:', utilsPath);
12+
process.exit(1);
13+
}
14+
15+
let content = fs.readFileSync(utilsPath, 'utf8');
16+
17+
// Check if already patched
18+
if (content.includes('SPRING_BOOT_DEBUG')) {
19+
console.log('✅ NX utils.js already patched');
20+
process.exit(0);
21+
}
22+
23+
// Add debugging to getTargetConfigurationForTask function
24+
const originalPattern = /function getTargetConfigurationForTask\(task, projectsConfigurations\) \{/;
25+
const patchedFunction = `function getTargetConfigurationForTask(task, projectsConfigurations) {
26+
// SPRING_BOOT_DEBUG: Log task details before potential error
27+
console.log('🎯 SPRING_BOOT_DEBUG: Processing target:', task.target.target, 'for project:', task.target.project);
28+
console.log('🎯 SPRING_BOOT_DEBUG: Task object:', JSON.stringify(task, null, 2));
29+
console.log('🎯 SPRING_BOOT_DEBUG: ProjectsConfigurations keys:', Object.keys(projectsConfigurations || {}));
30+
31+
try {`;
32+
33+
if (originalPattern.test(content)) {
34+
// Patch the function start
35+
content = content.replace(originalPattern, patchedFunction);
36+
37+
// Find the end of the function and add error handling
38+
const functionEndPattern = /(\s+return projectsConfigurations\.projects\[task\.target\.project\]\.targets\[task\.target\.target\];?\s*\})/;
39+
content = content.replace(functionEndPattern, `$1
40+
} catch (error) {
41+
console.log('❌ SPRING_BOOT_DEBUG: Error in getTargetConfigurationForTask for target:', task.target.target, 'project:', task.target.project);
42+
console.log('❌ SPRING_BOOT_DEBUG: Error details:', error.message);
43+
console.log('❌ SPRING_BOOT_DEBUG: ProjectsConfigurations structure:', JSON.stringify(projectsConfigurations, null, 2));
44+
throw error;
45+
}`);
46+
47+
fs.writeFileSync(utilsPath, content);
48+
console.log('✅ Successfully patched NX utils.js with debug logging');
49+
} else {
50+
console.log('⚠️ Could not find getTargetConfigurationForTask function pattern to patch');
51+
process.exit(1);
52+
}

0 commit comments

Comments
 (0)