NPM-PACKAGE: Move @microsoft/kiota to ESM-only (lift of #7441) - #7963
Conversation
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>
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall coverage in commit adf9440 in the Show a code coverage summary of the most covered files.
Updated |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- 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
…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
There was a problem hiding this comment.
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.jsspecifiers andvscode-jsonrpc/node.js). - Update tests and CI/automation paths to the new
lib/runtime.jsonlocation 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. |
…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
There was a problem hiding this comment.
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 publisheddist/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 viaassert { type: 'json' }but not thewithform. Switching to the more widely supported import assertion keeps the emitted output compatible without changing behavior.
There was a problem hiding this comment.
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.jsonis 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.
Vincent Biret (baywet)
left a comment
There was a problem hiding this comment.
Thank you for making the changes!
Summary
Lifts #7441 (by Raul Hidalgo Caballero (@deinok)) onto current
mainand fixes the issues that kept it from building, so CI automations can run against a clean state.The npm package
@microsoft/kiotamoves to ESM-only:tsconfig.cjs.json/tsconfig.esm.json, singletsconfig.jsonwithmodule/moduleResolution: nodenext.config,connect,install,types,utils,runtime.json) intolib/. Becauseruntime.jsonis now underrootDir,tscemits it todist/, so thescripts/copy-files.jscopy step is no longer needed and was removed.package.json: single.export,"type": "module",main/typespoint atdist/index.js/dist/index.d.ts,filestrimmed todist.ci-build.yml,build-vscode-extension.yml):runtimeFilePathnow points atvscode/packages/npm-package/lib/runtime.json.Fixes on top of the original PR
vscode-jsonrpc/nodedid not resolve undernodenext(TS2307) because that CJS dependency has noexportsmap, so extensionless ESM subpath resolution fails. Added the explicit.js(vscode-jsonrpc/node.js) to all 12 importers. This also unblocked cascadingimplicit anyerrors inremoveItem.ts. The specifier is valid under Node ESM, webpack, and jest.tests/unit/install.spec.tsstill imported../../install; updated to../../lib/install(the original PR missed this file).mainpackage.json version and dependencies (the original PR carried a stale1.30.0bump — version is managed by CI).vscode/package-lock.jsonvianpm install; it was already consistent, so there is no lockfile diff.Validation
npm run build(both packages) — ✅ npm-packagetscbuild + extension webpack bundle succeed;dist/runtime.jsonis emitted.npm run test:unit --w=@microsoft/kiota— ✅ 11 suites / 18 tests pass.npm run lint— ✅ 0 errors (only pre-existing enum-naming warnings intypes.ts).