Repository navigation
Open
Description
Context
The extension is currently CommonJS. This blocks us from consuming a growing number of modern, ESM-only dependencies. Concrete recent example: p-limit@4+ is pure ESM, which is why #685 introduced an in-house ConcurrencyLimiter instead of pulling a battle-tested library off the shelf.
vscode-cosmosdb (sibling extension, same org) has already completed this migration on main, so there is a working reference for what the end state looks like.
What this issue tracks
The actual migration. The choice of build system, test runner, linter/formatter, and Node target is still to be made as part of this work. Options to evaluate:
- Build: Vite (what vscode-cosmosdb chose) vs. continuing with webpack in ESM mode vs. esbuild vs. tsup.
- Test runner: Vitest (what vscode-cosmosdb chose) vs. Jest with ESM support vs. node:test.
- Linter/formatter: continue with ESLint + Prettier vs. switch to oxlint / oxfmt (faster, what vscode-cosmosdb chose).
- Node engine: bump to >=22 (matches vscode-cosmosdb) or hold lower.
- TypeScript: bump to latest (vscode-cosmosdb is on TS 6.x).
A short design note before the implementation PR is expected.
Concrete benefits
- Unblocks ESM-only dependencies:
p-limit,chalk,node-fetch,nanoid,execa, and a long and growing tail. - Smaller bundles and faster cold start (tree-shaking is much more effective on ESM).
- Faster build/test feedback loops if we adopt Vite + Vitest (sub-second incremental builds reported by vscode-cosmosdb).
- Aligns us with vscode-cosmosdb tooling, lowering the cognitive cost of moving between repos.
- Removes the mocha-based VS Code test runner pain point. The legacy
@vscode/test-electron+ mocha pipeline does not love ESM; vscode-cosmosdb works around this with apretesthook that drops a CJSpackage.jsonintoout/. The upstream story is that this runner has either already been removed or is on track to be removed, so the workaround should be temporary or unnecessary depending on when we land.
Known costs / risks
- Touches every file with a relative import (
./foo->./foo.jsin many ESM toolchains, depending on bundler/moduleResolution). - Webpack config rewrite or replacement.
- Jest -> alternative test runner migration (touches every test file's imports and mocks;
jest.mockdoes not have a 1:1 ESM equivalent). __dirname/requireremoval from the codebase.- Potential VS Code engine version bump.
- One-shot reviewer load: the diff will be large.
References
- PR perf(tree): throttle background document-count fetches #685 (the immediate motivating example).
- vscode-cosmosdb
package.jsonon main ("type": "module","main": "./main.mjs", Node >=22.18.0, Vite, Vitest, oxlint, oxfmt).
Acceptance criteria
- Decision recorded for each open choice above.
- All existing tests pass under the new test runner (or a documented, scoped exception list).
- Extension activates, builds, packages, and ships exactly as before.
- CI green.
- No CJS-only fallback shims remaining (e.g. no
pretest-stylepackage.jsonrewrite needed once the upstream test runner removal lands).
Metadata
Metadata
Assignees
Labels
No labels
Activity
tnaum-ms commentedon May 28, 2026
Tooling trade-offs (summary from review discussion)
Captured here for context before we make the decisions called out above.
Vitest (vs. Jest)
What it is. Test runner from the Vite team. Jest-compatible API, native ESM, native TypeScript via esbuild, reuses your Vite config so the test environment matches the build environment.
describe/it/expect/beforeEachare unchanged;jest.fn()->vi.fn(),jest.mock()->vi.mock().Why teams move off Jest:
--experimental-vm-modules, andjest.mock()of ESM modules has sharp edges (hoisting, partial mocks, top-level await). For a project migrating to ESM, dragging Jest along is the worst of both worlds.ts-jest/@swc/jest. TS via esbuild by default.vite.config.tsfor build and test. No duplicate path aliases ormoduleNameMapper.Why not leave Jest:
jest.mocksemantics are close but not 100% identical. Mocks sometimes need a small rewrite.jest-*matchers / reporters is shorter on the Vitest side (the popular ones are covered).--projectsfor monorepos is more battle-tested than Vitest workspaces.For this repo: ~1900 tests, mostly pure unit tests with light mocking. Port is mechanical, mostly
jest.->vi.find-and-replace.Vite (vs. webpack)
vscode, conditional driver imports.oxlint + oxfmt (vs. ESLint + Prettier)
Node >=22
fetch,--watch,node:test, top-level await,import.meta.resolve. Drop polyfill deps.engines.vscodemust be high enough that the bundled Node is >=22, which cuts off users on older VS Code. vscode-cosmosdb picked^1.109.0(recent but not bleeding-edge). Decide against installed-VS-Code-version telemetry.Lowest-risk recommendation
Vite + Vitest, keep ESLint + Prettier for now. Get 90% of the benefit with the smallest blast radius. oxlint/oxfmt is a separate, smaller decision later. The Node 22 bump is the only choice with real user-facing impact and deserves its own discussion.
tnaum-ms commentedon May 28, 2026
Build tool: Vite vs. esbuild vs. mixed (follow-up to the tooling summary above)
What vscode-cosmosdb actually picked
All-Vite, no esbuild as a separate tool. Two Vite configs:
vite.config.ext.mjs— extension host in Vite's "library mode" (build.lib),target: 'node22', ESM output (main.mjs), externalizesvscode+vs+ Node built-ins, bundles everything else.vite.config.views.mjs— webviews with@vitejs/plugin-react, dev server, Monaco workers, prod-only bundle analyzer.esbuild is still in the picture, just underneath Vite (Vite uses it for dev transform). They don't invoke it directly.
What that decision cost them
Reading their configs, they paid for "Vite everywhere" in non-trivial ways:
CJS-interop banner injected into every output file:
Needed because the output is ESM but the bundled CJS packages still call
require()at runtime.tslibaliased to its ESM build. Long comment in the ext config explains: Rolldown's__toESMinterop helper crashes on legacy Azure SDKs (@azure/arm-cosmosdb,@azure/arm-postgresql,@azure/arm-postgresql-flexible) compiled withimportHelpers: true. The fix istslib: path.resolve(__dirname, 'node_modules/tslib/tslib.es6.mjs'). A genuine landmine, defused with a one-line alias once you know what to look for.Six custom Vite plugins:
vite-plugin-no-extension-imports(guards webview code from importingvscode),vite-plugin-webview-entry(dev-mode entry shim),vite-plugin-react-refresh-preamble,vite-plugin-monaco-workers,vite-plugin-inline-css,vite-plugin-bundle-report.A dedicated
docs/webview-build.mdthat the config has anchor links into. They explicitly designed the configs to be terse and to defer rationale to that doc.So: meaningful investment, but they bought consistency. One tool, one mental model, one plugin API across both targets, and Vitest plugs in for free (shared config, shared transforms, shared resolver).
Option A: All-Vite (mirror vscode-cosmosdb)
For:
concurrentlysetups.docs/webview-build.mdlargely verbatim.Against:
tslibalias and thecreateRequirebanner).Option B: esbuild-for-ext + Vite-for-webviews
For:
--platform=node --format=esm --external:vscodejust works on the kinds of deps that made cosmosdb write the tslib alias.build.mjsof <50 lines replaces all ofvite.config.ext.mjsplus its workarounds.Against:
package.jsontransforms. cosmosdb does all of that invite-plugin-static-copyblocks; split builds duplicate it.Option C: All-esbuild
For:
Against:
Recommendation
Start with Option A (all-Vite, mirror cosmosdb). The marginal cost is low because we can copy their configs, adapt the aliases, reuse their plugins, and reuse their
docs/webview-build.md. The long-term consistency benefit across the two sibling repos is real.If Vite library mode for Node keeps biting us (more Rolldown interop bugs surface, build times become noticeable, the plugin maintenance burden grows), dropping to Option B is a one-day refactor — the webview side and the Vitest setup don't have to change. So the decision is cheap to revisit.
Option C is not recommended for this codebase given the webview complexity (Monaco, React, SCSS).
docs(bson): flag the static import as load-bearing at each call site
tnaum-ms commentedon Sep 21, 2026
Risk worth adding to the register: the dual-package hazard
We just spent three months shipping a silent data bug caused by exactly the mechanism this migration will touch repo-wide. Details in #933; summarising here because the "Known costs / risks" list above does not currently name it.
What happened.
bson@7declares split export conditions:Three call sites used
await import('bson'). Webpack resolved those through theimportcondition and bundled the ESM build, whilemongodband every staticimport … from 'bson'(which swc emits asrequire) resolved the CJS build. Two copies, two sets of classes, so everyinstanceof ObjectIdcheck against driver values returnedfalse.The schema analyzer then classified
ObjectId,Double,Int32,Long,Decimal128,Binary,Code,DBRefandTimestampas plain objects and enumerated their internals — autocompletion offered_id.bufferandrating.valueinstead of_idandrating.MinKey/MaxKeyvanished from the output entirely.Why it matters here. Three properties made this expensive, and all three are amplified by an ESM migration:
EJSON.stringifyduck-types on_bsontype, so serialisation and rendering kept working perfectly — only type inference broke. It took a user report to notice.import()torequire(). The bug appeared whenignoreDynamic: truewas added to the swc loader so webpack could split lazy dependencies. Nobody touched the affected code.instanceofacross package copies is invisible to the type system. TypeScript cannot see it, lint cannot see it, and the unit tests passed because they construct values from the same copy the assertion uses. It only reproduces in a bundled build.Concrete suggestions for this migration:
import/requireexport conditions" to the risks list. Every dependency whose classes we compare withinstanceofis exposed —bsonis the one that bit us, but it is not the only candidate.import, the CJS copy becomes the anomaly rather than the ESM one. The failure mode inverts but does not go away, and any dependency still resolved throughrequire(transitively, via a non-migrated package) reintroduces it.dist/:grep -c vendors-node_modules_bson_lib_bson_node_mjs dist/main.js # must be 0instanceofat package boundaries where a discriminator exists. We added a_bsontypefallback toBSONTypes.inferType()so the analyzer degrades correctly rather than silently, independent of how the bundler resolves things.The three import sites now carry an inline comment pointing back at this issue, so whoever does the migration meets the constraint at the place where it would be reintroduced.
docs(playground): record why the lazy `mongodb` import is still safe