Skip to content

Bundle the extension, so the .vsix carries its dependencies as resolved - #45

Merged
Kinflou merged 1 commit into
mainfrom
deps/bundle-esbuild
Nov 16, 2026
Merged

Kinflou merged 1 commit into
mainfrom
deps/bundle-esbuild

Conversation

@Kinflou

@Kinflou Kinflou commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Depends on #44, which is merged; this is rebased on it, so the diff is only the bundling commit.

The bug

The .vsix has never carried the dependencies it was resolved to. vsce package --yarn builds its file list from yarn list --prod, which hoists for the production tree only, and then copies the top-level node_modules/<name> from the real install, where the development dependencies decide what is hoisted. So each package gets whichever copy is most common among all dependencies, not the one its dependent asked for. Measured on the .vsix of main (after #44, CI run 43778646724, test-vsix):

in the package vscode-languageclient asks for
minimatch 3.1.5 (eslint 8's copy; 3.1.2 in v0.1.0-dev.59) minimatch ^5.1.0, which is locked at 5.1.9 and was never packaged: no vscode-languageclient/node_modules in the .vsix
brace-expansion 2.1.8 what minimatch 3 asks for is ^1; what 5.1.9 asks for is ^2

It happened to work (vscode-languageclient only uses new minimatch.Minimatch(...)), but any change to the development tree could change what ships; it was about to (see the eslint pull request, where minimatch 10 would have been packaged, a version that needs Node 18 or later).

The fix

scripts/bundle.mjs bundles src/extension.ts with esbuild into one file, dist/extension.js: cjs, platform: node, vscode external, target: node16 (VS Code ^1.75's extension host is Node 16.14). Every require is resolved by Node's rules from the file that makes it, so vscode-languageclient gets its own minimatch 5.1.9.

  • main is ./dist/extension.js. vscode:prepublish is yarn compile && yarn bundle:production: tsc stays as the type check (a type error still fails packaging), then the production bundle, minified, with no source map. yarn bundle is the development build (unminified, with a map).
  • tsc also stays what builds out/ for yarn test (node --test out/*.test.js) and for scripts/flatpak-e2e.cjs, which loads out/resolve.js; the Flatpak workflow's compile job runs yarn compile and uploads out/, so neither changed. The Flatpak workflow runs on this pull request and passes.
  • vsce package --yarn is vsce package --no-dependencies everywhere (ci.yml, release.yml, scripts/package.sh): vsce no longer lists or copies dependencies, and --yarn only selected how it listed them. .vscodeignore adds node_modules/** and out/** as well, so nothing but the bundle and the non-JavaScript assets is packaged.
  • esbuild is a devDependency, pinned exactly (0.28.2). vscode-languageclient stays in dependencies: it is a runtime dependency, now bundled.
  • .gitignore, the F5 launch config and task (bundle, dist/), README and QUICKSTART follow.
  • idpSchema.generated.json, which was a separate file under out/, is part of the bundle (resolveJsonModule).

What the package holds, before and after

Release (universal) package, from CI artifacts:

main (#44) this pull request
files 224 22
size 385,562 bytes (376 KB), 1.33 MB unpacked 157,240 bytes (153.6 KB), 393,452 bytes dist/extension.js (384.2 KB)
extension/node_modules/** 198 files: vscode-languageclient, semver, vscode-languageserver-protocol, vscode-jsonrpc, vscode-languageserver-types, balanced-match, minimatch, brace-expansion none
extension/out/** coreRev.js, extension.js, idpSchema.js, idpSchema.generated.json, resolve.js none
extension/dist/extension.js the bundle

Everything else is the same 20 files (manifest, package.json, readme and changelog, LICENSE, QUICKSTART, TESTING, language configurations, renovate.json, example, font, icons, the three grammars and their notices). The five platform packages are the same plus the language server binary (23 files, 3.5 to 4 MB). The new check on the Package jobs prints ... 23 files, no node_modules, main is ./dist/extension.js for each.

Which minimatch is in the bundle

The production build prints every package that went in (scripts/bundle.mjs --report, run by vscode:prepublish, in the Package Test log):

dist/extension.js  384.2kb
Packages in the bundle:
  balanced-match@1.0.2  (node_modules/balanced-match)
  brace-expansion@2.1.8  (node_modules/brace-expansion)
  minimatch@5.1.9  (node_modules/vscode-languageclient/node_modules/minimatch)
  semver@7.7.3  (node_modules/semver)
  vscode-jsonrpc@8.2.0  (node_modules/vscode-jsonrpc)
  vscode-languageclient@9.0.1  (node_modules/vscode-languageclient)
  vscode-languageserver-protocol@3.17.5  (node_modules/vscode-languageserver-protocol)
  vscode-languageserver-types@3.17.5  (node_modules/vscode-languageserver-types)

It is read from esbuild's metafile (the files it actually bundled), not from a grep of the minified output, where no version string survives. minimatch 5.1.9 and brace-expansion 2.1.8 are both outside every open advisory range, so the shipped alerts are cleared by what is packaged, not only by the lock.

Does it activate

The release.yml smoke test runs the language server binary, not the extension, and nothing in the repo starts the extension in an editor (no @vscode/test-electron), so I added what CI can check:

  • scripts/check-package.sh (Package Test and every release.yml Package job): the .vsix has dist/extension.js, main points to it, and it has no node_modules and no out/. A package that regresses to the old shape fails.
  • scripts/check-bundle.cjs, in Package Test, on Node 16.20.2 (the extension host of the oldest allowed editor): unzips the package, loads extension/dist/extension.js the way the editor does with vscode stubbed, and requires activate() and deactivate() to be exported. It passed: node v16.20.2: loading ... loaded: exports activate() and deactivate(). It catches a module the bundle needs but lacks and syntax Node 16 cannot parse. It does not call activate(), which needs an editor; that I could not test.

CI

All checks pass on this pull request: Lint and Compile, Package Test, Config schema, Language server pin, Flatpak (VSCodium sandbox), and Release Extension with all six Package jobs.

@Kinflou
Kinflou force-pushed the deps/bundle-esbuild branch from 1d34a3c to 00e549b Compare November 16, 2026 00:09
@Kinflou
Kinflou marked this pull request as ready for review November 16, 2026 00:23
@Kinflou
Kinflou merged commit fa87d36 into main Nov 16, 2026
28 checks passed
@Kinflou
Kinflou deleted the deps/bundle-esbuild branch November 16, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant