3
3
const fs = require ( 'fs' ) ;
4
4
const path = require ( 'path' ) ;
5
5
6
- const utilsPath = path . join ( __dirname , 'node_modules/nx/src/tasks-runner/utils.js' ) ;
6
+ // Try multiple possible paths for NX utils.js
7
+ const possiblePaths = [
8
+ path . join ( __dirname , 'node_modules/nx/src/tasks-runner/utils.js' ) ,
9
+ path . join ( process . cwd ( ) , 'node_modules/nx/src/tasks-runner/utils.js' ) ,
10
+ path . join ( __dirname , '../../node_modules/nx/src/tasks-runner/utils.js' ) ,
11
+ ] ;
7
12
8
13
console . log ( '🔧 Patching NX utils.js to add target debugging...' ) ;
14
+ console . log ( '🔍 Current working directory:' , process . cwd ( ) ) ;
15
+ console . log ( '🔍 Script directory:' , __dirname ) ;
9
16
10
- if ( ! fs . existsSync ( utilsPath ) ) {
11
- console . log ( '❌ NX utils.js not found at:' , utilsPath ) ;
12
- process . exit ( 1 ) ;
17
+ let utilsPath ;
18
+ for ( const tryPath of possiblePaths ) {
19
+ console . log ( '🔍 Checking path:' , tryPath ) ;
20
+ if ( fs . existsSync ( tryPath ) ) {
21
+ utilsPath = tryPath ;
22
+ console . log ( '✅ Found NX utils.js at:' , utilsPath ) ;
23
+ break ;
24
+ }
25
+ }
26
+
27
+ if ( ! utilsPath ) {
28
+ console . log ( '⚠️ NX utils.js not found at any expected location. Skipping patch (this is OK).' ) ;
29
+ console . log ( '📋 Checked paths:' , possiblePaths ) ;
30
+ process . exit ( 0 ) ; // Don't fail the build
13
31
}
14
32
15
33
let content = fs . readFileSync ( utilsPath , 'utf8' ) ;
@@ -21,32 +39,78 @@ if (content.includes('SPRING_BOOT_DEBUG')) {
21
39
}
22
40
23
41
// 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 ) {
42
+ 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 G r a p h \) \{ \s * c o n s t p r o j e c t = p r o j e c t G r a p h \. n o d e s \[ t a s k \. t a r g e t \. p r o j e c t \] \. d a t a ; / ;
43
+ const replacement = `function getTargetConfigurationForTask(task, projectGraph ) {
26
44
// SPRING_BOOT_DEBUG: Log task details before potential error
27
45
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 || {}));
46
+ console.log('🎯 SPRING_BOOT_DEBUG: Available projects in projectGraph.nodes:', Object.keys(projectGraph?.nodes || {}));
47
+
48
+ if (!projectGraph?.nodes?.[task.target.project]) {
49
+ console.log('❌ SPRING_BOOT_DEBUG: Project not found in projectGraph.nodes:', task.target.project);
50
+ console.log('❌ SPRING_BOOT_DEBUG: Available projects:', Object.keys(projectGraph?.nodes || {}));
51
+ throw new Error(\`Project \${task.target.project} not found in projectGraph.nodes\`);
52
+ }
30
53
31
- try { ` ;
54
+ const project = projectGraph.nodes[task.target.project].data; ` ;
32
55
33
56
if ( originalPattern . test ( content ) ) {
34
- // Patch the function start
35
- content = content . replace ( originalPattern , patchedFunction ) ;
57
+ // Patch the function
58
+ content = content . replace ( originalPattern , replacement ) ;
36
59
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
60
fs . writeFileSync ( utilsPath , content ) ;
48
61
console . log ( '✅ Successfully patched NX utils.js with debug logging' ) ;
49
62
} else {
50
63
console . log ( '⚠️ Could not find getTargetConfigurationForTask function pattern to patch' ) ;
51
- process . exit ( 1 ) ;
64
+ console . log ( '🔍 Looking for alternative patterns...' ) ;
65
+
66
+ // Try multiple fallback patterns
67
+ const fallbackPatterns = [
68
+ // Simple pattern - just the problematic line
69
+ {
70
+ pattern : / c o n s t p r o j e c t = p r o j e c t G r a p h \. n o d e s \[ t a s k \. t a r g e t \. p r o j e c t \] \. d a t a ; / ,
71
+ replacement : `// SPRING_BOOT_DEBUG: Log task details before potential error
72
+ console.log('🎯 SPRING_BOOT_DEBUG: Processing target:', task.target.target, 'for project:', task.target.project);
73
+ console.log('🎯 SPRING_BOOT_DEBUG: Available projects in projectGraph.nodes:', Object.keys(projectGraph?.nodes || {}));
74
+
75
+ if (!projectGraph?.nodes?.[task.target.project]) {
76
+ console.log('❌ SPRING_BOOT_DEBUG: Project not found in projectGraph.nodes:', task.target.project);
77
+ console.log('❌ SPRING_BOOT_DEBUG: Available projects:', Object.keys(projectGraph?.nodes || {}));
78
+ throw new Error(\`Project \${task.target.project} not found in projectGraph.nodes\`);
79
+ }
80
+
81
+ const project = projectGraph.nodes[task.target.project].data;` ,
82
+ name : 'simple pattern'
83
+ } ,
84
+ // Even simpler - just add logging before the line
85
+ {
86
+ pattern : / ( c o n s t p r o j e c t = p r o j e c t G r a p h \. n o d e s \[ t a s k \. t a r g e t \. p r o j e c t \] \. d a t a ; ) / ,
87
+ replacement : `console.log('🎯 SPRING_BOOT_DEBUG: Processing target:', task.target.target, 'for project:', task.target.project, '- Available projects:', Object.keys(projectGraph?.nodes || {}));
88
+ $1` ,
89
+ name : 'minimal pattern'
90
+ }
91
+ ] ;
92
+
93
+ let patched = false ;
94
+ for ( const { pattern, replacement, name } of fallbackPatterns ) {
95
+ if ( pattern . test ( content ) ) {
96
+ content = content . replace ( pattern , replacement ) ;
97
+ fs . writeFileSync ( utilsPath , content ) ;
98
+ console . log ( '✅ Successfully patched NX utils.js with debug logging (' + name + ')' ) ;
99
+ patched = true ;
100
+ break ;
101
+ }
102
+ }
103
+
104
+ if ( ! patched ) {
105
+ console . log ( '⚠️ Could not find any matching pattern to patch. Dumping file info for debugging:' ) ;
106
+ const lines = content . split ( '\n' ) ;
107
+ const relevantLines = lines . filter ( ( line , i ) =>
108
+ line . includes ( 'getTargetConfigurationForTask' ) ||
109
+ line . includes ( 'projectGraph.nodes' ) ||
110
+ line . includes ( '.data' )
111
+ ) . map ( ( line , i ) => 'Line ' + ( lines . indexOf ( line ) + 1 ) + ': ' + line . trim ( ) ) ;
112
+ console . log ( '🔍 Relevant lines found:' , relevantLines . slice ( 0 , 10 ) ) ;
113
+ console . log ( '⚠️ Skipping patch - this won\'t break the build but debug info won\'t be available' ) ;
114
+ process . exit ( 0 ) ; // Don't fail the build
115
+ }
52
116
}
0 commit comments