vsix-utils
Version:
utilities for working with VSIX packages
110 lines (106 loc) • 3.58 kB
text/typescript
import { Manifest } from './types.cjs';
/**
* @module validation
*
* This module contains utility functions for validating manifests.
*
* @example
* ```ts
* import { readProjectManifest } from "vsix-utils/manifest";
* import { validateProjectManifest } from "vsix-utils/validation";
*
* const projectManifest = await readProjectManifest('/path/to/project');
*
* if (projectManifest != null) {
* console.log("an error occurred while reading the project manifest");
* }
*
* const { manifest } = projectManifest;
*
* const errors = await validateProjectManifest(manifest);
*
* if (errors != null) {
* console.log("validation failed with the following errors:");
* console.log(errors);
* }
*
* console.log("no errors found");
* ```
*/
/**
* Validates the compatibility between VS Code engine version and @types/vscode version
*
* @param {string} engineVersion - The VS Code engine version specified in package.json (e.g., "^1.70.0")
* @param {string} typesVersion - The @types/vscode version specified in package.json (e.g., "1.70.0")
*
* @throws {Error} When engine version is invalid
* @throws {Error} When types version is invalid
* @throws {Error} When either version cannot be parsed
* @throws {Error} When types version is higher than engine version
*
* @remarks
* If engine version is "*", no validation is performed as it indicates compatibility with any version.
* The function ensures that the @types/vscode version does not exceed the specified engine version
* to prevent compatibility issues.
*/
declare function validateVSCodeTypesCompatability(engineVersion: string, typesVersion: string): void;
type ManifestValidation = {
type: "MISSING_FIELD";
field: string;
message: string;
} | {
type: "INVALID_VSCODE_ENGINE_COMPATIBILITY";
field: string;
message: string;
} | {
type: "INVALID_VALUE";
field: string;
message: string;
} | {
type: "INVALID_PRICING";
message: string;
value: string;
} | {
type: "VSCODE_TYPES_INCOMPATIBILITY";
message: string;
} | {
type: "INVALID_ICON";
field: string;
message: string;
} | {
type: "INVALID_BADGE_URL";
field: string;
message: string;
} | {
type: "UNTRUSTED_HOST";
field: string;
message: string;
} | {
type: "DEPENDS_ON_VSCODE_IN_DEPENDENCIES";
field: string;
message: string;
} | {
type: "INVALID_EXTENSION_KIND";
field: string;
message: string;
} | {
type: "INVALID_SPONSOR_URL";
field: string;
message: string;
};
declare const ALLOWED_SPONSOR_PROTOCOLS: string[];
declare const VALID_EXTENSION_KINDS: string[];
declare const EXTENSION_PRICING: string[];
declare const EXTENSION_NAME_REGEX: RegExp;
declare const VSCODE_ENGINE_COMPATIBILITY_REGEX: RegExp;
declare const GITHUB_BADGE_URL_REGEX: RegExp;
/**
* Validates a partial manifest object for required fields and valid sponsor URL.
*
* @param {Partial<Manifest>} manifest - The partial manifest object to validate
* @returns {Promise<ManifestValidation[] | null>} A promise that resolves to either:
* - `null` if validation passes with no errors
* - An array of {@link ManifestValidation} objects describing validation errors
*/
declare function validateProjectManifest(manifest: Partial<Manifest>): Promise<ManifestValidation[] | null>;
export { ALLOWED_SPONSOR_PROTOCOLS, EXTENSION_NAME_REGEX, EXTENSION_PRICING, GITHUB_BADGE_URL_REGEX, type ManifestValidation, VALID_EXTENSION_KINDS, VSCODE_ENGINE_COMPATIBILITY_REGEX, validateProjectManifest, validateVSCodeTypesCompatability };