-
Notifications
You must be signed in to change notification settings - Fork 61
feat: add getPackageAvailableVersions to public API and bump API to 1.1.0 #1682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
540d41d
chore: bump API package version to 1.1.0
edvilme 7c33fa6
Merge branch 'main' into api-version-bump
edvilme e07536a
feat: expose getPackageAvailableVersions on public API
edvilme b62da99
Revert return-type
edvilme bc432d0
Add packed-package validation
edvilme ea372a6
Update changelog to only include released versions
edvilme 104bb66
Address PR comments
edvilme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ dist | |
| node_modules | ||
| .vscode-test/ | ||
| *.vsix | ||
| *.tgz | ||
| *.tsbuildinfo | ||
| .nox/ | ||
| .venv/ | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| node_modules/ | ||
| src/ | ||
| scripts/ | ||
| test/ | ||
| out/**/*.map | ||
| *.tgz | ||
| *.tsbuildinfo | ||
| tsconfig*.json |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| const assert = require('node:assert'); | ||
| const fs = require('node:fs'); | ||
| const os = require('node:os'); | ||
| const path = require('node:path'); | ||
| const { execFileSync } = require('node:child_process'); | ||
| const { createRequire } = require('node:module'); | ||
| const { fileURLToPath } = require('node:url'); | ||
|
|
||
| const packageRoot = path.resolve(__dirname, '..'); | ||
| const npmCli = process.env.npm_execpath; | ||
|
|
||
| if (!npmCli) { | ||
| throw new Error('npm_execpath is unavailable. Run this validation through npm run test:package.'); | ||
| } | ||
|
|
||
| function runNodeScript(script, args, cwd, captureOutput = false) { | ||
| return execFileSync(process.execPath, [script, ...args], { | ||
| cwd, | ||
| encoding: 'utf8', | ||
| stdio: captureOutput ? ['ignore', 'pipe', 'inherit'] : 'inherit', | ||
| }); | ||
| } | ||
|
|
||
| const packOutput = runNodeScript(npmCli, ['pack', '--ignore-scripts', '--json'], packageRoot, true); | ||
| const packResult = JSON.parse(packOutput); | ||
| assert.strictEqual(packResult.length, 1, 'Expected npm pack to produce exactly one package'); | ||
|
|
||
| const tarballPath = path.join(packageRoot, packResult[0].filename); | ||
| const testRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'python-environments-api-')); | ||
|
|
||
| function canonicalPath(value) { | ||
| return fs.realpathSync.native(path.resolve(value)); | ||
| } | ||
|
|
||
| try { | ||
| fs.writeFileSync( | ||
| path.join(testRoot, 'package.json'), | ||
| JSON.stringify({ name: 'python-environments-api-consumer', private: true }), | ||
| ); | ||
|
|
||
| runNodeScript( | ||
| npmCli, | ||
| [ | ||
| 'install', | ||
| '--ignore-scripts', | ||
| '--no-package-lock', | ||
| '--no-save', | ||
| tarballPath, | ||
| '@types/node@^22.0.0', | ||
| '@types/vscode@^1.99.0', | ||
| ], | ||
| testRoot, | ||
| ); | ||
|
|
||
| const typescriptCli = path.join(packageRoot, 'node_modules', 'typescript', 'bin', 'tsc'); | ||
| const fixtureRoot = path.join(packageRoot, 'test'); | ||
|
|
||
| for (const consumer of [ | ||
| { name: 'modern', type: 'module' }, | ||
| { name: 'legacy', type: 'commonjs' }, | ||
| ]) { | ||
| const consumerRoot = path.join(testRoot, consumer.name); | ||
| fs.mkdirSync(consumerRoot); | ||
| fs.copyFileSync(path.join(fixtureRoot, 'consumer.ts'), path.join(consumerRoot, 'consumer.ts')); | ||
| fs.copyFileSync( | ||
| path.join(fixtureRoot, `tsconfig.${consumer.name}.json`), | ||
| path.join(consumerRoot, 'tsconfig.json'), | ||
| ); | ||
| fs.writeFileSync( | ||
| path.join(consumerRoot, 'package.json'), | ||
| JSON.stringify({ private: true, type: consumer.type }), | ||
| ); | ||
|
|
||
| runNodeScript(typescriptCli, ['--project', path.join(consumerRoot, 'tsconfig.json')], packageRoot); | ||
| } | ||
|
|
||
| const installedPackageRoot = path.join(testRoot, 'node_modules', '@vscode', 'python-environments'); | ||
| const installedPackageJson = JSON.parse(fs.readFileSync(path.join(installedPackageRoot, 'package.json'), 'utf8')); | ||
| assert.strictEqual(installedPackageJson.main, './out/cjs/main.cjs'); | ||
| assert.strictEqual(installedPackageJson.types, './out/cjs/main.d.ts'); | ||
| assert.deepStrictEqual(installedPackageJson.exports, { | ||
| import: { | ||
| types: './out/esm/main.d.ts', | ||
| default: './out/esm/main.mjs', | ||
| }, | ||
| require: { | ||
| types: './out/cjs/main.d.ts', | ||
| default: './out/cjs/main.cjs', | ||
| }, | ||
| }); | ||
|
|
||
| for (const target of [ | ||
| installedPackageJson.main, | ||
| installedPackageJson.types, | ||
| installedPackageJson.exports.import.types, | ||
| installedPackageJson.exports.import.default, | ||
| installedPackageJson.exports.require.types, | ||
| installedPackageJson.exports.require.default, | ||
| ]) { | ||
| assert.ok(fs.statSync(path.resolve(installedPackageRoot, target)).isFile(), `${target} must be a file`); | ||
| } | ||
|
|
||
| const requireFromConsumer = createRequire(path.join(testRoot, 'legacy', 'consumer.cjs')); | ||
| assert.strictEqual( | ||
| canonicalPath(requireFromConsumer.resolve('@vscode/python-environments')), | ||
| canonicalPath(path.join(installedPackageRoot, installedPackageJson.exports.require.default)), | ||
| 'CommonJS consumers should resolve the packaged CommonJS entry point', | ||
| ); | ||
|
|
||
| const esmEntryPoint = execFileSync( | ||
| process.execPath, | ||
| ['--input-type=module', '--eval', "console.log(import.meta.resolve('@vscode/python-environments'))"], | ||
| { | ||
| cwd: path.join(testRoot, 'modern'), | ||
| encoding: 'utf8', | ||
| }, | ||
| ).trim(); | ||
| assert.strictEqual( | ||
| canonicalPath(fileURLToPath(esmEntryPoint)), | ||
| canonicalPath(path.join(installedPackageRoot, installedPackageJson.exports.import.default)), | ||
| 'ES module consumers should resolve the packaged ES module entry point', | ||
| ); | ||
| } finally { | ||
| fs.rmSync(testRoot, { recursive: true, force: true }); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import type { | ||
| PackageManager, | ||
| Pep440Version, | ||
| PythonEnvironment, | ||
| PythonPackageGetterApi, | ||
| } from '@vscode/python-environments'; | ||
|
|
||
| type Equal<Left, Right> = | ||
| (<Value>() => Value extends Left ? 1 : 2) extends <Value>() => Value extends Right ? 1 : 2 ? true : false; | ||
|
|
||
| type AvailableVersionsReturn = ReturnType<PythonPackageGetterApi['getPackageAvailableVersions']>; | ||
| type RefreshReturn = ReturnType<PackageManager['refresh']>; | ||
|
|
||
| const availableVersionsReturnIsExact: Equal<AvailableVersionsReturn, Promise<Pep440Version[] | undefined>> = true; | ||
| const refreshReturnIsExact: Equal<RefreshReturn, Promise<void>> = true; | ||
|
|
||
| declare const api: PythonPackageGetterApi; | ||
| declare const environment: PythonEnvironment; | ||
| const availableVersions: Promise<Pep440Version[] | undefined> = api.getPackageAvailableVersions(environment, 'example'); | ||
|
|
||
| void availableVersionsReturnIsExact; | ||
| void refreshReturnIsExact; | ||
| void availableVersions; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2020", | ||
| "module": "CommonJS", | ||
| "moduleResolution": "Node", | ||
| "noEmit": true, | ||
| "strict": true, | ||
| "skipLibCheck": false | ||
| }, | ||
| "include": ["consumer.ts"] | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2020", | ||
| "module": "NodeNext", | ||
| "moduleResolution": "NodeNext", | ||
| "noEmit": true, | ||
| "strict": true, | ||
| "skipLibCheck": false | ||
| }, | ||
| "include": ["consumer.ts"] | ||
| } |
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.