@vscode/python-environments 1.0.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,96 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+ import { extensions } from 'vscode';
4
+ /**
5
+ * Enum representing the kinds of environment changes.
6
+ */
7
+ export var EnvironmentChangeKind;
8
+ (function (EnvironmentChangeKind) {
9
+ /**
10
+ * Indicates that an environment was added.
11
+ */
12
+ EnvironmentChangeKind["add"] = "add";
13
+ /**
14
+ * Indicates that an environment was removed.
15
+ */
16
+ EnvironmentChangeKind["remove"] = "remove";
17
+ })(EnvironmentChangeKind || (EnvironmentChangeKind = {}));
18
+ /**
19
+ * Enum representing the kinds of package changes.
20
+ */
21
+ export var PackageChangeKind;
22
+ (function (PackageChangeKind) {
23
+ /**
24
+ * Indicates that a package was added.
25
+ */
26
+ PackageChangeKind["add"] = "add";
27
+ /**
28
+ * Indicates that a package was removed.
29
+ */
30
+ PackageChangeKind["remove"] = "remove";
31
+ })(PackageChangeKind || (PackageChangeKind = {}));
32
+ /**
33
+ * Error thrown when a package manager cannot list available package versions.
34
+ *
35
+ * This distinguishes an *unsupported capability* from an *operational failure* (such as a
36
+ * failed command, a network error, or malformed/unparseable output). Consumers of
37
+ * {@link PythonPackageGetterApi.getPackageAvailableVersions} should treat this specific error
38
+ * as a signal to fall back to manual version entry, while letting any other error propagate.
39
+ *
40
+ * The {@link code} property carries a stable, string-literal discriminator so the error can be
41
+ * recognized reliably across extension bundle boundaries, where `instanceof` may fail because
42
+ * each bundle can load its own copy of this class. Prefer {@link isPackageVersionLookupNotSupportedError}
43
+ * over a bare `instanceof` check for that reason.
44
+ */
45
+ export class PackageVersionLookupNotSupportedError extends Error {
46
+ constructor(message) {
47
+ super(message ?? 'The package manager does not support looking up available package versions.');
48
+ /**
49
+ * Stable discriminator identifying this error type across bundle boundaries.
50
+ */
51
+ this.code = 'PackageVersionLookupNotSupported';
52
+ this.name = 'PackageVersionLookupNotSupportedError';
53
+ // Preserve the prototype chain when this class is transpiled to older targets so that
54
+ // `instanceof` continues to work within a single bundle.
55
+ Object.setPrototypeOf(this, PackageVersionLookupNotSupportedError.prototype);
56
+ }
57
+ }
58
+ /**
59
+ * Type guard reporting whether an error represents unsupported package version lookup.
60
+ *
61
+ * Uses the stable {@link PackageVersionLookupNotSupportedError.code} discriminator, so it returns
62
+ * `true` even when the error crossed an extension bundle boundary and `instanceof` would fail.
63
+ *
64
+ * @param error The value to test.
65
+ * @returns `true` if `error` is a {@link PackageVersionLookupNotSupportedError} (or a structurally
66
+ * equivalent error carrying the same `code`).
67
+ */
68
+ export function isPackageVersionLookupNotSupportedError(error) {
69
+ return (error instanceof PackageVersionLookupNotSupportedError ||
70
+ (typeof error === 'object' &&
71
+ error !== null &&
72
+ 'code' in error &&
73
+ error.code === 'PackageVersionLookupNotSupported'));
74
+ }
75
+ export const EXTENSION_ID = 'ms-python.vscode-python-envs';
76
+ export var PythonEnvironments;
77
+ (function (PythonEnvironments) {
78
+ /**
79
+ * Returns the API exposed by the Python Environments extension in VS Code.
80
+ */
81
+ async function api() {
82
+ const extension = extensions.getExtension(EXTENSION_ID);
83
+ if (extension === undefined) {
84
+ throw new Error(`Python Environments extension (${EXTENSION_ID}) is not installed or is disabled`);
85
+ }
86
+ if (!extension.isActive) {
87
+ await extension.activate();
88
+ }
89
+ const api = extension.exports;
90
+ if (!api) {
91
+ throw new Error(`Python Environments extension (${EXTENSION_ID}) did not expose its API. Ensure "python.useEnvironmentsExtension" is enabled and reload the window.`);
92
+ }
93
+ return api;
94
+ }
95
+ PythonEnvironments.api = api;
96
+ })(PythonEnvironments || (PythonEnvironments = {}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vscode/python-environments",
3
3
  "description": "An API facade for the Python Environments extension in VS Code",
4
- "version": "1.0.0",
4
+ "version": "1.3.0",
5
5
  "author": {
6
6
  "name": "Microsoft Corporation"
7
7
  },
@@ -11,8 +11,18 @@
11
11
  "API",
12
12
  "Environments"
13
13
  ],
14
- "main": "./out/main.js",
15
- "types": "./out/main.d.ts",
14
+ "main": "./out/cjs/main.cjs",
15
+ "types": "./out/cjs/main.d.ts",
16
+ "exports": {
17
+ "import": {
18
+ "types": "./out/esm/main.d.ts",
19
+ "default": "./out/esm/main.mjs"
20
+ },
21
+ "require": {
22
+ "types": "./out/cjs/main.d.ts",
23
+ "default": "./out/cjs/main.cjs"
24
+ }
25
+ },
16
26
  "engines": {
17
27
  "node": ">=22.21.1",
18
28
  "vscode": "^1.110.0"
@@ -30,12 +40,19 @@
30
40
  "prepublishOnly": "echo \"⛔ Can only publish from a secure pipeline ⛔\" && node -e \"process.exitCode = 1\"",
31
41
  "prepack": "npm run all:publish",
32
42
  "all:publish": "git clean -xfd . && npm install && npm run compile",
33
- "compile": "tsc -b ./tsconfig.json",
34
- "clean": "node -e \"const fs = require('fs'); fs.rmSync('./out', { recursive: true, force: true });\""
43
+ "compile": "npm run compile:esm && npm run compile:cjs",
44
+ "compile:esm": "tsc -b ./tsconfig.esm.json && mve out/esm/main.js out/esm/main.mjs",
45
+ "compile:cjs": "tsc -b ./tsconfig.cjs.json && mve out/cjs/main.js out/cjs/main.cjs",
46
+ "clean": "node -e \"const fs = require('fs'); fs.rmSync('./out', { recursive: true, force: true });\"",
47
+ "test:package": "node ./scripts/test-package.cjs"
35
48
  },
36
49
  "devDependencies": {
37
50
  "@types/node": "^22.0.0",
38
51
  "@types/vscode": "^1.99.0",
52
+ "mve": "^0.1.2",
39
53
  "typescript": "^5.1.3"
54
+ },
55
+ "dependencies": {
56
+ "@renovatebot/pep440": "^3.1.0"
40
57
  }
41
58
  }
package/out/main.js DELETED
@@ -1,54 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation. All rights reserved.
3
- // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.PythonEnvironments = exports.EXTENSION_ID = exports.PackageChangeKind = exports.EnvironmentChangeKind = void 0;
6
- const vscode_1 = require("vscode");
7
- /**
8
- * Enum representing the kinds of environment changes.
9
- */
10
- var EnvironmentChangeKind;
11
- (function (EnvironmentChangeKind) {
12
- /**
13
- * Indicates that an environment was added.
14
- */
15
- EnvironmentChangeKind["add"] = "add";
16
- /**
17
- * Indicates that an environment was removed.
18
- */
19
- EnvironmentChangeKind["remove"] = "remove";
20
- })(EnvironmentChangeKind || (exports.EnvironmentChangeKind = EnvironmentChangeKind = {}));
21
- /**
22
- * Enum representing the kinds of package changes.
23
- */
24
- var PackageChangeKind;
25
- (function (PackageChangeKind) {
26
- /**
27
- * Indicates that a package was added.
28
- */
29
- PackageChangeKind["add"] = "add";
30
- /**
31
- * Indicates that a package was removed.
32
- */
33
- PackageChangeKind["remove"] = "remove";
34
- })(PackageChangeKind || (exports.PackageChangeKind = PackageChangeKind = {}));
35
- exports.EXTENSION_ID = 'ms-python.vscode-python-envs';
36
- // eslint-disable-next-line @typescript-eslint/no-namespace
37
- var PythonEnvironments;
38
- (function (PythonEnvironments) {
39
- /**
40
- * Returns the API exposed by the Python Environments extension in VS Code.
41
- */
42
- async function api() {
43
- const extension = vscode_1.extensions.getExtension(exports.EXTENSION_ID);
44
- if (extension === undefined) {
45
- throw new Error(`Python Environments extension is not installed or is disabled`);
46
- }
47
- if (!extension.isActive) {
48
- await extension.activate();
49
- }
50
- const pythonEnvsApi = extension.exports;
51
- return pythonEnvsApi;
52
- }
53
- PythonEnvironments.api = api;
54
- })(PythonEnvironments || (exports.PythonEnvironments = PythonEnvironments = {}));