You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dual ESM/CJS build for CommonJS compatibility (#528)
Produce both ESM and CJS outputs from the esbuild config so that
consumers using either module system get a working package automatically.
- Add a second esbuild.build() call with format:"cjs" outputting to dist/cjs/
- Write a dist/cjs/package.json with type:"commonjs" so Node treats .js as CJS
- Update package.json exports with "import" and "require" conditions for both
the main and ./extension entry points
- Revert getBundledCliPath() to use import.meta.resolve for ESM, with a
createRequire + path-walking fallback for CJS contexts
- Update CJS compatibility tests to verify the actual dual build
- Update README to document CJS/CommonJS support
Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: nodejs/README.md
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -850,13 +850,18 @@ try {
850
850
- Node.js >= 18.0.0
851
851
- GitHub Copilot CLI installed and in PATH (or provide custom `cliPath`)
852
852
853
-
### CJS Bundles (esbuild, VS Code extensions)
853
+
### CJS / CommonJS Support
854
854
855
-
The SDK is ESM-only. When loaded in a CJS-shimmed environment (e.g., a VS Code extension bundled with `esbuild format:"cjs"`), `getBundledCliPath()` resolves the CLI by walking `node_modules`. The `@github/copilot` package **must be present in `node_modules` at runtime** — do not externalize or exclude it from your bundle.
855
+
The SDK ships both ESM and CJS builds. Node.js and bundlers (esbuild, webpack, etc.) automatically select the correct format via the `exports` field in `package.json`:
856
+
857
+
-`import` / `from` → ESM (`dist/index.js`)
858
+
-`require()` → CJS (`dist/cjs/index.cjs`)
859
+
860
+
This means the SDK works out of the box in CJS environments such as VS Code extensions bundled with `esbuild format:"cjs"`.
856
861
857
862
### System-installed CLI (winget, brew, apt)
858
863
859
-
If you installed the Copilot CLI separately rather than relying on the SDK's bundled copy, `getBundledCliPath()` will not find it (it only searches `node_modules`). Pass `cliPath` explicitly instead:
864
+
If you installed the Copilot CLI separately rather than relying on the SDK's bundled copy, pass `cliPath` explicitly:
0 commit comments