From 27ccba8d0e2756ce198b4e555eae945f615c6eb1 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Wed, 10 Mar 2021 12:18:01 -0800 Subject: [PATCH] build: Switch to esbuild instead of rollup for the client and banner We have found that the performance with esbuild is much better than using rollup and especially rollup+terser. This allows us to efficiently build, minify, and treeshake the client code, especially with respect to the new dependency on the typescript scanner for the client middleware. We still need to investigate how or if we can use esbuild for the server code as well. Since it does not support the 'amd' format, we need to see if there is another way to configure it to generate the output we need to use the `define` from the banner for requires. --- banner.rollup.config.js | 13 -------- esbuild.js | 67 +++++++++++++++++++++++++++++++++++++++++ package.json | 6 ++-- rollup.config.js | 20 ++---------- yarn.lock | 29 +++++++++++++----- 5 files changed, 93 insertions(+), 42 deletions(-) delete mode 100644 banner.rollup.config.js create mode 100644 esbuild.js diff --git a/banner.rollup.config.js b/banner.rollup.config.js deleted file mode 100644 index fadebcedb7..0000000000 --- a/banner.rollup.config.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = [ - { - input: 'dist/banner/banner.js', - output: { - file: 'dist/banner/banner.rollup.js', - format: 'cjs', - }, - external: [ - 'path', - ], - }, - -]; diff --git a/esbuild.js b/esbuild.js new file mode 100644 index 0000000000..53094115d1 --- /dev/null +++ b/esbuild.js @@ -0,0 +1,67 @@ +const esbuild = require('esbuild'); +const fs = require('fs'); + +const defaultOptions = { + bundle: true, + platform: 'node', + logLevel: 'info', +}; + +/** @type esbuild.BuildOptions */ +const clientConfig = { + ...defaultOptions, + entryPoints: ['dist/client/extension.js'], + outfile: 'dist/npm/index.js', + external: [ + 'fs', + 'path', + 'vscode', + 'vscode-languageclient/node', + 'vscode-languageserver-protocol', + 'vscode-jsonrpc', + ], + format: 'cjs', + minify: true, +}; + +/** @type esbuild.BuildOptions */ +const bannerConfig = { + ...defaultOptions, + entryPoints: ['dist/banner/banner.js'], + outfile: 'dist/banner/banner.esbuild.js', + external: [ + 'path', + ], + format: 'cjs', +}; + +/** @type esbuild.BuildOptions */ +const serverConfig = { + ...defaultOptions, + entryPoints: ['dist/server/server.js'], + outfile: 'dist/npm/server/index.js', + external: [ + 'fs', + 'path', + 'typescript/lib/tsserverlibrary', + 'vscode-languageserver', + 'vscode-uri', + 'vscode-jsonrpc', + ], + // TODO(atscott): Figure out how to use the banner correctly. + // iife format produces a `require("typescript/lib/tsserverlibrary");` line but it needs to use + // the `define` in the banner to resolve tsserverlibrary. + format: 'iife', +}; + +async function build() { + try { + await esbuild.build(clientConfig); + await esbuild.build(bannerConfig); + } catch (e) { + console.error(e); + process.exit(1); + } +} + +build(); \ No newline at end of file diff --git a/package.json b/package.json index 06456191e9..8c48320dae 100644 --- a/package.json +++ b/package.json @@ -136,8 +136,7 @@ ], "main": "./dist/client/extension", "scripts": { - "compile": "yarn compile:banner && tsc -b && rollup -c", - "compile:banner": "tsc -p server/banner.tsconfig.json && rollup -c banner.rollup.config.js", + "compile": "tsc -p server/banner.tsconfig.json && tsc -b && node esbuild.js && rollup -c", "compile:test": "tsc -b server/src/tests", "compile:integration": "tsc -b integration", "compile:syntaxes-test": "tsc -b syntaxes/test", @@ -163,6 +162,7 @@ "@types/jasmine": "3.6.3", "@types/node": "12.19.16", "clang-format": "1.5.0", + "esbuild": "^0.9.0", "jasmine": "3.6.4", "prettier": "2.2.1", "rollup": "2.38.5", @@ -178,4 +178,4 @@ "type": "git", "url": "https://github.com/angular/vscode-ng-language-service" } -} +} \ No newline at end of file diff --git a/rollup.config.js b/rollup.config.js index 42722998f3..5c5d91a554 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,28 +2,12 @@ import * as fs from 'fs'; import commonjs from 'rollup-plugin-commonjs'; module.exports = [ - { - input: 'dist/client/extension.js', - output: { - file: 'dist/npm/index.js', - format: 'cjs', - exports: 'named', - }, - external: [ - 'path', - 'vscode', - 'vscode-languageclient', - ], - plugins: [ - commonjs(), - ], - }, { input: 'dist/server/server.js', output: { file: 'dist/npm/server/index.js', format: 'amd', - banner: fs.readFileSync('dist/banner/banner.rollup.js', 'utf8'), + banner: fs.readFileSync('dist/banner/banner.esbuild.js', 'utf8'), }, external: [ 'fs', @@ -41,4 +25,4 @@ module.exports = [ }), ], }, -]; +]; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 590714225a..d4e4fafe64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -34,9 +34,9 @@ integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw== "@types/estree@*": - version "0.0.45" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.45.tgz#e9387572998e5ecdac221950dab3e8c3b16af884" - integrity sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g== + version "0.0.46" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.46.tgz#0fb6bfbbeabd7a30880504993369c4bf1deab1fe" + integrity sha512-laIjwTQaD+5DukBZaygQ79K1Z0jb1bPEMRrkXSLjtCcZm+abyp5YbrqpSLzD42FwWW6gK/aS4NYpJ804nG2brg== "@types/jasmine@3.6.3": version "3.6.3" @@ -331,6 +331,11 @@ es6-promisify@^5.0.0: dependencies: es6-promise "^4.0.3" +esbuild@^0.9.0: + version "0.9.0" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.9.0.tgz#b8320df85048ed1637c6b59ee52abba248936d3c" + integrity sha512-IqYFO7ZKHf0y4uJpJfGqInmSRn8jMPMbyI1W0Y2PSjSjJcVP538tC8TleJAS4Y8QeqwajqBTwFKayWVzYlMIgg== + escape-string-regexp@1.0.5, escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -364,9 +369,9 @@ fs.realpath@^1.0.0: integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= fsevents@~2.3.1: - version "2.3.1" - resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.1.tgz#b209ab14c61012636c8863507edf7fb68cc54e9f" - integrity sha512-YR47Eg4hChJGAB1O3yEAOkGO+rlzutoICGqGo9EZ4lKWokzZRSyIW1QmTzqjtw8MJdj9srP869CuWw/hyzSiBw== + version "2.3.2" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== function-bind@^1.1.1: version "1.1.1" @@ -477,7 +482,7 @@ inherits@2, inherits@^2.0.1, inherits@^2.0.3: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== -is-core-module@^2.1.0: +is-core-module@^2.1.0, is-core-module@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.2.0.tgz#97037ef3d52224d85163f5597b2b63d9afed981a" integrity sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ== @@ -741,7 +746,7 @@ readable-stream@^3.1.1: string_decoder "^1.1.1" util-deprecate "^1.0.1" -resolve@^1.1.6, resolve@^1.11.0, resolve@^1.3.2: +resolve@^1.1.6, resolve@^1.3.2: version "1.19.0" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c" integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg== @@ -749,6 +754,14 @@ resolve@^1.1.6, resolve@^1.11.0, resolve@^1.3.2: is-core-module "^2.1.0" path-parse "^1.0.6" +resolve@^1.11.0: + version "1.20.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" + integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A== + dependencies: + is-core-module "^2.2.0" + path-parse "^1.0.6" + rollup-plugin-commonjs@10.1.0: version "10.1.0" resolved "https://registry.yarnpkg.com/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz#417af3b54503878e084d127adf4d1caf8beb86fb"