Skip to content

NPM-PACKAGE: Move @microsoft/kiota to ESM-only (lift of #7441) - #7963

Merged
Gavin Barron (gavinbarron) merged 18 commits into
mainfrom
gavinbarron-npm-package-esm-only
Jul 22, 2026
Merged

NPM-PACKAGE: Move @microsoft/kiota to ESM-only (lift of #7441)#7963
Gavin Barron (gavinbarron) merged 18 commits into
mainfrom
gavinbarron-npm-package-esm-only

Conversation

@gavinbarron

Copy link
Copy Markdown
Contributor

Summary

Lifts #7441 (by Raul Hidalgo Caballero (@deinok)) onto current main and fixes the issues that kept it from building, so CI automations can run against a clean state.

The npm package @microsoft/kiota moves to ESM-only:

  • Ship ESM only — dropped the dual CJS/ESM build and tsconfig.cjs.json / tsconfig.esm.json, single tsconfig.json with module/moduleResolution: nodenext.
  • Relocated the remaining root modules (config, connect, install, types, utils, runtime.json) into lib/. Because runtime.json is now under rootDir, tsc emits it to dist/, so the scripts/copy-files.js copy step is no longer needed and was removed.
  • package.json: single . export, "type": "module", main/types point at dist/index.js / dist/index.d.ts, files trimmed to dist.
  • CI (ci-build.yml, build-vscode-extension.yml): runtimeFilePath now points at vscode/packages/npm-package/lib/runtime.json.

Fixes on top of the original PR

  • vscode-jsonrpc/node did not resolve under nodenext (TS2307) because that CJS dependency has no exports map, so extensionless ESM subpath resolution fails. Added the explicit .js (vscode-jsonrpc/node.js) to all 12 importers. This also unblocked cascading implicit any errors in removeItem.ts. The specifier is valid under Node ESM, webpack, and jest.
  • tests/unit/install.spec.ts still imported ../../install; updated to ../../lib/install (the original PR missed this file).
  • Preserved current main package.json version and dependencies (the original PR carried a stale 1.30.0 bump — version is managed by CI).
  • Regenerated vscode/package-lock.json via npm install; it was already consistent, so there is no lockfile diff.

Validation

  • npm run build (both packages) — ✅ npm-package tsc build + extension webpack bundle succeed; dist/runtime.json is emitted.
  • npm run test:unit --w=@microsoft/kiota — ✅ 11 suites / 18 tests pass.
  • npm run lint — ✅ 0 errors (only pre-existing enum-naming warnings in types.ts).
  • Integration tests were left for CI to exercise.

Note (from the original PR): if this package is consumed outside the webpack-bundled VS Code extension, ESM-only may be a breaking change for CommonJS consumers.

Lifts PR #7441 (deinok) onto current main, with fixes so the build,
unit tests, lint and extension webpack bundling all pass.

- Ship ESM only (drop dual CJS/ESM build, tsconfig.cjs/esm.json)
- Relocate remaining root modules into lib/ so the imported runtime.json
  is emitted to dist by tsc (removes the copy-files.js script)
- Use explicit .js import specifiers under module/moduleResolution nodenext
- Point CI runtimeFilePath at vscode/packages/npm-package/lib/runtime.json

Fixes over the original PR:
- Add .js extension to vscode-jsonrpc/node imports so they resolve under
  nodenext ESM (was TS2307; also unblocked cascading implicit-any errors)
- Update tests/unit/install.spec.ts import to ../../lib/install
- Preserve current main package.json version and dependencies

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@gavinbarron
Gavin Barron (gavinbarron) requested a review from a team as a code owner July 20, 2026 23:23
@msgraph-bot msgraph-bot Bot added this to Kiota Jul 20, 2026
@github-code-quality

github-code-quality Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall coverage in commit adf9440 in the gavinbarron-npm-pack... branch is 72%. Coverage data for the main branch is not yet available.

Show a code coverage summary of the most covered files.
File main gavinbarron-npm-pack... adf9440 +/-
/home/runner/wo...guageRefiner.cs 98%
/home/runner/wo...criptRefiner.cs 98%
/home/runner/wo...MethodWriter.cs 97%
/home/runner/wo...MethodWriter.cs 96%
/home/runner/wo...MethodWriter.cs 96%
/home/runner/wo...MethodWriter.cs 95%
/home/runner/wo...rs/GoRefiner.cs 94%
/home/runner/wo...KiotaBuilder.cs 90%
/home/runner/wo...ationService.cs 89%
/home/runner/wo...xGenerator.g.cs 75%

Updated July 22, 2026 10:57 UTC

Comment thread vscode/packages/npm-package/lib/generateClient.ts
Comment thread vscode/packages/npm-package/lib/install.ts Outdated
Comment thread vscode/packages/npm-package/lib/utils.ts Outdated
@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Jul 21, 2026
- Use node: prefix for Node builtin imports (crypto, https, fs, path, url,
  child_process) across install.ts, connect.ts, generatePlugin.ts.
- Split utils.ts import into an import type for type-only symbols
  (KiotaLogEntry, LogLevel) while keeping MaturityLevel and DependencyType as
  value imports since they are enums accessed at runtime.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0c0540e6-edc8-43c3-ba28-e40e0781f759
@gavinbarron
Gavin Barron (gavinbarron) enabled auto-merge (squash) July 21, 2026 18:12
…d into lib/

The runtime.json was relocated to vscode/packages/npm-package/lib/, so the sibling-directory lookup resolved to a nonexistent lib/package.json and silently skipped the @microsoft/kiota version bump. Fall back to the parent directory's package.json when the sibling is missing.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a68f8d52-664a-4ba6-a074-bd4d149ae498
Copilot AI review requested due to automatic review settings July 22, 2026 02:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the VS Code extension’s embedded npm package (vscode/packages/npm-package, published as @microsoft/kiota) to ESM-only, consolidating TypeScript configuration around nodenext, relocating source modules under lib/, and updating test/CI wiring so builds can run cleanly on current main.

Changes:

  • Switch npm-package build output to a single ESM dist/ (drop dual CJS/ESM tsconfigs and copy script).
  • Move and normalize internal imports for nodenext (explicit .js specifiers and vscode-jsonrpc/node.js).
  • Update tests and CI/automation paths to the new lib/runtime.json location and ESM build layout.

Reviewed changes

Copilot reviewed 43 out of 46 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vscode/packages/npm-package/tsconfig.json Consolidates TS build to nodenext with rootDir=lib and outDir=dist.
vscode/packages/npm-package/tsconfig.esm.json Removes separate ESM tsconfig (single build output).
vscode/packages/npm-package/tsconfig.cjs.json Removes separate CJS tsconfig (ESM-only).
vscode/packages/npm-package/package.json Switches package to "type":"module", single export, and simplified build scripts/files list.
vscode/packages/npm-package/scripts/copy-files.js Removes prior runtime.json copy step (now assumed unnecessary).
vscode/packages/npm-package/index.ts Removes old root re-export entrypoint in favor of lib/index.ts.
vscode/packages/npm-package/lib/index.ts Adds new ESM entrypoint re-exporting lib/* surface.
vscode/packages/npm-package/lib/config.ts Adds config module under lib/.
vscode/packages/npm-package/lib/connect.ts Updates Node built-in imports and ESM-compatible local imports.
vscode/packages/npm-package/lib/install.ts Updates to node:-prefixed built-ins and JSON module import for runtime metadata.
vscode/packages/npm-package/lib/runtime.json Moves runtime dependency metadata JSON under lib/.
vscode/packages/npm-package/lib/types.ts Adds consolidated types/enums in lib/.
vscode/packages/npm-package/lib/utils.ts Updates imports to explicit .js and uses type-only imports where applicable.
vscode/packages/npm-package/lib/updateClients.ts Updates RPC import to vscode-jsonrpc/node.js and local import paths.
vscode/packages/npm-package/lib/searchDescription.ts Updates RPC import and local import paths for nodenext.
vscode/packages/npm-package/lib/removeItem.ts Updates RPC import and local import paths for nodenext.
vscode/packages/npm-package/lib/migrateFromLockFile.ts Updates RPC import and local import paths for nodenext.
vscode/packages/npm-package/lib/languageInformation.ts Updates RPC import and local import paths for nodenext.
vscode/packages/npm-package/lib/getPluginManifest.ts Updates RPC import and local import paths for nodenext.
vscode/packages/npm-package/lib/getManifestDetails.ts Updates RPC import and local import paths for nodenext.
vscode/packages/npm-package/lib/getKiotaVersion.ts Updates RPC import and local import paths for nodenext.
vscode/packages/npm-package/lib/getKiotaTree.ts Updates RPC import and local import paths for nodenext.
vscode/packages/npm-package/lib/generatePlugin.ts Updates RPC import, local imports, and Node built-in imports.
vscode/packages/npm-package/lib/generateClient.ts Updates RPC import and local import paths for nodenext.
vscode/packages/npm-package/jest.common.config.cjs Switches globalSetup to a CJS wrapper to accommodate new module resolution.
vscode/packages/npm-package/jest.config.cjs Updates globalSetup path to the new CJS wrapper.
vscode/packages/npm-package/jest.config.integration.cjs Updates globalSetup path to the new CJS wrapper.
vscode/packages/npm-package/tests/integration/setup.ts Updates import path to ../../lib/install.
vscode/packages/npm-package/tests/integration/setup.cjs Adds globalSetup wrapper + module resolution shim for .js specifiers.
vscode/packages/npm-package/tests/integration/integrationInstall.spec.ts Updates imports to ../../lib/* modules.
vscode/packages/npm-package/tests/integration/integrationGetKiotaTree.spec.ts Updates types import to ../../lib/types.
vscode/packages/npm-package/tests/integration/integrationGeneratePlugin.spec.ts Updates types imports to ../../lib/types.
vscode/packages/npm-package/tests/assertUtils.ts Updates types import to ../lib/types.
vscode/packages/npm-package/tests/unit/install.spec.ts Updates import to ../../lib/install.
vscode/packages/npm-package/tests/unit/generateClient.spec.ts Updates types import to ../../lib/types.
vscode/packages/npm-package/tests/unit/generatePlugin.spec.ts Updates types imports to ../../lib/types.
vscode/packages/npm-package/tests/unit/getKiotaTree.spec.ts Updates types import to ../../lib/types.
vscode/packages/npm-package/tests/unit/getManifestDetails.spec.ts Updates types import to ../../lib/types.
vscode/packages/npm-package/tests/unit/migrateFromLockFile.spec.ts Updates types import to ../../lib/types.
vscode/packages/npm-package/tests/unit/removeItem.spec.ts Updates types import to ../../lib/types.
vscode/packages/npm-package/tests/unit/searchDescriptions.spec.ts Updates types import to ../../lib/types.
vscode/packages/npm-package/tests/unit/stubs.util.ts Updates connect import to ../../lib/connect.
vscode/packages/npm-package/tests/unit/updateClients.spec.ts Updates types import to ../../lib/types.
scripts/update-vscode-releases.ps1 Adjusts version update script to find package.json when runtime.json lives under lib/.
.github/workflows/build-vscode-extension.yml Updates runtimeFilePath to vscode/packages/npm-package/lib/runtime.json.
.azure-pipelines/ci-build.yml Updates runtimeFilePath to vscode/packages/npm-package/lib/runtime.json.

Comment thread vscode/packages/npm-package/package.json
Copilot AI review requested due to automatic review settings July 22, 2026 09:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 43 out of 46 changed files in this pull request and generated 2 comments.

Comment thread vscode/packages/npm-package/package.json
Comment thread vscode/packages/npm-package/tests/integration/setup.cjs
…odule

With `type: module` in package.json, Node treats scripts/generate-readme.js
as ESM, breaking its require/__dirname usage. Rename it to .cjs and update the
generate-readme script reference so it continues to run as CommonJS.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0c0540e6-edc8-43c3-ba28-e40e0781f759
Copilot AI review requested due to automatic review settings July 22, 2026 09:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 43 out of 47 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

vscode/packages/npm-package/lib/install.ts:9

  • import ... with { type: 'json' } relies on the newer import-attributes syntax being supported by the runtime that executes the published dist/install.js. Since this package doesn't declare a Node.js engine range, this can produce a hard syntax error for consumers running Node versions that support JSON modules via assert { type: 'json' } but not the with form. Switching to the more widely supported import assertion keeps the emitted output compatible without changing behavior.

Copilot AI review requested due to automatic review settings July 22, 2026 10:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 43 out of 47 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

vscode/packages/npm-package/lib/install.ts:9

  • runtime.json is imported using the new import-attributes syntax (with { type: 'json' }). This syntax is not supported in all Node ESM runtimes yet, so the published ESM output can fail to parse for consumers running older Node versions. Since this package doesn't declare a Node engine requirement, it’s safer to use the more widely-supported JSON import assertion syntax for now.

Copilot AI review requested due to automatic review settings July 22, 2026 10:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 43 out of 47 changed files in this pull request and generated 1 comment.

Comment thread vscode/packages/npm-package/jest.common.config.cjs

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes!

@gavinbarron
Gavin Barron (gavinbarron) merged commit 31e450b into main Jul 22, 2026
317 checks passed
@gavinbarron
Gavin Barron (gavinbarron) deleted the gavinbarron-npm-package-esm-only branch July 22, 2026 11:53
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants