Commit b192cdf
Generate published API entry point from src/api.ts (#1619)
## 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.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>1 parent 2bfc9ef commit b192cdf
10 files changed
Lines changed: 170 additions & 1438 deletions
File tree
- .github/workflows
- api
- src
- build
- scripts
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
92 | 101 | | |
93 | 102 | | |
94 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
0 commit comments