Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support bundling Theia with esbuild #14414

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ errorShots
examples/*/src-gen
examples/*/gen-webpack.config.js
examples/*/gen-webpack.node.config.js
examples/*/gen-esbuild.*.mjs
examples/*/.test
.browser_modules
**/docs/api
Expand Down
4 changes: 4 additions & 0 deletions dev-packages/application-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@theia/application-package": "1.55.0",
"@theia/ffmpeg": "1.55.0",
"@theia/native-webpack-plugin": "1.55.0",
"@theia/native-esbuild-plugin": "1.55.0",
"@types/fs-extra": "^4.0.2",
"@types/semver": "^7.5.0",
"babel-loader": "^8.2.2",
Expand All @@ -44,6 +45,9 @@
"copy-webpack-plugin": "^8.1.1",
"css-loader": "^6.2.0",
"electron-rebuild": "^3.2.7",
"esbuild": "^0.24.0",
"esbuild-plugins-node-modules-polyfill": "^1.6.7",
"esbuild-plugin-copy": "^2.1.1",
"fs-extra": "^4.0.2",
"http-server": "^14.1.1",
"ignore-loader": "^0.1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as fs from 'fs-extra';
import * as cp from 'child_process';
import * as semver from 'semver';
import { ApplicationPackage, ApplicationPackageOptions } from '@theia/application-package';
import { WebpackGenerator, FrontendGenerator, BackendGenerator } from './generator';
import { BundlerGenerator, FrontendGenerator, BackendGenerator } from './generator';
import { ApplicationProcess } from './application-process';
import { GeneratorOptions } from './generator/abstract-generator';
import yargs = require('yargs');
Expand Down Expand Up @@ -73,12 +73,14 @@ export class ApplicationPackageManager {
}

async clean(): Promise<void> {
const webpackGenerator = new WebpackGenerator(this.pck);
const bundlerGenerator = new BundlerGenerator(this.pck);
await Promise.all([
this.remove(this.pck.lib()),
this.remove(this.pck.srcGen()),
this.remove(webpackGenerator.genConfigPath),
this.remove(webpackGenerator.genNodeConfigPath)
this.remove(bundlerGenerator.genConfigPath),
this.remove(bundlerGenerator.genNodeConfigPath),
this.remove(bundlerGenerator.genESBuildBrowserPath),
this.remove(bundlerGenerator.genESBuildNodePath),
]);
}

Expand All @@ -99,7 +101,7 @@ export class ApplicationPackageManager {
throw error;
}
await Promise.all([
new WebpackGenerator(this.pck, options).generate(),
new BundlerGenerator(this.pck, options).generate(),
new BackendGenerator(this.pck, options).generate(),
new FrontendGenerator(this.pck, options).generate(),
]);
Expand All @@ -111,9 +113,15 @@ export class ApplicationPackageManager {
}

async build(args: string[] = [], options: GeneratorOptions = {}): Promise<void> {
const bundlerGenerator = new BundlerGenerator(this.pck);
await this.generate(options);
await this.copy();
return this.__process.run('webpack', args);
if (await bundlerGenerator.preferESBuild()) {
const process = this.__process.spawn('node', [bundlerGenerator.esbuildPath, ...args]);
return this.__process.promisify('esbuild', process);
} else {
return this.__process.run('webpack', args);
}
}

start(args: string[] = []): cp.ChildProcess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ApplicationProcess {
return process.platform === 'win32' ? commandPath + '.cmd' : commandPath;
}

protected promisify(command: string, p: cp.ChildProcess): Promise<void> {
promisify(command: string, p: cp.ChildProcess): Promise<void> {
return new Promise((resolve, reject) => {
p.stdout!.on('data', data => this.pck.log(data.toString()));
p.stderr!.on('data', data => this.pck.error(data.toString()));
Expand Down
Loading
Loading