Skip to content

Commit 87e40b4

Browse files
committed
fix postinstall script
1 parent 01b83bd commit 87e40b4

File tree

2 files changed

+87
-22
lines changed

2 files changed

+87
-22
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

patch-nx-debug.js

Lines changed: 86 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
33
const fs = require('fs');
44
const path = require('path');
55

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+
];
712

813
console.log('🔧 Patching NX utils.js to add target debugging...');
14+
console.log('🔍 Current working directory:', process.cwd());
15+
console.log('🔍 Script directory:', __dirname);
916

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
1331
}
1432

1533
let content = fs.readFileSync(utilsPath, 'utf8');
@@ -21,32 +39,78 @@ if (content.includes('SPRING_BOOT_DEBUG')) {
2139
}
2240

2341
// Add debugging to getTargetConfigurationForTask function
24-
const originalPattern = /function getTargetConfigurationForTask\(task, projectsConfigurations\) \{/;
25-
const patchedFunction = `function getTargetConfigurationForTask(task, projectsConfigurations) {
42+
const originalPattern = /function getTargetConfigurationForTask\(task, projectGraph\) \{\s*const project = projectGraph\.nodes\[task\.target\.project\]\.data;/;
43+
const replacement = `function getTargetConfigurationForTask(task, projectGraph) {
2644
// SPRING_BOOT_DEBUG: Log task details before potential error
2745
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+
}
3053
31-
try {`;
54+
const project = projectGraph.nodes[task.target.project].data;`;
3255

3356
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);
3659

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-
4760
fs.writeFileSync(utilsPath, content);
4861
console.log('✅ Successfully patched NX utils.js with debug logging');
4962
} else {
5063
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: /const project = projectGraph\.nodes\[task\.target\.project\]\.data;/,
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: /(const project = projectGraph\.nodes\[task\.target\.project\]\.data;)/,
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+
}
52116
}

0 commit comments

Comments
 (0)