Generate published API entry point from src/api.ts#1619
Open
edvilme wants to merge 6 commits into
Open
Conversation
The npm package `@vscode/python-environments` previously duplicated the entire API definition in `api/src/main.ts`, a near-copy of `src/api.ts` that was hand-maintained and had drifted. Make `src/api.ts` the single source of truth by folding the publish-only runtime helper (`PythonEnvironments.api()` and `EXTENSION_ID`) into it, and stop committing `api/src/main.ts`. The publish pipeline now copies `src/api.ts` to `api/src/main.ts` before compiling the package. - src/api.ts: add the `PythonEnvironments.api()` helper and `EXTENSION_ID` - api/src/main.ts: remove (now generated); ignore via api/.gitignore - build/azure-pipeline.npm.yml: copy src/api.ts before compile - CONTRIBUTING.md: document the copy model Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add scripts/compare_package_versions.py and a CI job to verify the extension (package.json) and published API package (api/package.json) share the same version. Bump api package to 1.37.0 to match. Add a check-for-changed-files gate requiring an api/package.json version bump when src/api.ts changes (bypass with the 'skip api version' label). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edvilme
commented
Jul 1, 2026
| failure-message: 'The public API (${prereq-pattern}) was changed without bumping the package version in ${file-pattern} (the ${skip-label} label can be used to pass this check)' | ||
|
|
||
| version-match: | ||
| name: 'Extension and API package versions match' |
Contributor
Author
There was a problem hiding this comment.
Optional: I think this would be helpful, but could understand if we would rather have separate versions of the API and the extension to better identify breaking changes.
rchiodo
previously approved these changes
Jul 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes src/api.ts the single source of truth for the published @vscode/python-environments API by generating api/src/main.ts at publish time instead of committing a drift-prone duplicate, and adds CI checks to keep the published package version aligned with the extension version.
Changes:
- Folded the publish-only runtime helper (
PythonEnvironments.api()andEXTENSION_ID) intosrc/api.tsand removed the committedapi/src/main.tscopy. - Updated the npm publish pipeline to copy
src/api.ts→api/src/main.tsbefore compiling/packing the API package. - Added CI enforcement for API version bumping + version parity between
package.jsonandapi/package.json.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/api.ts |
Adds the runtime helper + extension ID to the canonical API surface. |
api/src/main.ts |
Removes the committed duplicate API entry point (now generated). |
api/.gitignore |
Ignores generated api/src/main.ts to prevent reintroducing duplication. |
build/azure-pipeline.npm.yml |
Copies src/api.ts into the API package during the publish build. |
api/package.json |
Bumps API package version to stay in lock-step with the extension. |
api/package-lock.json |
Updates lockfile version metadata to match the API package bump. |
scripts/compare_package_versions.py |
Adds a CI script to enforce extension/package version parity. |
CONTRIBUTING.md |
Documents the new “copy at publish time” model and versioning expectations. |
.github/workflows/pr-file-check.yml |
Enforces API version bump on src/api.ts edits and checks version parity. |
Files not reviewed (1)
- api/package-lock.json: Generated file
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Re-indent the api() function back inside the namespace and restore the namespace's closing brace that was dropped during a manual edit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add api/CHANGELOG.md for the published @vscode/python-environments package and a check-for-changed-files gate requiring a changelog entry whenever src/api.ts changes (bypass with the 'skip api changelog' label). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The npm package
@vscode/python-environmentspreviously duplicated the entire API definition inapi/src/main.ts— a near-copy ofsrc/api.tsthat was hand-maintained and had already drifted (dozens of differing lines).This PR makes
src/api.tsthe single source of truth, stops committing the duplicate, and adds CI guardrails so public API changes are versioned and documented.What changed
src/api.ts— folded in the publish-only runtime helper so it is now the complete public surface: thePythonEnvironments.api()helper andEXTENSION_ID. The extension itself never calls this helper (it implements the API), so it is harmless dead code in the extension bundle; a bonus is that consumers who copysrc/api.ts(perexamples/README.md) now also get the helper.api/src/main.ts— removed. It is now generated at publish time and ignored viaapi/.gitignore.build/azure-pipeline.npm.yml— added a step that copiessrc/api.tstoapi/src/main.tsbefore compiling the package.api/package.json/api/package-lock.json— bumped to1.37.0to match the extension version.api/CHANGELOG.md— new changelog for the published package (Keep a Changelog format).scripts/compare_package_versions.py— new script that verifies the extension (package.json) and API package (api/package.json) declare the same version..github/workflows/pr-file-check.yml— added CI guardrails (see below).CONTRIBUTING.md— documents the copy model and the versioning/changelog rules.How it works now
The publish pipeline runs:
npm install->cp ../src/api.ts src/main.ts->npm run compile->npm pack --ignore-scripts.src/api.tsis validated on every PR by the extension's own lint +tsc.CI guardrails
version-matchjob runsscripts/compare_package_versions.pyand fails ifpackage.jsonandapi/package.jsonversions differ.src/api.ts,api/package.jsonmust also change. Bypass with theskip api versionlabel.src/api.ts,api/CHANGELOG.mdmust also change. Bypass with theskip api changeloglabel.Trade-off
The api package now builds only in the Linux publish pipeline. To build it locally, copy the file first (
cp src/api.ts api/src/main.ts) — documented in CONTRIBUTING.md.Validation
npm run lintandtsc -p . --noEmitpass with the helper folded intosrc/api.ts.cpstep produces a byte-identicalapi/src/main.ts.scripts/compare_package_versions.pyverified for both matching (exit 0) and mismatching (exit 1) versions.