diff --git a/packages/cli/lang/en.json b/packages/cli/lang/en.json index 66704fcfb6..ee7e5adbf1 100644 --- a/packages/cli/lang/en.json +++ b/packages/cli/lang/en.json @@ -171,8 +171,10 @@ "commands_polywrap_helpPrompt": "Type {command} to view common commands", "commands_manifest_description": "Inspect & Migrade Polywrap Manifests", "commands_manifest_options_m": "Path to the manifest file (default: {default})", + "commands_manifest_options_f": "Target format to migrate to (defaults to latest)", "commands_manifest_options_t": "Type of manifest file to migrate (default: {default})", "commands_manifest_options_m_path": "path", + "commands_manifest_options_m_format": "format", "commands_manifest_options_t_type": "type", "commands_manifest_command_s": "Prints out the schema for the current manifest format.", "commands_manifest_command_m": "Migrates the polywrap project manifest to the latest version.", @@ -180,6 +182,7 @@ "commands_manifest_command_m_preserveManifestMessage": "Saved previous version of manifest to {preservedFilePath}", "commands_manifest_command_m_migrateManifestMessage": "Migrating {manifestFile} to version {version}", "commands_manifest_formatError": "Unsupported manifest format. Please make sure that you have the 'format' field present in {fileName} with one of the following values: {values}", + "commands_manifest_migrate_targetFormatError": "Unsupported target format. Supported formats: {formats}", "commands_manifest_projectTypeError": "Unsupported project type.", "lib_codeGenerator_genCodeError": "Failed to generate types", "lib_codeGenerator_genCodeText": "Generate types", diff --git a/packages/cli/lang/es.json b/packages/cli/lang/es.json index 6b7672f82a..a085fec988 100644 --- a/packages/cli/lang/es.json +++ b/packages/cli/lang/es.json @@ -171,15 +171,18 @@ "commands_polywrap_helpPrompt": "Type {command} to view common commands", "commands_manifest_description": "Inspect & Migrade Polywrap Manifests", "commands_manifest_options_m": "Path to the manifest file (default: {default})", + "commands_manifest_options_f": "Target format to migrate to (defaults to latest)", "commands_manifest_options_t": "Type of manifest file to migrate (default: {default})", "commands_manifest_options_m_path": "path", + "commands_manifest_options_m_format": "format", "commands_manifest_options_t_type": "type", "commands_manifest_command_s": "Prints out the schema for the current manifest format.", "commands_manifest_command_m": "Migrates the polywrap project manifest to the latest version.", "commands_manifest_command_s_option_r": "Output raw JSON Schema", "commands_manifest_command_m_preserveManifestMessage": "Saved previous version of manifest to {preservedFilePath}", "commands_manifest_command_m_migrateManifestMessage": "Migrating {manifestFile} to version {version}", - "commands_manifest_formatError": "Could not detect manifest format. Please make sure that you have the 'format' field present in {fileName} with one of the following values: {values}", + "commands_manifest_formatError": "Unsupported manifest format. Please make sure that you have the 'format' field present in {fileName} with one of the following values: {values}", + "commands_manifest_migrate_targetFormatError": "Unsupported target format. Supported formats: {formats}", "commands_manifest_projectTypeError": "Unsupported project type.", "lib_codeGenerator_genCodeError": "Failed to generate types", "lib_codeGenerator_genCodeText": "Generate types", diff --git a/packages/cli/src/__tests__/e2e/manifest.spec.ts b/packages/cli/src/__tests__/e2e/manifest.spec.ts index 99e75963af..6403355681 100644 --- a/packages/cli/src/__tests__/e2e/manifest.spec.ts +++ b/packages/cli/src/__tests__/e2e/manifest.spec.ts @@ -36,6 +36,7 @@ Options: | polywrap.yml | polywrap.app.yaml | polywrap.app.yml | polywrap.plugin.yaml | polywrap.plugin.yml) + -f, --format Target format to migrate to (defaults to latest) -h, --help display help for command `; @@ -135,7 +136,7 @@ describe("e2e tests for manifest command", () => { app: "polywrap.app.yaml", plugin: "polywrap.plugin.yaml", }; - + const validSampleExtensionManifestFiles: Record = { build: "polywrap.build.yaml", deploy: "polywrap.deploy.yaml", @@ -143,7 +144,7 @@ describe("e2e tests for manifest command", () => { meta: "polywrap.meta.yaml", workflow: "polywrap.test.yaml", }; - + const tempDir = path.join(testsRoot, "temp"); beforeAll(async () => { @@ -193,6 +194,22 @@ describe("e2e tests for manifest command", () => { expect(oldFileExists).toBeTruthy(); }); + + test(`Should display error when invalid target format is provided for ${projectType} project manifest`, async () => { + const { + exitCode: code, + stdout: output, + stderr: error, + } = await runCLI({ + args: ["manifest", "migrate", "-m", manifestFile, "-f", "INVALID_MANIFEST_FORMAT"], + cwd: tempDir, + cli: polywrapCli, + }); + + expect(output).toBe(""); + expect(error).toContain("Unsupported target format. Supported formats:"); + expect(code).toBe(1); + }); } for (const extensionType in validSampleExtensionManifestFiles) { @@ -226,6 +243,22 @@ describe("e2e tests for manifest command", () => { expect(oldFileExists).toBeTruthy(); }); + + test(`Should display error when invalid target format is provided for ${extensionType} extension manifest`, async () => { + const { + exitCode: code, + stdout: output, + stderr: error, + } = await runCLI({ + args: ["manifest", "migrate", extensionType, "-m", manifestFile, "-f", "INVALID_MANIFEST_FORMAT"], + cwd: tempDir, + cli: polywrapCli, + }); + + expect(output).toBe(""); + expect(error).toContain("Unsupported target format. Supported formats:"); + expect(code).toBe(1); + }); } }); }); diff --git a/packages/cli/src/commands/manifest.ts b/packages/cli/src/commands/manifest.ts index cd1d56bb62..438d086144 100644 --- a/packages/cli/src/commands/manifest.ts +++ b/packages/cli/src/commands/manifest.ts @@ -59,6 +59,7 @@ import fs from "fs"; import path from "path"; const pathStr = intlMsg.commands_manifest_options_m_path(); +const formatStr = intlMsg.commands_manifest_options_m_format(); const defaultProjectManifestStr = defaultProjectManifestFiles.join(" | "); @@ -79,6 +80,7 @@ type ManifestSchemaCommandOptions = { type ManifestMigrateCommandOptions = { manifestFile: string; + format: string; }; export const manifest: Command = { @@ -135,6 +137,10 @@ export const manifest: Command = { default: defaultProjectManifestStr, })}` ) + .option( + `-f, --format <${formatStr}>`, + `${intlMsg.commands_manifest_options_f()}` + ) .action(async (type, options) => { await runMigrateCommand(type, options); }); @@ -366,22 +372,34 @@ const runMigrateCommand = async ( } if (isPolywrapManifestLanguage(language)) { + maybeFailOnUnsupportedTargetFormat( + options.format, + Object.values(PolywrapManifestFormats) + ); return migrateManifestFile( manifestFile, migratePolywrapProjectManifest, - latestPolywrapManifestFormat + options.format ?? latestPolywrapManifestFormat ); } else if (isAppManifestLanguage(language)) { + maybeFailOnUnsupportedTargetFormat( + options.format, + Object.values(AppManifestFormats) + ); return migrateManifestFile( manifestFile, migrateAppProjectManifest, - latestPolywrapManifestFormat + options.format ?? latestPolywrapManifestFormat ); } else if (isPluginManifestLanguage(language)) { + maybeFailOnUnsupportedTargetFormat( + options.format, + Object.values(PluginManifestFormats) + ); return migrateManifestFile( manifestFile, migratePluginProjectManifest, - latestPolywrapManifestFormat + options.format ?? latestPolywrapManifestFormat ); } @@ -390,42 +408,62 @@ const runMigrateCommand = async ( break; case "build": + maybeFailOnUnsupportedTargetFormat( + options.format, + Object.values(BuildManifestFormats) + ); migrateManifestFile( parseManifestFileOption(options.manifestFile, defaultBuildManifest), migrateBuildExtensionManifest, - latestBuildManifestFormat + options.format ?? latestBuildManifestFormat ); break; case "meta": + maybeFailOnUnsupportedTargetFormat( + options.format, + Object.values(MetaManifestFormats) + ); migrateManifestFile( parseManifestFileOption(options.manifestFile, defaultMetaManifest), migrateMetaExtensionManifest, - latestMetaManifestFormat + options.format ?? latestMetaManifestFormat ); break; case "deploy": + maybeFailOnUnsupportedTargetFormat( + options.format, + Object.values(DeployManifestFormats) + ); migrateManifestFile( parseManifestFileOption(options.manifestFile, defaultDeployManifest), migrateDeployExtensionManifest, - latestDeployManifestFormat + options.format ?? latestDeployManifestFormat ); break; case "infra": + maybeFailOnUnsupportedTargetFormat( + options.format, + Object.values(InfraManifestFormats) + ); migrateManifestFile( parseManifestFileOption(options.manifestFile, defaultInfraManifest), migrateInfraExtensionManifest, - latestInfraManifestFormat + options.format ?? latestInfraManifestFormat ); break; case "workflow": + maybeFailOnUnsupportedTargetFormat( + options.format, + Object.values(PolywrapWorkflowFormats) + ); migrateManifestFile( parseManifestFileOption(options.manifestFile, defaultWorkflowManifest), migrateWorkflow, - latestPolywrapWorkflowFormat + options.format ?? latestPolywrapWorkflowFormat ); break; } @@ -433,8 +471,8 @@ const runMigrateCommand = async ( function migrateManifestFile( manifestFile: string, - migrationFn: (input: string) => string, - version: string + migrationFn: (input: string, to: string) => string, + to: string ): void { const manifestFileName = path.basename(manifestFile); const manifestFileDir = path.dirname(manifestFile); @@ -442,7 +480,7 @@ function migrateManifestFile( console.log( intlMsg.commands_manifest_command_m_migrateManifestMessage({ manifestFile: manifestFileName, - version: version, + version: to, }) ); @@ -450,7 +488,7 @@ function migrateManifestFile( encoding: "utf-8", }); - const outputManifestString = migrationFn(manifestString); + const outputManifestString = migrationFn(manifestString, to); // Cache the old manifest file const cache = new CacheDirectory({ @@ -489,7 +527,25 @@ function maybeFailOnUnsupportedManifestFormat( console.error( intlMsg.commands_manifest_formatError({ fileName: path.relative(".", manifestFile), - values: Object.values(PolywrapManifestFormats).join(", "), + values: formats.join(", "), + }) + ); + process.exit(1); + } +} + +function maybeFailOnUnsupportedTargetFormat( + format: string | undefined, + formats: string[] +) { + if (!format) { + return; + } + + if (!formats.includes(format)) { + console.error( + intlMsg.commands_manifest_migrate_targetFormatError({ + formats: formats.join(", "), }) ); process.exit(1); diff --git a/packages/cli/src/lib/manifest/migrate/migrateAnyManifest.ts b/packages/cli/src/lib/manifest/migrate/migrateAnyManifest.ts index 72da66f0ac..c8725db501 100644 --- a/packages/cli/src/lib/manifest/migrate/migrateAnyManifest.ts +++ b/packages/cli/src/lib/manifest/migrate/migrateAnyManifest.ts @@ -3,7 +3,8 @@ import YAML from "js-yaml"; export function migrateAnyManifest( manifestString: string, manifestTypeName: string, - migrateFn: (manifest: unknown) => unknown + migrateFn: (manifest: unknown, to: string) => unknown, + to: string ): string { let manifest: unknown | undefined; try { @@ -16,7 +17,7 @@ export function migrateAnyManifest( throw Error(`Unable to parse ${manifestTypeName}: ${manifestString}`); } - const newManifest = migrateFn(manifest); + const newManifest = migrateFn(manifest, to); const cleanedManifest = JSON.parse(JSON.stringify(newManifest)); delete cleanedManifest.__type; diff --git a/packages/cli/src/lib/manifest/migrate/migrateAppProjectManifest.ts b/packages/cli/src/lib/manifest/migrate/migrateAppProjectManifest.ts index f68b9993a8..9b8e920194 100644 --- a/packages/cli/src/lib/manifest/migrate/migrateAppProjectManifest.ts +++ b/packages/cli/src/lib/manifest/migrate/migrateAppProjectManifest.ts @@ -1,16 +1,15 @@ import { migrateAnyManifest } from "./migrateAnyManifest"; -import { - AnyAppManifest, - latestAppManifestFormat, - migrateAppManifest, -} from "@polywrap/polywrap-manifest-types-js"; +import { migrateAppManifest } from "@polywrap/polywrap-manifest-types-js"; -export function migrateAppProjectManifest(manifestString: string): string { +export function migrateAppProjectManifest( + manifestString: string, + to: string +): string { return migrateAnyManifest( manifestString, "AppManifest", - (manifest: AnyAppManifest) => - migrateAppManifest(manifest, latestAppManifestFormat) + migrateAppManifest, + to ); } diff --git a/packages/cli/src/lib/manifest/migrate/migrateBuildExtensionManifest.ts b/packages/cli/src/lib/manifest/migrate/migrateBuildExtensionManifest.ts index 6c305e03e8..1d6607f881 100644 --- a/packages/cli/src/lib/manifest/migrate/migrateBuildExtensionManifest.ts +++ b/packages/cli/src/lib/manifest/migrate/migrateBuildExtensionManifest.ts @@ -1,16 +1,15 @@ import { migrateAnyManifest } from "./migrateAnyManifest"; -import { - AnyBuildManifest, - latestBuildManifestFormat, - migrateBuildManifest, -} from "@polywrap/polywrap-manifest-types-js"; +import { migrateBuildManifest } from "@polywrap/polywrap-manifest-types-js"; -export function migrateBuildExtensionManifest(manifestString: string): string { +export function migrateBuildExtensionManifest( + manifestString: string, + to: string +): string { return migrateAnyManifest( manifestString, "BuildManifest", - (manifest: AnyBuildManifest) => - migrateBuildManifest(manifest, latestBuildManifestFormat) + migrateBuildManifest, + to ); } diff --git a/packages/cli/src/lib/manifest/migrate/migrateDeployExtensionManifest.ts b/packages/cli/src/lib/manifest/migrate/migrateDeployExtensionManifest.ts index 98f2bf5722..0b096e63a9 100644 --- a/packages/cli/src/lib/manifest/migrate/migrateDeployExtensionManifest.ts +++ b/packages/cli/src/lib/manifest/migrate/migrateDeployExtensionManifest.ts @@ -1,16 +1,15 @@ import { migrateAnyManifest } from "./migrateAnyManifest"; -import { - AnyDeployManifest, - latestDeployManifestFormat, - migrateDeployManifest, -} from "@polywrap/polywrap-manifest-types-js"; +import { migrateDeployManifest } from "@polywrap/polywrap-manifest-types-js"; -export function migrateDeployExtensionManifest(manifestString: string): string { +export function migrateDeployExtensionManifest( + manifestString: string, + to: string +): string { return migrateAnyManifest( manifestString, "DeployManifest", - (manifest: AnyDeployManifest) => - migrateDeployManifest(manifest, latestDeployManifestFormat) + migrateDeployManifest, + to ); } diff --git a/packages/cli/src/lib/manifest/migrate/migrateInfraExtensionManifest.ts b/packages/cli/src/lib/manifest/migrate/migrateInfraExtensionManifest.ts index 7b31439084..e7a214810e 100644 --- a/packages/cli/src/lib/manifest/migrate/migrateInfraExtensionManifest.ts +++ b/packages/cli/src/lib/manifest/migrate/migrateInfraExtensionManifest.ts @@ -1,16 +1,15 @@ import { migrateAnyManifest } from "./migrateAnyManifest"; -import { - AnyInfraManifest, - latestInfraManifestFormat, - migrateInfraManifest, -} from "@polywrap/polywrap-manifest-types-js"; +import { migrateInfraManifest } from "@polywrap/polywrap-manifest-types-js"; -export function migrateInfraExtensionManifest(manifestString: string): string { +export function migrateInfraExtensionManifest( + manifestString: string, + to: string +): string { return migrateAnyManifest( manifestString, "InfraManifest", - (manifest: AnyInfraManifest) => - migrateInfraManifest(manifest, latestInfraManifestFormat) + migrateInfraManifest, + to ); } diff --git a/packages/cli/src/lib/manifest/migrate/migrateMetaExtensionManifest.ts b/packages/cli/src/lib/manifest/migrate/migrateMetaExtensionManifest.ts index 320d02ab4d..c136d4edd2 100644 --- a/packages/cli/src/lib/manifest/migrate/migrateMetaExtensionManifest.ts +++ b/packages/cli/src/lib/manifest/migrate/migrateMetaExtensionManifest.ts @@ -1,16 +1,15 @@ import { migrateAnyManifest } from "./migrateAnyManifest"; -import { - AnyMetaManifest, - latestMetaManifestFormat, - migrateMetaManifest, -} from "@polywrap/polywrap-manifest-types-js"; +import { migrateMetaManifest } from "@polywrap/polywrap-manifest-types-js"; -export function migrateMetaExtensionManifest(manifestString: string): string { +export function migrateMetaExtensionManifest( + manifestString: string, + to: string +): string { return migrateAnyManifest( manifestString, "MetaManifest", - (manifest: AnyMetaManifest) => - migrateMetaManifest(manifest, latestMetaManifestFormat) + migrateMetaManifest, + to ); } diff --git a/packages/cli/src/lib/manifest/migrate/migratePluginProjectManifest.ts b/packages/cli/src/lib/manifest/migrate/migratePluginProjectManifest.ts index f5dc484af3..21297e7116 100644 --- a/packages/cli/src/lib/manifest/migrate/migratePluginProjectManifest.ts +++ b/packages/cli/src/lib/manifest/migrate/migratePluginProjectManifest.ts @@ -1,16 +1,15 @@ import { migrateAnyManifest } from "./migrateAnyManifest"; -import { - AnyPluginManifest, - latestPluginManifestFormat, - migratePluginManifest, -} from "@polywrap/polywrap-manifest-types-js"; +import { migratePluginManifest } from "@polywrap/polywrap-manifest-types-js"; -export function migratePluginProjectManifest(manifestString: string): string { +export function migratePluginProjectManifest( + manifestString: string, + to: string +): string { return migrateAnyManifest( manifestString, "PluginManifest", - (manifest: AnyPluginManifest) => - migratePluginManifest(manifest, latestPluginManifestFormat) + migratePluginManifest, + to ); } diff --git a/packages/cli/src/lib/manifest/migrate/migratePolywrapProjectManifest.ts b/packages/cli/src/lib/manifest/migrate/migratePolywrapProjectManifest.ts index 5e4afd4ecb..9c15a4e62b 100644 --- a/packages/cli/src/lib/manifest/migrate/migratePolywrapProjectManifest.ts +++ b/packages/cli/src/lib/manifest/migrate/migratePolywrapProjectManifest.ts @@ -1,16 +1,15 @@ import { migrateAnyManifest } from "./migrateAnyManifest"; -import { - AnyPolywrapManifest, - latestPolywrapManifestFormat, - migratePolywrapManifest, -} from "@polywrap/polywrap-manifest-types-js"; +import { migratePolywrapManifest } from "@polywrap/polywrap-manifest-types-js"; -export function migratePolywrapProjectManifest(manifestString: string): string { +export function migratePolywrapProjectManifest( + manifestString: string, + to: string +): string { return migrateAnyManifest( manifestString, "PolywrapManifest", - (manifest: AnyPolywrapManifest) => - migratePolywrapManifest(manifest, latestPolywrapManifestFormat) + migratePolywrapManifest, + to ); } diff --git a/packages/cli/src/lib/manifest/migrate/migrateTestExtensionManifest.ts b/packages/cli/src/lib/manifest/migrate/migrateTestExtensionManifest.ts index 679d7836b2..cd61504b5b 100644 --- a/packages/cli/src/lib/manifest/migrate/migrateTestExtensionManifest.ts +++ b/packages/cli/src/lib/manifest/migrate/migrateTestExtensionManifest.ts @@ -1,16 +1,12 @@ import { migrateAnyManifest } from "./migrateAnyManifest"; -import { - AnyPolywrapWorkflow, - latestPolywrapWorkflowFormat, - migratePolywrapWorkflow, -} from "@polywrap/polywrap-manifest-types-js"; +import { migratePolywrapWorkflow } from "@polywrap/polywrap-manifest-types-js"; -export function migrateWorkflow(manifestString: string): string { +export function migrateWorkflow(manifestString: string, to: string): string { return migrateAnyManifest( manifestString, "PolywrapWorkflow", - (manifest: AnyPolywrapWorkflow) => - migratePolywrapWorkflow(manifest, latestPolywrapWorkflowFormat) + migratePolywrapWorkflow, + to ); } diff --git a/packages/js/manifests/polywrap/scripts/templates/migrate-ts.mustache b/packages/js/manifests/polywrap/scripts/templates/migrate-ts.mustache index 8817e13039..d53a3f4bbc 100644 --- a/packages/js/manifests/polywrap/scripts/templates/migrate-ts.mustache +++ b/packages/js/manifests/polywrap/scripts/templates/migrate-ts.mustache @@ -8,7 +8,6 @@ import { Any{{#latest}}{{type}}{{/latest}}, {{#latest}}{{type}}{{/latest}}, {{#latest}}{{type}}{{/latest}}Formats, - latest{{#latest}}{{type}}{{/latest}}Format } from "."; import { findShortestMigrationPath } from "../../migrations"; import { migrators } from "./migrators"; @@ -19,14 +18,14 @@ export function migrate{{#latest}}{{type}}{{/latest}}( ): {{#latest}}{{type}}{{/latest}} { let from = manifest.format as {{#latest}}{{type}}{{/latest}}Formats; - if (from === latest{{#latest}}{{type}}{{/latest}}Format) { - return manifest as {{#latest}}{{type}}{{/latest}}; - } - if (!(Object.values({{#latest}}{{type}}{{/latest}}Formats).some(x => x === from))) { throw new Error(`Unrecognized {{#latest}}{{type}}{{/latest}}Format "${manifest.format}"`); } + if (!(Object.values({{#latest}}{{type}}{{/latest}}Formats).some(x => x === to))) { + throw new Error(`Unrecognized {{#latest}}{{type}}{{/latest}}Format "${to}"`); + } + const migrationPath = findShortestMigrationPath(migrators, from, to); if (!migrationPath) { throw new Error( diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.app/migrate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.app/migrate.ts index f0b24e1abc..d5223e4cdb 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.app/migrate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.app/migrate.ts @@ -8,7 +8,6 @@ import { AnyAppManifest, AppManifest, AppManifestFormats, - latestAppManifestFormat } from "."; import { findShortestMigrationPath } from "../../migrations"; import { migrators } from "./migrators"; @@ -19,14 +18,14 @@ export function migrateAppManifest( ): AppManifest { let from = manifest.format as AppManifestFormats; - if (from === latestAppManifestFormat) { - return manifest as AppManifest; - } - if (!(Object.values(AppManifestFormats).some(x => x === from))) { throw new Error(`Unrecognized AppManifestFormat "${manifest.format}"`); } + if (!(Object.values(AppManifestFormats).some(x => x === to))) { + throw new Error(`Unrecognized AppManifestFormat "${to}"`); + } + const migrationPath = findShortestMigrationPath(migrators, from, to); if (!migrationPath) { throw new Error( diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.build/migrate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.build/migrate.ts index acf48ffbec..ba82b20295 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.build/migrate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.build/migrate.ts @@ -8,7 +8,6 @@ import { AnyBuildManifest, BuildManifest, BuildManifestFormats, - latestBuildManifestFormat } from "."; import { findShortestMigrationPath } from "../../migrations"; import { migrators } from "./migrators"; @@ -19,14 +18,14 @@ export function migrateBuildManifest( ): BuildManifest { let from = manifest.format as BuildManifestFormats; - if (from === latestBuildManifestFormat) { - return manifest as BuildManifest; - } - if (!(Object.values(BuildManifestFormats).some(x => x === from))) { throw new Error(`Unrecognized BuildManifestFormat "${manifest.format}"`); } + if (!(Object.values(BuildManifestFormats).some(x => x === to))) { + throw new Error(`Unrecognized BuildManifestFormat "${to}"`); + } + const migrationPath = findShortestMigrationPath(migrators, from, to); if (!migrationPath) { throw new Error( diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.deploy/migrate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.deploy/migrate.ts index 7186f8edd5..09cc08fda8 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.deploy/migrate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.deploy/migrate.ts @@ -8,7 +8,6 @@ import { AnyDeployManifest, DeployManifest, DeployManifestFormats, - latestDeployManifestFormat } from "."; import { findShortestMigrationPath } from "../../migrations"; import { migrators } from "./migrators"; @@ -19,14 +18,14 @@ export function migrateDeployManifest( ): DeployManifest { let from = manifest.format as DeployManifestFormats; - if (from === latestDeployManifestFormat) { - return manifest as DeployManifest; - } - if (!(Object.values(DeployManifestFormats).some(x => x === from))) { throw new Error(`Unrecognized DeployManifestFormat "${manifest.format}"`); } + if (!(Object.values(DeployManifestFormats).some(x => x === to))) { + throw new Error(`Unrecognized DeployManifestFormat "${to}"`); + } + const migrationPath = findShortestMigrationPath(migrators, from, to); if (!migrationPath) { throw new Error( diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.infra/migrate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.infra/migrate.ts index 989982381f..ee769e3f9d 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.infra/migrate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.infra/migrate.ts @@ -8,7 +8,6 @@ import { AnyInfraManifest, InfraManifest, InfraManifestFormats, - latestInfraManifestFormat } from "."; import { findShortestMigrationPath } from "../../migrations"; import { migrators } from "./migrators"; @@ -19,14 +18,14 @@ export function migrateInfraManifest( ): InfraManifest { let from = manifest.format as InfraManifestFormats; - if (from === latestInfraManifestFormat) { - return manifest as InfraManifest; - } - if (!(Object.values(InfraManifestFormats).some(x => x === from))) { throw new Error(`Unrecognized InfraManifestFormat "${manifest.format}"`); } + if (!(Object.values(InfraManifestFormats).some(x => x === to))) { + throw new Error(`Unrecognized InfraManifestFormat "${to}"`); + } + const migrationPath = findShortestMigrationPath(migrators, from, to); if (!migrationPath) { throw new Error( diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.meta/migrate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.meta/migrate.ts index 170087ac42..d9066967bc 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.meta/migrate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.meta/migrate.ts @@ -8,7 +8,6 @@ import { AnyMetaManifest, MetaManifest, MetaManifestFormats, - latestMetaManifestFormat } from "."; import { findShortestMigrationPath } from "../../migrations"; import { migrators } from "./migrators"; @@ -19,14 +18,14 @@ export function migrateMetaManifest( ): MetaManifest { let from = manifest.format as MetaManifestFormats; - if (from === latestMetaManifestFormat) { - return manifest as MetaManifest; - } - if (!(Object.values(MetaManifestFormats).some(x => x === from))) { throw new Error(`Unrecognized MetaManifestFormat "${manifest.format}"`); } + if (!(Object.values(MetaManifestFormats).some(x => x === to))) { + throw new Error(`Unrecognized MetaManifestFormat "${to}"`); + } + const migrationPath = findShortestMigrationPath(migrators, from, to); if (!migrationPath) { throw new Error( diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.plugin/migrate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.plugin/migrate.ts index 16e49bddbe..462745b609 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.plugin/migrate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.plugin/migrate.ts @@ -8,7 +8,6 @@ import { AnyPluginManifest, PluginManifest, PluginManifestFormats, - latestPluginManifestFormat } from "."; import { findShortestMigrationPath } from "../../migrations"; import { migrators } from "./migrators"; @@ -19,14 +18,14 @@ export function migratePluginManifest( ): PluginManifest { let from = manifest.format as PluginManifestFormats; - if (from === latestPluginManifestFormat) { - return manifest as PluginManifest; - } - if (!(Object.values(PluginManifestFormats).some(x => x === from))) { throw new Error(`Unrecognized PluginManifestFormat "${manifest.format}"`); } + if (!(Object.values(PluginManifestFormats).some(x => x === to))) { + throw new Error(`Unrecognized PluginManifestFormat "${to}"`); + } + const migrationPath = findShortestMigrationPath(migrators, from, to); if (!migrationPath) { throw new Error( diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.test/migrate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.test/migrate.ts index 6ba38c0066..fab4a75251 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.test/migrate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.test/migrate.ts @@ -8,7 +8,6 @@ import { AnyPolywrapWorkflow, PolywrapWorkflow, PolywrapWorkflowFormats, - latestPolywrapWorkflowFormat } from "."; import { findShortestMigrationPath } from "../../migrations"; import { migrators } from "./migrators"; @@ -19,14 +18,14 @@ export function migratePolywrapWorkflow( ): PolywrapWorkflow { let from = manifest.format as PolywrapWorkflowFormats; - if (from === latestPolywrapWorkflowFormat) { - return manifest as PolywrapWorkflow; - } - if (!(Object.values(PolywrapWorkflowFormats).some(x => x === from))) { throw new Error(`Unrecognized PolywrapWorkflowFormat "${manifest.format}"`); } + if (!(Object.values(PolywrapWorkflowFormats).some(x => x === to))) { + throw new Error(`Unrecognized PolywrapWorkflowFormat "${to}"`); + } + const migrationPath = findShortestMigrationPath(migrators, from, to); if (!migrationPath) { throw new Error( diff --git a/packages/js/manifests/polywrap/src/formats/polywrap/migrate.ts b/packages/js/manifests/polywrap/src/formats/polywrap/migrate.ts index 45d4167a4c..300cd6dc68 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap/migrate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap/migrate.ts @@ -8,7 +8,6 @@ import { AnyPolywrapManifest, PolywrapManifest, PolywrapManifestFormats, - latestPolywrapManifestFormat } from "."; import { findShortestMigrationPath } from "../../migrations"; import { migrators } from "./migrators"; @@ -19,14 +18,14 @@ export function migratePolywrapManifest( ): PolywrapManifest { let from = manifest.format as PolywrapManifestFormats; - if (from === latestPolywrapManifestFormat) { - return manifest as PolywrapManifest; - } - if (!(Object.values(PolywrapManifestFormats).some(x => x === from))) { throw new Error(`Unrecognized PolywrapManifestFormat "${manifest.format}"`); } + if (!(Object.values(PolywrapManifestFormats).some(x => x === to))) { + throw new Error(`Unrecognized PolywrapManifestFormat "${to}"`); + } + const migrationPath = findShortestMigrationPath(migrators, from, to); if (!migrationPath) { throw new Error(