feat: create schema version map with CURRENT_MANIFEST_SCHEMA selector
This commit is contained in:
parent
fe733e3450
commit
3a0d4a8635
4 changed files with 42 additions and 8 deletions
|
|
@ -2,7 +2,7 @@ import { confirm, input, select } from "@inquirer/prompts";
|
||||||
import { existsSync, readFileSync, writeFileSync } from "fs";
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
||||||
import { basename, join, resolve } from "path";
|
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";
|
import type { McpbManifest } from "../types.js";
|
||||||
|
|
||||||
interface PackageJson {
|
interface PackageJson {
|
||||||
|
|
@ -774,7 +774,7 @@ export function buildManifest(
|
||||||
const { keywords, license, repository } = optionalFields;
|
const { keywords, license, repository } = optionalFields;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
manifest_version: MANIFEST_VERSION,
|
manifest_version: CURRENT_MANIFEST_VERSION,
|
||||||
name,
|
name,
|
||||||
...(displayName && displayName !== name
|
...(displayName && displayName !== name
|
||||||
? { display_name: displayName }
|
? { display_name: displayName }
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import { basename, join, relative, resolve, sep } from "path";
|
||||||
|
|
||||||
import { getAllFilesWithCount, readMcpbIgnorePatterns } from "../node/files.js";
|
import { getAllFilesWithCount, readMcpbIgnorePatterns } from "../node/files.js";
|
||||||
import { validateManifest } from "../node/validate.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 { getLogger } from "../shared/log.js";
|
||||||
import { initExtension } from "./init.js";
|
import { initExtension } from "./init.js";
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ export async function packExtension({
|
||||||
try {
|
try {
|
||||||
const manifestContent = readFileSync(manifestPath, "utf-8");
|
const manifestContent = readFileSync(manifestPath, "utf-8");
|
||||||
const manifestData = JSON.parse(manifestContent);
|
const manifestData = JSON.parse(manifestContent);
|
||||||
manifest = McpbManifestSchema.parse(manifestData);
|
manifest = CURRENT_MANIFEST_SCHEMA.parse(manifestData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("ERROR: Failed to parse manifest.json");
|
logger.error("ERROR: Failed to parse manifest.json");
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ import { join, resolve } from "path";
|
||||||
import prettyBytes from "pretty-bytes";
|
import prettyBytes from "pretty-bytes";
|
||||||
|
|
||||||
import { unpackExtension } from "../cli/unpack.js";
|
import { unpackExtension } from "../cli/unpack.js";
|
||||||
import { McpbManifestSchema } from "../schemas/0.2.js";
|
import { CURRENT_MANIFEST_SCHEMA, CURRENT_MANIFEST_SCHEMA_LOOSE } from "../shared/constants.js";
|
||||||
import { McpbManifestSchema as LooseMcpbManifestSchema } from "../schemas_loose/0.2.js";
|
|
||||||
|
|
||||||
export function validateManifest(inputPath: string): boolean {
|
export function validateManifest(inputPath: string): boolean {
|
||||||
try {
|
try {
|
||||||
|
|
@ -22,7 +21,7 @@ export function validateManifest(inputPath: string): boolean {
|
||||||
const manifestContent = readFileSync(manifestPath, "utf-8");
|
const manifestContent = readFileSync(manifestPath, "utf-8");
|
||||||
const manifestData = JSON.parse(manifestContent);
|
const manifestData = JSON.parse(manifestContent);
|
||||||
|
|
||||||
const result = McpbManifestSchema.safeParse(manifestData);
|
const result = CURRENT_MANIFEST_SCHEMA.safeParse(manifestData);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
console.log("Manifest schema validation passes!");
|
console.log("Manifest schema validation passes!");
|
||||||
|
|
@ -72,7 +71,7 @@ export async function cleanMcpb(inputPath: string) {
|
||||||
const manifestPath = resolve(unpackPath, "manifest.json");
|
const manifestPath = resolve(unpackPath, "manifest.json");
|
||||||
const originalManifest = await fs.readFile(manifestPath, "utf-8");
|
const originalManifest = await fs.readFile(manifestPath, "utf-8");
|
||||||
const manifestData = JSON.parse(originalManifest);
|
const manifestData = JSON.parse(originalManifest);
|
||||||
const result = LooseMcpbManifestSchema.safeParse(manifestData);
|
const result = CURRENT_MANIFEST_SCHEMA_LOOSE.safeParse(manifestData);
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
|
||||||
35
src/shared/constants.ts
Normal file
35
src/shared/constants.ts
Normal 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];
|
||||||
Loading…
Reference in a new issue