feat: create schema version map with CURRENT_MANIFEST_SCHEMA selector

This commit is contained in:
Joan Xie 2025-09-24 13:57:19 -07:00
commit 3a0d4a8635
No known key found for this signature in database
4 changed files with 42 additions and 8 deletions

View file

@ -2,7 +2,7 @@ import { confirm, input, select } from "@inquirer/prompts";
import { existsSync, readFileSync, writeFileSync } from "fs";
import { basename, join, resolve } from "path";
import { MANIFEST_VERSION } from "../schemas/0.2.js";
import { CURRENT_MANIFEST_VERSION } from "../shared/constants.js";
import type { McpbManifest } from "../types.js";
interface PackageJson {
@ -774,7 +774,7 @@ export function buildManifest(
const { keywords, license, repository } = optionalFields;
return {
manifest_version: MANIFEST_VERSION,
manifest_version: CURRENT_MANIFEST_VERSION,
name,
...(displayName && displayName !== name
? { display_name: displayName }

View file

@ -13,7 +13,7 @@ import { basename, join, relative, resolve, sep } from "path";
import { getAllFilesWithCount, readMcpbIgnorePatterns } from "../node/files.js";
import { validateManifest } from "../node/validate.js";
import { MANIFEST_VERSION, McpbManifestSchema } from "../schemas/0.2.js";
import { CURRENT_MANIFEST_VERSION, CURRENT_MANIFEST_SCHEMA } from "../shared/constants.js";
import { getLogger } from "../shared/log.js";
import { initExtension } from "./init.js";
@ -92,7 +92,7 @@ export async function packExtension({
try {
const manifestContent = readFileSync(manifestPath, "utf-8");
const manifestData = JSON.parse(manifestContent);
manifest = McpbManifestSchema.parse(manifestData);
manifest = CURRENT_MANIFEST_SCHEMA.parse(manifestData);
} catch (error) {
logger.error("ERROR: Failed to parse manifest.json");
if (error instanceof Error) {

View file

@ -6,8 +6,7 @@ import { join, resolve } from "path";
import prettyBytes from "pretty-bytes";
import { unpackExtension } from "../cli/unpack.js";
import { McpbManifestSchema } from "../schemas/0.2.js";
import { McpbManifestSchema as LooseMcpbManifestSchema } from "../schemas_loose/0.2.js";
import { CURRENT_MANIFEST_SCHEMA, CURRENT_MANIFEST_SCHEMA_LOOSE } from "../shared/constants.js";
export function validateManifest(inputPath: string): boolean {
try {
@ -22,7 +21,7 @@ export function validateManifest(inputPath: string): boolean {
const manifestContent = readFileSync(manifestPath, "utf-8");
const manifestData = JSON.parse(manifestContent);
const result = McpbManifestSchema.safeParse(manifestData);
const result = CURRENT_MANIFEST_SCHEMA.safeParse(manifestData);
if (result.success) {
console.log("Manifest schema validation passes!");
@ -72,7 +71,7 @@ export async function cleanMcpb(inputPath: string) {
const manifestPath = resolve(unpackPath, "manifest.json");
const originalManifest = await fs.readFile(manifestPath, "utf-8");
const manifestData = JSON.parse(originalManifest);
const result = LooseMcpbManifestSchema.safeParse(manifestData);
const result = CURRENT_MANIFEST_SCHEMA_LOOSE.safeParse(manifestData);
if (!result.success) {
throw new Error(

35
src/shared/constants.ts Normal file
View file

@ -0,0 +1,35 @@
import { McpbManifestSchema as ManifestSchemaV0_1 } from "../schemas/0.1.js";
import { McpbManifestSchema as ManifestSchemaV0_2 } from "../schemas/0.2.js";
import { McpbManifestSchema as LooseManifestSchemaV0_1 } from "../schemas_loose/0.1.js";
import { McpbManifestSchema as LooseManifestSchemaV0_2 } from "../schemas_loose/0.2.js";
/**
* Current manifest version - the version that new manifests should use
*/
export const CURRENT_MANIFEST_VERSION = "0.2" as const;
/**
* Map of manifest versions to their strict schemas
*/
export const MANIFEST_SCHEMAS = {
"0.1": ManifestSchemaV0_1,
"0.2": ManifestSchemaV0_2,
} as const;
/**
* Map of manifest versions to their loose schemas (with passthrough)
*/
export const MANIFEST_SCHEMAS_LOOSE = {
"0.1": LooseManifestSchemaV0_1,
"0.2": LooseManifestSchemaV0_2,
} as const;
/**
* Get the current manifest schema based on CURRENT_MANIFEST_VERSION
*/
export const CURRENT_MANIFEST_SCHEMA = MANIFEST_SCHEMAS[CURRENT_MANIFEST_VERSION];
/**
* Get the current loose manifest schema based on CURRENT_MANIFEST_VERSION
*/
export const CURRENT_MANIFEST_SCHEMA_LOOSE = MANIFEST_SCHEMAS_LOOSE[CURRENT_MANIFEST_VERSION];