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 = / f u n c t i o n g e t T a r g e t C o n f i g u r a t i o n F o r T a s k \( t a s k , p r o j e c t s C o n f i g u r a t i o n s \) \{ / ;
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 + r e t u r n p r o j e c t s C o n f i g u r a t i o n s \. p r o j e c t s \[ t a s k \. t a r g e t \. p r o j e c t \] \. t a r g e t s \[ t a s k \. t a r g e t \. t a r g e t \] ; ? \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