-
Notifications
You must be signed in to change notification settings - Fork 17
GLSP-1693: Switch bundling to esbuild #142
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
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| # Populated by `yarn start` (verbatim assets + synced worker bundle + webpack output) | ||
| # Populated by `yarn start` (verbatim assets + synced worker bundle + esbuild output) | ||
| dist/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 EclipseSource and others. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License v. 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0. | ||
| * | ||
| * This Source Code may also be made available under the following Secondary | ||
| * Licenses when the conditions for such availability set forth in the Eclipse | ||
| * Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
| * with the GNU Classpath Exception which is available at | ||
| * https://www.gnu.org/software/classpath/license.html. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
| ********************************************************************************/ | ||
| // @ts-check | ||
| const { resolve } = require('node:path'); | ||
| const esbuild = require('esbuild'); | ||
|
|
||
| const watch = process.argv.slice(2).includes('--watch'); | ||
|
|
||
| /** | ||
| * Reports the build progress and surfaces errors/warnings in a format that | ||
| * VS Code's `$esbuild-watch` problem matcher can pick up. | ||
| * @type {import('esbuild').Plugin} | ||
| */ | ||
| const esbuildProblemMatcherPlugin = { | ||
| name: 'esbuild-problem-matcher', | ||
| setup(build) { | ||
| build.onStart(() => { | ||
| console.log(`${watch ? '[watch] ' : ''}build started`); | ||
| }); | ||
| build.onEnd(result => { | ||
| result.errors.forEach(({ text, location }) => { | ||
| console.error(`✘ [ERROR] ${text}`); | ||
| if (location) { | ||
| console.error(` ${location.file}:${location.line}:${location.column}:`); | ||
| } | ||
| }); | ||
| console.log(`${watch ? '[watch] ' : ''}build finished`); | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| // Bundle `vscode-jsonrpc/browser` plus the page-side script into a single file emitted into | ||
| // `dist/`, alongside the verbatim assets copied from `public/` and the worker bundle synced | ||
| // from `@eclipse-glsp-examples/workflow-server-bundled-web` by `scripts/prepare-dist.mjs`. | ||
| /** @type {import('esbuild').BuildOptions} */ | ||
| const config = { | ||
| entryPoints: [resolve(__dirname, 'src/index.js')], | ||
| outfile: resolve(__dirname, 'dist/index.bundle.js'), | ||
| bundle: true, | ||
| sourcemap: true, | ||
| platform: 'browser', | ||
| format: 'iife', | ||
| target: 'es2019', | ||
| mainFields: ['browser', 'module', 'main'], | ||
| conditions: ['browser'], | ||
| logLevel: 'silent', | ||
| plugins: [esbuildProblemMatcherPlugin] | ||
| }; | ||
|
|
||
| async function main() { | ||
| if (watch) { | ||
| const ctx = await esbuild.context(config); | ||
| await ctx.watch(); | ||
| } else { | ||
| await esbuild.build(config); | ||
| } | ||
| } | ||
|
|
||
| main().catch(e => { | ||
| console.error(e); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2022-2026 EclipseSource and others. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License v. 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0. | ||
| * | ||
| * This Source Code may also be made available under the following Secondary | ||
| * Licenses when the conditions for such availability set forth in the Eclipse | ||
| * Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
| * with the GNU Classpath Exception which is available at | ||
| * https://www.gnu.org/software/classpath/license.html. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
| ********************************************************************************/ | ||
| // @ts-check | ||
| const { spawn } = require('node:child_process'); | ||
| const { resolve } = require('node:path'); | ||
| const esbuild = require('esbuild'); | ||
|
|
||
| const argv = process.argv.slice(2); | ||
| const watch = argv.includes('--watch'); | ||
| // Dev mode: build only the node target and (re)start the server after each successful build. | ||
| const runNode = argv.includes('--run-node'); | ||
| // Everything after `--` is forwarded verbatim to the spawned node server (e.g. `--port 5007`). | ||
| const dashDash = argv.indexOf('--'); | ||
| const serverArgs = dashDash >= 0 ? argv.slice(dashDash + 1) : []; | ||
|
|
||
| const bundledDir = resolve(__dirname, '..', 'workflow-server-bundled'); | ||
| const bundledWebDir = resolve(__dirname, '..', 'workflow-server-bundled-web'); | ||
|
|
||
| /** | ||
| * Reports the build progress and surfaces errors/warnings in a format that | ||
| * VS Code's `$esbuild-watch` problem matcher can pick up. | ||
| * @type {import('esbuild').Plugin} | ||
| */ | ||
| const esbuildProblemMatcherPlugin = { | ||
| name: 'esbuild-problem-matcher', | ||
| setup(build) { | ||
| build.onStart(() => { | ||
| console.log(`${watch ? '[watch] ' : ''}build started`); | ||
| }); | ||
| build.onEnd(result => { | ||
| result.errors.forEach(({ text, location }) => { | ||
| console.error(`✘ [ERROR] ${text}`); | ||
| if (location) { | ||
| console.error(` ${location.file}:${location.line}:${location.column}:`); | ||
| } | ||
| }); | ||
| console.log(`${watch ? '[watch] ' : ''}build finished`); | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| /** @type {import('esbuild').BuildOptions} */ | ||
| const common = { | ||
| bundle: true, | ||
| // Minify one-shot production builds; keep watch/dev output readable and fast to rebuild. | ||
| // `sourcemap` still maps the (minified) output back to the original TypeScript sources. | ||
| minify: !watch, | ||
| // Preserve original class/function names through minification — GLSP's logger and error | ||
| // messages use `constructor.name` for labels, which would otherwise be mangled. | ||
| keepNames: true, | ||
| sourcemap: true, | ||
| logLevel: 'silent', | ||
| tsconfig: resolve(__dirname, 'tsconfig.json'), | ||
| plugins: [esbuildProblemMatcherPlugin] | ||
| }; | ||
|
|
||
| /** @type {import('esbuild').BuildOptions} */ | ||
| const nodeConfig = { | ||
| ...common, | ||
| entryPoints: [resolve(__dirname, 'src/node/app.ts')], | ||
| outfile: resolve(bundledDir, 'wf-glsp-server-node.js'), | ||
| platform: 'node', | ||
| format: 'cjs', | ||
| target: 'node22', | ||
| // `ws` requires these optional native deps in a try/catch; keep them external so the | ||
| // graceful-fallback path works and esbuild does not error on the missing modules. | ||
| external: ['bufferutil', 'utf-8-validate'] | ||
| }; | ||
|
|
||
| /** @type {import('esbuild').BuildOptions} */ | ||
| const webworkerConfig = { | ||
| ...common, | ||
| entryPoints: [resolve(__dirname, 'src/browser/app.ts')], | ||
| outfile: resolve(bundledWebDir, 'wf-glsp-server-webworker.js'), | ||
| platform: 'browser', | ||
| format: 'iife', | ||
| target: 'es2019', | ||
| // Honor the legacy `browser` package field + browser condition for transitive deps. | ||
| mainFields: ['browser', 'module', 'main'], | ||
| conditions: ['browser'] | ||
| }; | ||
|
|
||
| /** Restart the bundled node server after every successful build. */ | ||
| function runNodePlugin() { | ||
| /** @type {import('node:child_process').ChildProcess | undefined} */ | ||
| let child; | ||
| const stop = () => child?.kill('SIGTERM'); | ||
| process.on('SIGINT', () => { | ||
| stop(); | ||
| process.exit(0); | ||
| }); | ||
| return { | ||
| name: 'run-node-server', | ||
| setup(build) { | ||
| build.onEnd(result => { | ||
| if (result.errors.length > 0) { | ||
| // Keep the last good server running so a broken build does not crash the loop. | ||
| return; | ||
| } | ||
| stop(); | ||
| child = spawn('node', ['--enable-source-maps', nodeConfig.outfile, ...serverArgs], { stdio: 'inherit' }); | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| async function run(config) { | ||
| if (watch) { | ||
| const ctx = await esbuild.context(config); | ||
| await ctx.watch(); | ||
| } else { | ||
| await esbuild.build(config); | ||
| } | ||
| } | ||
|
|
||
| async function main() { | ||
| if (runNode) { | ||
| await run({ ...nodeConfig, plugins: [esbuildProblemMatcherPlugin, runNodePlugin()] }); | ||
| } else { | ||
| await Promise.all([run(nodeConfig), run(webworkerConfig)]); | ||
| } | ||
| } | ||
|
|
||
| main().catch(e => { | ||
| console.error(e); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,14 +46,15 @@ | |
| "browser.js" | ||
| ], | ||
| "scripts": { | ||
| "build": "tsc -b && yarn bundle && yarn bundle:browser", | ||
| "bundle": "webpack", | ||
| "bundle:browser": "webpack --env target=webworker ", | ||
| "build": "tsc -b && yarn bundle", | ||
| "bundle": "node esbuild.js", | ||
| "clean": "rimraf lib *.tsbuildinfo", | ||
| "dev": "node esbuild.js --watch --run-node -- --port 5007", | ||
| "dev:ws": "node esbuild.js --watch --run-node -- -w --port 8081", | ||
| "generate:index": "glsp generateIndex src/browser src/common src/node -s -f", | ||
| "lint": "eslint ./src", | ||
| "watch": "tsc -w", | ||
| "watch:bundle": "webpack -w" | ||
| "watch:bundle": "node esbuild.js --watch" | ||
| }, | ||
| "dependencies": { | ||
| "@eclipse-glsp/layout-elk": "2.8.0-next", | ||
|
|
@@ -62,9 +63,7 @@ | |
| "inversify": "^6.1.3" | ||
| }, | ||
| "devDependencies": { | ||
| "source-map-loader": "^4.0.1", | ||
| "webpack": "^5.75.0", | ||
| "webpack-cli": "^5.0.1" | ||
| "esbuild": "~0.25.9" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. outdated version |
||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outdated version.