Skip to content

Make SDK ESM-only; convert VS extension to ESM#425

Merged
clavery merged 1 commit into
mainfrom
sdk-esm-only
May 14, 2026
Merged

Make SDK ESM-only; convert VS extension to ESM#425
clavery merged 1 commit into
mainfrom
sdk-esm-only

Conversation

@clavery
Copy link
Copy Markdown
Collaborator

@clavery clavery commented May 13, 2026

Summary

  • Drop the SDK's dual-format build. dist/cjs was emitting ESM syntax (because tsc with module: Node16 honors the SDK's "type": "module"), so the published require condition resolved to a file Node's CJS loader rejected. Production paths (CLI, MCP, VSIX bundle) all consume the ESM build, which is why this went unnoticed until @W-22453800 site library support in libraries config #422 added an SDK import to webdav-mappings.ts and vscode-test (the only CJS consumer) tripped on it.
  • Simplify the SDK exports map to ESM-only ({development, types, default} per subpath).
  • Convert the VS extension package to "type": "module". Esbuild now writes dist/extension.cjs (still CJS-formatted; VS Code requires a CJS entry), and main points there. Two test files swap __dirname for fileURLToPath(import.meta.url).
  • Re-enable the VS extension test step in ci-vs-extension.yml (it was disabled in bf7e64d while this fix was prepared).

Consumer impact

The SDK is no longer importable from CJS via require(...) unless the consumer is on Node ≥22.12 (where require(esm) is stable for static-export modules). All in-tree consumers are ESM and unaffected.

Test plan

  • pnpm -r run build clean.
  • pnpm run test:agent — SDK 1723 / CLI 1229 passing.
  • pnpm --filter b2c-vs-extension test — 66 passing (including out/test/webdav-mappings.test.js, the file that broke main).
  • pnpm run typecheck:agent, pnpm run lint:agent, pnpm run -r format:check clean.
  • CI VS Extension Tests workflow green on this branch.

The SDK previously dual-published both ESM and CJS via tsconfig.cjs.json.
With module: Node16, tsc respected the SDK's "type": "module" and emitted
ESM syntax into dist/cjs/, which Node's CJS loader then rejected at
runtime. Production paths (CLI, MCP, VSIX bundle) all consumed the ESM
build, so the broken CJS output went unnoticed until vscode-test loaded
out/test/*.js as CJS and required the SDK transitively (#422 added the
first such SDK import to webdav-mappings.ts).

Drop the CJS build entirely and simplify the SDK exports map to ESM-only.
Convert the VS extension package to "type": "module" so its tsc test
compile emits ESM; rename the esbuild output to dist/extension.cjs (still
CJS-formatted, since VS Code requires a CJS extension entry) and point
main at the new filename. Replace two __dirname usages in tests with
fileURLToPath(import.meta.url). Re-enable the VS extension test step.
@clavery clavery requested a review from wei-liu-sf as a code owner May 13, 2026 14:30
@clavery clavery merged commit 5e43132 into main May 14, 2026
6 checks passed
@clavery clavery deleted the sdk-esm-only branch May 14, 2026 03:37
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