Skip to content

Commit 6b748bb

Browse files
author
Tajudeen
committed
Fix: Add 2 levels (not 1) to deep relative imports + add logging
The original import '../../../../../base/...' has 5 levels, but from the output location we need 7 levels. The fix was only adding 1 level, causing the 'platform is not defined' error. Changes: - Fix path adjustment to add 2 levels instead of 1 - Add detailed logging to track when fixes run and what files are affected - Log missing files and count of fixed files for better debugging
1 parent c136af2 commit 6b748bb

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

  • src/vs/workbench/contrib/cortexide/browser/react

src/vs/workbench/contrib/cortexide/browser/react/build.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,14 @@ if (isWatch) {
209209
'diff'
210210
];
211211

212+
let fixedCount = 0;
213+
const missingFiles = [];
214+
212215
for (const module of reactOutputModules) {
213216
const indexPath = path.join(outDir, module, 'index.js');
214217
if (fs.existsSync(indexPath)) {
215218
let content = fs.readFileSync(indexPath, 'utf8');
219+
const originalContent = content;
216220
// Fix import paths: React outputs are in sibling directories under out/
217221
// Replace './react/out/MODULE/index.js' with '../MODULE/index.js'
218222
// Replace '../react/out/MODULE/index.js' with '../../MODULE/index.js'
@@ -238,29 +242,45 @@ if (isWatch) {
238242
// Fix deep relative imports to VS Code platform/base modules
239243
// When tsup builds, relative imports are preserved, but the output file location
240244
// is different, so paths need adjustment. From out/MODULE/index.js, we need
241-
// one more level up to reach the same target as from the source location.
242-
// Example: ../../../../../base/... needs to become ../../../../../../base/...
245+
// two more levels up to reach the same target as from the source location.
246+
// Example: ../../../../../base/... (5 levels) needs to become ../../../../../../base/... (7 levels)
243247
// This fixes imports like: import { x } from '../../../../../base/common/platform.js'
244248
// which come from files like systemInfo.ts that import VS Code internal modules
245-
// Match any relative import (../...) that leads to base/platform/editor/workbench and add one more level
249+
// Match any relative import (../...) that leads to base/platform/editor/workbench and add two more levels
246250
// Handle: import statements, dynamic imports, and require() calls
247251
content = content.replace(
248252
/(from\s+['\"])((?:\.\.\/)+)(base|platform|editor|workbench)\//g,
249-
(match, prefix, dots, module) => `${prefix}${dots}../${module}/`
253+
(match, prefix, dots, module) => `${prefix}${dots}../../${module}/`
250254
);
251255
content = content.replace(
252256
/(import\s*\(\s*['\"])((?:\.\.\/)+)(base|platform|editor|workbench)\//g,
253-
(match, prefix, dots, module) => `${prefix}${dots}../${module}/`
257+
(match, prefix, dots, module) => `${prefix}${dots}../../${module}/`
254258
);
255259
content = content.replace(
256260
/(require\(['\"])((?:\.\.\/)+)(base|platform|editor|workbench)\//g,
257-
(match, prefix, dots, module) => `${prefix}${dots}../${module}/`
261+
(match, prefix, dots, module) => `${prefix}${dots}../../${module}/`
258262
);
259263

260-
fs.writeFileSync(indexPath, content, 'utf8');
264+
if (content !== originalContent) {
265+
fs.writeFileSync(indexPath, content, 'utf8');
266+
fixedCount++;
267+
console.log(` ✓ Fixed paths in ${module}/index.js`);
268+
}
269+
} else {
270+
missingFiles.push(module);
261271
}
262272
}
263273

274+
if (fixedCount > 0) {
275+
// allow-any-unicode-next-line
276+
console.log(`✅ Fixed import paths in ${fixedCount} React output files`);
277+
} else {
278+
console.log('⚠ No files needed fixing (paths already correct or files not found)');
279+
}
280+
if (missingFiles.length > 0) {
281+
console.log(`⚠ Missing files: ${missingFiles.join(', ')}`);
282+
}
283+
264284
// allow-any-unicode-next-line
265285
console.log('✅ Build complete!');
266286
}

0 commit comments

Comments
 (0)