Skip to content

Commit 8c78a75

Browse files
author
Tajudeen
committed
Fix production build: Copy React components to out-build/ directory
- Fix React build script to copy files to both out/ and out-build/ directories - Production builds use out-build/, development uses out/ - Copy all files (not just .js) including chunks, CSS, source maps - Integrate React build into production build process (compile-build tasks) - Add error handling for React component imports to prevent blank screens
1 parent 329afa6 commit 8c78a75

File tree

4 files changed

+73
-20
lines changed

4 files changed

+73
-20
lines changed

build/gulpfile.compile.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@ const util = require('./lib/util');
1111
const date = require('./lib/date');
1212
const task = require('./lib/task');
1313
const compilation = require('./lib/compilation');
14+
const { execSync } = require('child_process');
15+
const path = require('path');
16+
17+
/**
18+
* Task to build React components for production
19+
*/
20+
const buildReactTask = task.define('build-react', () => {
21+
return new Promise((resolve, reject) => {
22+
try {
23+
const reactBuildPath = path.join(__dirname, '../src/vs/workbench/contrib/cortexide/browser/react');
24+
// allow-any-unicode-next-line
25+
console.log('🔨 Building React components...');
26+
execSync('node build.js', {
27+
cwd: reactBuildPath,
28+
stdio: 'inherit'
29+
});
30+
// allow-any-unicode-next-line
31+
console.log('✅ React components built successfully');
32+
resolve();
33+
} catch (error) {
34+
// allow-any-unicode-next-line
35+
console.error('❌ Error building React components:', error);
36+
reject(error);
37+
}
38+
});
39+
});
1440

1541
/**
1642
* @param {boolean} disableMangle
@@ -20,6 +46,7 @@ function makeCompileBuildTask(disableMangle) {
2046
util.rimraf('out-build'),
2147
date.writeISODate('out-build'),
2248
compilation.compileApiProposalNamesTask,
49+
buildReactTask, // Build React components before compiling
2350
compilation.compileTask('src', 'out-build', true, { disableMangle })
2451
);
2552
}

src/vs/platform/native/electron-main/nativeHostMainService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
502502
}
503503

504504
private async getShellCommandLink(): Promise<{ readonly source: string; readonly target: string }> {
505-
const target = resolve(this.environmentMainService.appRoot, 'bin', 'code');
505+
const target = resolve(this.environmentMainService.appRoot, 'bin', this.productService.applicationName);
506506
const source = `/usr/local/bin/${this.productService.applicationName}`;
507507

508508
// Ensure source exists
@@ -771,7 +771,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
771771

772772
// macOS
773773
if (this.environmentMainService.isBuilt) {
774-
return join(this.environmentMainService.appRoot, 'bin', 'code');
774+
return join(this.environmentMainService.appRoot, 'bin', `${this.productService.applicationName}`);
775775
}
776776

777777
return join(this.environmentMainService.appRoot, 'scripts', 'code-cli.sh');

src/vs/workbench/contrib/cortexide/browser/cortexideCommandBarService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ type VoidCommandBarModule = typeof import('./react/out/void-editor-widgets-tsx/i
3232
let mountVoidCommandBarPromise: Promise<VoidCommandBarModule['mountVoidCommandBar']> | undefined;
3333
function getMountVoidCommandBar() {
3434
if (!mountVoidCommandBarPromise) {
35-
mountVoidCommandBarPromise = import('./react/out/void-editor-widgets-tsx/index.js').then(m => m.mountVoidCommandBar);
35+
mountVoidCommandBarPromise = import('./react/out/void-editor-widgets-tsx/index.js')
36+
.then(m => m.mountVoidCommandBar)
37+
.catch(error => {
38+
console.error('[CortexideCommandBar] Failed to load React component:', error);
39+
// Return a no-op function to prevent crashes
40+
return () => { /* no-op */ };
41+
});
3642
}
3743
return mountVoidCommandBarPromise;
3844
}

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

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ function doesPathExist(filePath) {
2727
}
2828

2929
/*
30-
30+
3131
This function finds `globalDesiredPath` given `localDesiredPath` and `currentPath`
32-
32+
3333
Diagram:
34-
34+
3535
...basePath/
36-
└── void/
37-
├── ...currentPath/ (defined globally)
38-
└── ...localDesiredPath/ (defined locally)
39-
36+
- void/
37+
- ...currentPath/ (defined globally)
38+
- ...localDesiredPath/ (defined locally)
39+
4040
*/
4141
function findDesiredPathFromLocalPath(localDesiredPath, currentPath) {
4242

@@ -322,13 +322,16 @@ if (isWatch) {
322322
// Check if src2/ exists; if not, do an initial scope-tailwind build
323323
if (!fs.existsSync('src2')) {
324324
try {
325+
// allow-any-unicode-next-line
325326
console.log('🔨 Running initial scope-tailwind build to create src2 folder...');
326327
execSync(
327328
'npx scope-tailwind ./src -o src2/ -s void-scope -c styles.css -p "void-"',
328329
{ stdio: 'inherit' }
329330
);
331+
// allow-any-unicode-next-line
330332
console.log('✅ src2/ created successfully.');
331333
} catch (err) {
334+
// allow-any-unicode-next-line
332335
console.error('❌ Error running initial scope-tailwind build:', err);
333336
process.exit(1);
334337
}
@@ -378,9 +381,11 @@ if (isWatch) {
378381
process.exit();
379382
});
380383

384+
// allow-any-unicode-next-line
381385
console.log('🔄 Watchers started! Press Ctrl+C to stop both watchers.');
382386
} else {
383387
// Build mode
388+
// allow-any-unicode-next-line
384389
console.log('📦 Building...');
385390

386391
// Run scope-tailwind once
@@ -393,21 +398,21 @@ if (isWatch) {
393398
console.log('🔧 Fixing import paths...');
394399
fixImportPaths();
395400

396-
// Copy fixed files to out/ directory
401+
// Copy fixed files to out/ and out-build/ directories
397402
// IMPORTANT: fixImportPaths() must run BEFORE this copy step
398403
// The files in src/vs/.../react/out/ have been fixed with absolute imports
399-
// We need to copy those fixed files to out/vs/.../react/out/
400-
console.log('📋 Copying files to out/ directory...');
404+
// We need to copy those fixed files to both out/ and out-build/ directories
405+
// Production builds use out-build/, while development uses out/
406+
// allow-any-unicode-next-line
407+
console.log('📋 Copying files to out/ and out-build/ directories...');
401408
const srcOutDir = path.join(__dirname, 'out');
402409
const outReactOutDir = path.join(__dirname, '../../../../../../../out/vs/workbench/contrib/cortexide/browser/react/out');
410+
const outBuildReactOutDir = path.join(__dirname, '../../../../../../../out-build/vs/workbench/contrib/cortexide/browser/react/out');
403411

404412
if (!fs.existsSync(srcOutDir)) {
405413
console.log(' Source out directory does not exist, skipping copy');
406414
} else {
407-
if (!fs.existsSync(outReactOutDir)) {
408-
fs.mkdirSync(outReactOutDir, { recursive: true });
409-
}
410-
415+
// Copy function that copies all files, not just .js files
411416
function copyDir(src, dest) {
412417
if (!fs.existsSync(dest)) {
413418
fs.mkdirSync(dest, { recursive: true });
@@ -418,15 +423,30 @@ if (isWatch) {
418423
const destPath = path.join(dest, entry.name);
419424
if (entry.isDirectory()) {
420425
copyDir(srcPath, destPath);
421-
} else if (entry.isFile() && entry.name.endsWith('.js')) {
422-
// Copy the fixed file (with absolute imports) to the out directory
426+
} else if (entry.isFile()) {
427+
// Copy all files (not just .js) - includes chunks, CSS, source maps, etc.
423428
fs.copyFileSync(srcPath, destPath);
424429
}
425430
}
426431
}
432+
433+
// Copy to out/ directory (for development)
434+
if (!fs.existsSync(outReactOutDir)) {
435+
fs.mkdirSync(outReactOutDir, { recursive: true });
436+
}
427437
copyDir(srcOutDir, outReactOutDir);
428-
console.log(' Copied fixed files to out/ directory');
438+
// allow-any-unicode-next-line
439+
console.log(' ✓ Copied fixed files to out/ directory');
440+
441+
// Copy to out-build/ directory (for production builds)
442+
if (!fs.existsSync(outBuildReactOutDir)) {
443+
fs.mkdirSync(outBuildReactOutDir, { recursive: true });
444+
}
445+
copyDir(srcOutDir, outBuildReactOutDir);
446+
// allow-any-unicode-next-line
447+
console.log(' ✓ Copied fixed files to out-build/ directory');
429448
}
430449

450+
// allow-any-unicode-next-line
431451
console.log('✅ Build complete!');
432452
}

0 commit comments

Comments
 (0)