Skip to content

Commit cb7f9df

Browse files
Copilotedvilme
andauthored
fix: address API packaging review feedback; decouple API/extension versions
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
1 parent ddf364f commit cb7f9df

7 files changed

Lines changed: 45 additions & 78 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ The npm package under [`api/`](./api) is the public API facade other extensions
9696
- 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.
9797
- `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`).
9898
- `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:** 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`, `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). When bumping, update both `package.json` files so they stay in sync.
99+
- **Versioning:** 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. 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).
100100

101101
## Questions or Issues?
102102

‎api/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"scripts": {
4040
"prepublishOnly": "echo \"⛔ Can only publish from a secure pipeline ⛔\" && node -e \"process.exitCode = 1\"",
4141
"prepack": "npm run all:publish",
42-
"all:publish": "git clean -xfd . && npm install && npm run compile",
42+
"all:publish": "git clean -xfd . && npm install && npm run copy:sources && npm run compile",
43+
"copy:sources": "node ./scripts/copy-sources.cjs",
4344
"compile": "npm run compile:esm && npm run compile:cjs",
4445
"compile:esm": "tsc -b ./tsconfig.esm.json && mve out/esm/main.js out/esm/main.mjs && node -e \"require('fs').writeFileSync('out/esm/package.json', '{\\\"type\\\":\\\"module\\\"}')\"",
4546
"compile:cjs": "tsc -b ./tsconfig.cjs.json && mve out/cjs/main.js out/cjs/main.cjs",

‎api/scripts/copy-sources.cjs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// Repopulates the package's generated `src` sources from the single sources of
5+
// truth in `../src`. These files are gitignored and are removed by the
6+
// `git clean -xfd .` step in `all:publish`, so they must be copied back before
7+
// TypeScript can compile. Mirrors the copy step in build/azure-pipeline.npm.yml.
8+
9+
const fs = require('node:fs');
10+
const path = require('node:path');
11+
12+
const packageRoot = path.resolve(__dirname, '..');
13+
const repoRoot = path.resolve(packageRoot, '..');
14+
const srcDir = path.join(packageRoot, 'src');
15+
16+
const sources = [
17+
{ from: path.join(repoRoot, 'src', 'api.ts'), to: path.join(srcDir, 'main.ts') },
18+
{ from: path.join(repoRoot, 'src', 'types.ts'), to: path.join(srcDir, 'types.ts') },
19+
{ from: path.join(repoRoot, 'src', 'publicErrors.ts'), to: path.join(srcDir, 'publicErrors.ts') },
20+
];
21+
22+
fs.mkdirSync(srcDir, { recursive: true });
23+
for (const { from, to } of sources) {
24+
fs.copyFileSync(from, to);
25+
}

‎build/azure-pipeline.npm.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extends:
7575
workingDirectory: $(Build.SourcesDirectory)/api
7676
displayName: Install package dependencies
7777

78-
- script: mkdir -p src && cp ../src/api.ts src/main.ts && cp ../src/types.ts src/types.ts && cp ../src/publicErrors.ts src/publicErrors.ts
78+
- script: npm run copy:sources
7979
workingDirectory: $(Build.SourcesDirectory)/api
8080
displayName: Copy src/api.ts, src/types.ts, src/publicErrors.ts to API package sources
8181

‎examples/sample1/package-lock.json‎

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/sample1/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"activationEvents": [],
1313
"main": "./dist/extension.js",
1414
"contributes": {},
15+
"dependencies": {
16+
"@renovatebot/pep440": "^4.2.4"
17+
},
1518
"scripts": {
1619
"vscode:prepublish": "npm run package",
1720
"compile": "webpack",

‎scripts/compare_package_versions.py‎

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)