You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 556b258
Browse filesBrowse the repository at this point in the historyBrowse files
refactor: separate API facade from public contracts (#1787)
This pull request clarifies the distinction between the Python
Environments runtime API and the public TypeScript contracts used by the
extension and npm package. The API is the runtime mechanism that
extensions and automation use to execute operations, while the types
define the public contracts and shared data shapes used throughout the
codebase and exposed through `@vscode/python-environments`.
## New file structure
- `src/types.ts`
- Canonical public contracts and interfaces, including
`PythonEnvironmentApi`, environment and package shapes, manager
contracts, and event/option types.
- This file is intentionally contract-focused and does not contain
extension lookup helpers or concrete implementations.
- `src/api.ts`
- Public runtime facade for consumers.
- Re-exports the public contracts and public errors, keeps
`EXTENSION_ID`, and provides `PythonEnvironments.api()` for resolving
the VS Code extension API at runtime.
- `src/publicErrors.ts`
- Public runtime error definitions and guards that package consumers may
need to handle explicitly.
- `src/extensionApi.ts`
- The extension-side implementation of `PythonEnvironmentApi` that is
returned from activation.
- This keeps the runtime implementation separate from the public facade
and type declarations.
- `src/managers/common/models.ts`
- Concrete `PythonEnvironmentImpl` and `PythonPackageImpl` model
implementations.
- `src/managers/common/registeredManagers.ts`
- Internal manager wrappers, preserving existing names such as
`InternalEnvironmentManager` and `InternalPackageManager` to minimize PR
impact.
- Owning feature modules now define their own internal contracts instead
of using the old `src/internal.api.ts` grab bag:
- `src/features/envManagers.ts` owns environment-manager registry
contracts and events.
- `src/features/projectManager.ts` owns project-manager contracts and
implementation.
- `src/features/creators/projectCreators.ts` owns project-creator
contracts and implementation.
## Package and consumer behavior
- The npm package continues to expose the existing public surface; this
PR does not intentionally remove or rename package exports.
- The extension does not consume `@vscode/python-environments`
internally. Shared contracts come from local source files.
- The package build copies the source-of-truth files from `src/` into
the package staging area before compiling.
- CommonJS and ES module package entry points are covered by package
smoke tests.
## Other cleanup
- Removed the obsolete `examples/` sample extension. External extension
authors should use the npm package/public contracts instead of copying a
local sample that duplicated API files.
- Updated documentation, packaging scripts, and release-gate checks to
account for the split public API files.
- Added webpack resolution support for `.js` import specifiers used by
the package-compatible TypeScript sources.
## Compatibility
No breaking changes are intended. Public names are preserved, internal
wrapper names are preserved where possible, and the npm package remains
the consumer-facing entry point for external extensions.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot-Session: de4cb63f-4a85-432d-a722-697b33e9d49a
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)'
52
55
53
56
- name: 'Public API changes require a changelog entry'
failure-message: 'The public API (${prereq-pattern}) was changed without a changelog entry in ${file-pattern} (the ${skip-label} label can be used to pass this check)'
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,12 +91,12 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
91
91
92
92
## Public API package (`@vscode/python-environments`)
93
93
94
-
The npm package under [`api/`](./api) is the public API facade other extensions consume. Its entry point,`api/src/main.ts`, is a **copy** of [`src/api.ts`](./src/api.ts)— the single source of truth — and is**not committed** (see [`api/.gitignore`](./api/.gitignore)).
94
+
The npm package under [`api/`](./api) is the public API facade other extensions consume. Its sources —`api/src/main.ts`, `api/src/types.ts`, and `api/src/publicErrors.ts` — are **copies** of [`src/api.ts`](./src/api.ts), [`src/types.ts`](./src/types.ts), and [`src/publicErrors.ts`](./src/publicErrors.ts) respectively — the single sources of truth — and are**not committed** (see [`api/.gitignore`](./api/.gitignore)).
95
95
96
-
- Edit the API only in `src/api.ts`. This file contains the full public surface, including the runtime `PythonEnvironments.api()` helper and `EXTENSION_ID`. `api/src/main.ts`is a build artifact — never edit or commit it.
97
-
-`api/src/main.ts` is produced by the publish pipeline ([`build/azure-pipeline.npm.yml`](./build/azure-pipeline.npm.yml)), which copies `src/api.ts` to `api/src/main.ts`before compiling. The api package is therefore built in CI only; to build it locally, copy the file first (e.g. `cp src/api.ts api/src/main.ts`).
98
-
-`src/api.ts` itself is validated on every PR by the extension's own lint and TypeScript compile.
99
-
-**Versioning:** the published package version in [`api/package.json`](./api/package.json)must always match the extension version in [`package.json`](./package.json). CI enforces this via [`scripts/compare_package_versions.py`](./scripts/compare_package_versions.py). Additionally, any PR that edits `src/api.ts`must bump `api/package.json` (use the `skip api version` label to bypass) and add an entry to [`api/CHANGELOG.md`](./api/CHANGELOG.md) (use the `skip api changelog` label to bypass). When bumping, update both `package.json` files so they stay in sync.
96
+
- Edit the public API only in `src/api.ts` (the runtime facade: `PythonEnvironments.api()` helper and `EXTENSION_ID`), `src/types.ts` (public contracts: interfaces, types, enums), and `src/publicErrors.ts` (concrete public error classes and type guards). `api/src/*.ts`files are build artifacts — never edit or commit them.
97
+
-`api/src/main.ts`, `api/src/types.ts`, and `api/src/publicErrors.ts` are produced by the publish pipeline ([`build/azure-pipeline.npm.yml`](./build/azure-pipeline.npm.yml)), which copies `src/api.ts` to `api/src/main.ts`, `src/types.ts` to `api/src/types.ts`, and `src/publicErrors.ts` to `api/src/publicErrors.ts`before compiling. The api package is therefore built in CI only; to build it locally, copy the files first (e.g. `cp src/api.ts api/src/main.ts && cp src/types.ts api/src/types.ts && cp src/publicErrors.ts api/src/publicErrors.ts`).
98
+
-`src/api.ts`, `src/types.ts`, and `src/publicErrors.ts` are validated on every PR by the extension's own lint and TypeScript compile.
99
+
-**Versioning and compatibility:** the published package version in [`api/package.json`](./api/package.json)is maintained independently of the extension version in [`package.json`](./package.json) — the two do not need to match. Compatibility is based on the API shape exported by the installed Python Environments extension at runtime. Package updates must preserve backwards-compatible contracts unless the API package version intentionally communicates a breaking change; consumers should treat newly added members as optional when they may run against older installed extension versions. Any PR that edits `src/api.ts`, `src/types.ts`, or `src/publicErrors.ts`must bump `api/package.json` (use the `skip api version` label to bypass) and add an entry to [`api/CHANGELOG.md`](./api/CHANGELOG.md) (use the `skip api changelog` label to bypass).
Copy file name to clipboardExpand all lines: README.md
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -155,9 +155,7 @@ The Python Environments extension was built to provide a cohesive and user frien
155
155
156
156
### API Reference (proposed)
157
157
158
-
See [api.ts](https://github.com/microsoft/vscode-python-environments/blob/main/src/api.ts) for the full list of Extension APIs.
159
-
160
-
To consume these APIs you can look at the example here: [API Consumption Examples](https://github.com/microsoft/vscode-python-environments/blob/main/examples/README.md)
158
+
See [api.ts](https://github.com/microsoft/vscode-python-environments/blob/main/src/api.ts) for the runtime API facade and [types.ts](https://github.com/microsoft/vscode-python-environments/blob/main/src/types.ts) for the public API contracts. Extension authors can consume these contracts from the `@vscode/python-environments` npm package.
0 commit comments