Skip to content

Generate published API entry point from src/api.ts#1619

Open
edvilme wants to merge 6 commits into
mainfrom
api-automatization
Open

Generate published API entry point from src/api.ts#1619
edvilme wants to merge 6 commits into
mainfrom
api-automatization

Conversation

@edvilme

@edvilme edvilme commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

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 already drifted (dozens of differing lines).

This PR makes src/api.ts the 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: the PythonEnvironments.api() helper and EXTENSION_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 copy src/api.ts (per examples/README.md) now also get the helper.
  • api/src/main.ts — removed. It is now generated at publish time and ignored via api/.gitignore.
  • build/azure-pipeline.npm.yml — added a step that copies src/api.ts to api/src/main.ts before compiling the package.
  • api/package.json / api/package-lock.json — bumped to 1.37.0 to 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.ts is validated on every PR by the extension's own lint + tsc.

CI guardrails

  • Version match — a version-match job runs scripts/compare_package_versions.py and fails if package.json and api/package.json versions differ.
  • API change requires a version bump — if a PR edits src/api.ts, api/package.json must also change. Bypass with the skip api version label.
  • API change requires a changelog entry — if a PR edits src/api.ts, api/CHANGELOG.md must also change. Bypass with the skip api changelog label.

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 lint and tsc -p . --noEmit pass with the helper folded into src/api.ts.
  • The cp step produces a byte-identical api/src/main.ts.
  • scripts/compare_package_versions.py verified for both matching (exit 0) and mismatching (exit 1) versions.
  • Built old vs. new npm tarballs and ran an isolated consumer against each (CJS + ESM type-check and runtime smoke): behavior is identical.

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>
@edvilme edvilme added skip tests debt Code quality issues labels Jul 1, 2026
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>
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'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
rchiodo previously approved these changes Jul 1, 2026

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 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() and EXTENSION_ID) into src/api.ts and removed the committed api/src/main.ts copy.
  • Updated the npm publish pipeline to copy src/api.tsapi/src/main.ts before compiling/packing the API package.
  • Added CI enforcement for API version bumping + version parity between package.json and api/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

Comment thread src/api.ts
Comment thread scripts/compare_package_versions.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
edvilme and others added 2 commits July 1, 2026 16:18
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>

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 9 out of 10 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • api/package-lock.json: Generated file

Comment thread src/api.ts Outdated
@edvilme edvilme enabled auto-merge (squash) July 2, 2026 17:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@edvilme edvilme requested a review from eleanorjboyd July 2, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

debt Code quality issues skip tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants