From 3ebee77c84204e9ae9739e230dd6a3c2aaab3500 Mon Sep 17 00:00:00 2001 From: Timo Stamm Date: Fri, 20 Sep 2024 13:10:37 +0200 Subject: [PATCH] V2: Update migration versions (#1245) --- packages/connect-migrate/src/cli.ts | 4 +- .../src/migrations/v0.13.1.spec.ts | 2 +- .../connect-migrate/src/migrations/v0.13.1.ts | 4 +- ...sform.spec.ts => v1.6.0-transform.spec.ts} | 2 +- ....16.0-transform.ts => v1.6.0-transform.ts} | 0 .../{v1.16.0.spec.ts => v1.6.0.spec.ts} | 20 +-- .../src/migrations/{v1.16.0.ts => v1.6.0.ts} | 4 +- .../src/migrations/v2.0.0.spec.ts | 121 +++++++++--------- .../connect-migrate/src/migrations/v2.0.0.ts | 42 +++--- 9 files changed, 97 insertions(+), 102 deletions(-) rename packages/connect-migrate/src/migrations/{v1.16.0-transform.spec.ts => v1.6.0-transform.spec.ts} (99%) rename packages/connect-migrate/src/migrations/{v1.16.0-transform.ts => v1.6.0-transform.ts} (100%) rename packages/connect-migrate/src/migrations/{v1.16.0.spec.ts => v1.6.0.spec.ts} (85%) rename packages/connect-migrate/src/migrations/{v1.16.0.ts => v1.6.0.ts} (96%) diff --git a/packages/connect-migrate/src/cli.ts b/packages/connect-migrate/src/cli.ts index c8188fccb..5649d2d36 100644 --- a/packages/connect-migrate/src/cli.ts +++ b/packages/connect-migrate/src/cli.ts @@ -20,7 +20,7 @@ import { scan } from "./lib/scan"; import { Logger } from "./lib/logger"; import { v0_13_1 } from "./migrations/v0.13.1"; import { v2_0_0 } from "./migrations/v2.0.0"; -import { v1_16_0 } from "./migrations/v1.16.0"; +import { v1_6_0 } from "./migrations/v1.6.0"; import type { Migration } from "./migration"; const usage = `USAGE: connect-migrate [flags] @@ -35,7 +35,7 @@ Flags: `; const logger = new Logger(); -const migrations = [v0_13_1, v1_16_0, v2_0_0]; +const migrations = [v0_13_1, v1_6_0, v2_0_0]; void main(); async function main() { diff --git a/packages/connect-migrate/src/migrations/v0.13.1.spec.ts b/packages/connect-migrate/src/migrations/v0.13.1.spec.ts index a315f963d..c2661c79c 100644 --- a/packages/connect-migrate/src/migrations/v0.13.1.spec.ts +++ b/packages/connect-migrate/src/migrations/v0.13.1.spec.ts @@ -166,7 +166,7 @@ describe("migration to v0.13.1", function () { expect(packageJsonWritten.length).toBe(1); expect(packageJsonWritten[0].pkg).toEqual({ dependencies: { - "@connectrpc/connect": "^1.1.2", + "@connectrpc/connect": "^1.6.0", }, }); expect(lockFilesUpdated.length).toBe(1); diff --git a/packages/connect-migrate/src/migrations/v0.13.1.ts b/packages/connect-migrate/src/migrations/v0.13.1.ts index 855b63d01..0a4203181 100644 --- a/packages/connect-migrate/src/migrations/v0.13.1.ts +++ b/packages/connect-migrate/src/migrations/v0.13.1.ts @@ -28,8 +28,8 @@ import { import { migratePackages } from "../lib/migrate-packages"; import { migrateLockFiles } from "../lib/migrate-lock-files"; -export const targetVersionConnectEs = "1.1.2"; -export const targetVersionConnectQuery = "0.5.1"; +export const targetVersionConnectEs = "1.6.0"; +export const targetVersionConnectQuery = "1.4.2"; /** * The latest available version of protoc-gen-connect-web is v0.11.0. diff --git a/packages/connect-migrate/src/migrations/v1.16.0-transform.spec.ts b/packages/connect-migrate/src/migrations/v1.6.0-transform.spec.ts similarity index 99% rename from packages/connect-migrate/src/migrations/v1.16.0-transform.spec.ts rename to packages/connect-migrate/src/migrations/v1.6.0-transform.spec.ts index 6fe1a966c..5541984e6 100644 --- a/packages/connect-migrate/src/migrations/v1.16.0-transform.spec.ts +++ b/packages/connect-migrate/src/migrations/v1.6.0-transform.spec.ts @@ -13,7 +13,7 @@ // limitations under the License. import jscodeshift from "jscodeshift"; -import transform from "./v1.16.0-transform"; +import transform from "./v1.6.0-transform"; function t( source: string, diff --git a/packages/connect-migrate/src/migrations/v1.16.0-transform.ts b/packages/connect-migrate/src/migrations/v1.6.0-transform.ts similarity index 100% rename from packages/connect-migrate/src/migrations/v1.16.0-transform.ts rename to packages/connect-migrate/src/migrations/v1.6.0-transform.ts diff --git a/packages/connect-migrate/src/migrations/v1.16.0.spec.ts b/packages/connect-migrate/src/migrations/v1.6.0.spec.ts similarity index 85% rename from packages/connect-migrate/src/migrations/v1.16.0.spec.ts rename to packages/connect-migrate/src/migrations/v1.6.0.spec.ts index bf16c3342..c75f1bfca 100644 --- a/packages/connect-migrate/src/migrations/v1.16.0.spec.ts +++ b/packages/connect-migrate/src/migrations/v1.6.0.spec.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { v1_16_0 } from "./v1.16.0"; +import { v1_6_0 } from "./v1.6.0"; import type { PackageJson } from "../lib/package-json"; import type { MigrateOptions } from "../migration"; @@ -55,20 +55,20 @@ describe("migration", function () { }; }); describe("should be applicable", function () { - it("for 1.16.0", () => { + it("for 1.6.0", () => { opt.scanned.packageFiles = [ { path: "package.json", pkg: { dependencies: { - "@connectrpc/connect": "^1.16.0", + "@connectrpc/connect": "^1.6.0", }, }, }, ]; - expect(v1_16_0.applicable(opt.scanned)).toBeTrue(); + expect(v1_6_0.applicable(opt.scanned)).toBeTrue(); }); - it("after 1.16.0", () => { + it("after 1.6.0", () => { opt.scanned.packageFiles = [ { path: "package.json", @@ -79,20 +79,20 @@ describe("migration", function () { }, }, ]; - expect(v1_16_0.applicable(opt.scanned)).toBeTrue(); + expect(v1_6_0.applicable(opt.scanned)).toBeTrue(); }); - it("before 1.16.0", () => { + it("before 1.6.0", () => { opt.scanned.packageFiles = [ { path: "package.json", pkg: { dependencies: { - "@connectrpc/connect": "^1.15.0", + "@connectrpc/connect": "^1.5.0", }, }, }, ]; - expect(v1_16_0.applicable(opt.scanned)).toBeTrue(); + expect(v1_6_0.applicable(opt.scanned)).toBeTrue(); }); }); describe("should not be applicable", function () { @@ -107,7 +107,7 @@ describe("migration", function () { }, }, ]; - expect(v1_16_0.applicable(opt.scanned)).toBeFalse(); + expect(v1_6_0.applicable(opt.scanned)).toBeFalse(); }); }); }); diff --git a/packages/connect-migrate/src/migrations/v1.16.0.ts b/packages/connect-migrate/src/migrations/v1.6.0.ts similarity index 96% rename from packages/connect-migrate/src/migrations/v1.16.0.ts rename to packages/connect-migrate/src/migrations/v1.6.0.ts index c7c7e895d..76db88662 100644 --- a/packages/connect-migrate/src/migrations/v1.16.0.ts +++ b/packages/connect-migrate/src/migrations/v1.6.0.ts @@ -13,7 +13,7 @@ // limitations under the License. import type { Scanned } from "../lib/scan"; -import replaceCalls from "./v1.16.0-transform"; +import replaceCalls from "./v1.6.0-transform"; import type { MigrateError, MigrateSuccess, Migration } from "../migration"; import { migrateSourceFiles, @@ -25,7 +25,7 @@ import * as semver from "semver"; * Migrates code to use new symbols `createClient` and `Client` instead * of `createPromiseClient` and `PromiseClient`. */ -export const v1_16_0: Migration = { +export const v1_6_0: Migration = { applicable(scanned: Scanned) { return getMatchingPackages(scanned.packageFiles).length > 0; }, diff --git a/packages/connect-migrate/src/migrations/v2.0.0.spec.ts b/packages/connect-migrate/src/migrations/v2.0.0.spec.ts index 629a94f03..79c76d2a4 100644 --- a/packages/connect-migrate/src/migrations/v2.0.0.spec.ts +++ b/packages/connect-migrate/src/migrations/v2.0.0.spec.ts @@ -118,7 +118,7 @@ plugins: expect(bufGenYamlWritten.length).toBe(1); expect(bufGenYamlWritten[0]?.yaml).toEqual(`version: v2 plugins: - - remote: buf.build/bufbuild/es:v2.0.0 + - remote: buf.build/bufbuild/es:v2.1.0 out: src/gen `); }); @@ -193,62 +193,63 @@ plugins: `); }); }); - describe("for connect-query-es v1", () => { - beforeEach(function () { - opt.scanned.packageFiles = [ - { - path: "package.json", - pkg: { - dependencies: { - "@connectrpc/connect-query": "^1.4.1", - "@connectrpc/protoc-gen-connect-query": "^1.4.1", - }, - }, - }, - ]; - opt.scanned.bufGenYamlFiles = [ - { - path: "buf.gen.yaml", - yaml: parseBufGenYaml( - `version: v2 -plugins: - - remote: buf.build/connectrpc/query-es:v1.4.1 - out: src/gen -`, - ), - }, - ]; - }); - it("should be applicable", () => { - expect(v2_0_0.applicable(opt.scanned)).toBeTrue(); - }); - it("should migrate packages", () => { - const result = v2_0_0.migrate(opt); - expect(result).toEqual({ - ok: true, - }); - expect(packageJsonWritten.length).toBe(1); - expect(packageJsonWritten[0].pkg).toEqual({ - dependencies: { - "@connectrpc/connect-query": `^${targetVersionConnectQuery}`, - "@connectrpc/protoc-gen-connect-query": `^${targetVersionConnectQuery}`, - }, - }); - expect(lockFilesUpdated.length).toBe(1); - }); - it("should migrate buf.gen.yaml", () => { - const result = v2_0_0.migrate(opt); - expect(result).toEqual({ - ok: true, - }); - expect(bufGenYamlWritten.length).toBe(1); - expect(bufGenYamlWritten[0]?.yaml).toEqual(`version: v2 -plugins: - - remote: buf.build/connectrpc/query-es:v2.0.0 - out: src/gen -`); - }); - }); + // TODO + // describe("for connect-query-es v1", () => { + // beforeEach(function () { + // opt.scanned.packageFiles = [ + // { + // path: "package.json", + // pkg: { + // dependencies: { + // "@connectrpc/connect-query": "^1.4.2", + // "@connectrpc/protoc-gen-connect-query": "^1.4.2", + // }, + // }, + // }, + // ]; + // opt.scanned.bufGenYamlFiles = [ + // { + // path: "buf.gen.yaml", + // yaml: parseBufGenYaml( + // `version: v2 + // plugins: + // - remote: buf.build/connectrpc/query-es:v1.4.1 + // out: src/gen + // `, + // ), + // }, + // ]; + // }); + // it("should be applicable", () => { + // expect(v2_0_0.applicable(opt.scanned)).toBeTrue(); + // }); + // it("should migrate packages", () => { + // const result = v2_0_0.migrate(opt); + // expect(result).toEqual({ + // ok: true, + // }); + // expect(packageJsonWritten.length).toBe(1); + // expect(packageJsonWritten[0].pkg).toEqual({ + // dependencies: { + // "@connectrpc/connect-query": `^${targetVersionConnectQuery}`, + // "@connectrpc/protoc-gen-connect-query": `^${targetVersionConnectQuery}`, + // }, + // }); + // expect(lockFilesUpdated.length).toBe(1); + // }); + // it("should migrate buf.gen.yaml", () => { + // const result = v2_0_0.migrate(opt); + // expect(result).toEqual({ + // ok: true, + // }); + // expect(bufGenYamlWritten.length).toBe(1); + // expect(bufGenYamlWritten[0]?.yaml).toEqual(`version: v2 + // plugins: + // - remote: buf.build/connectrpc/query-es:v1.4.2 + // out: src/gen + // `); + // }); + // }); describe("for connect-playwright-es v1", () => { beforeEach(function () { opt.scanned.packageFiles = [ @@ -300,7 +301,6 @@ plugins: "@connectrpc/connect-query": `^${targetVersionConnectQuery}`, "@connectrpc/protoc-gen-connect-query": `^${targetVersionConnectQuery}`, - "@connectrpc/protoc-gen-connect-query-react": `^${targetVersionConnectQuery}`, "@connectrpc/connect-playwright": `^${targetVersionConnectPlaywright}`, }, @@ -322,7 +322,7 @@ plugins: out: src/gen - remote: buf.build/bufbuild/es:v2.0.0 out: src/gen - - remote: buf.build/connectrpc/query-es:v2.0.0 + - remote: buf.build/connectrpc/query-es:v1.4.2 out: src/gen `, "buf.gen.yaml", @@ -342,7 +342,7 @@ plugins: out: src/gen - plugin: buf.build/bufbuild/es:v2.0.0 out: src/gen - - plugin: buf.build/connectrpc/query-es:v2.0.0 + - plugin: buf.build/connectrpc/query-es:v1.4.2 out: src/gen `, ), @@ -418,7 +418,6 @@ plugins: dependencies: { "@bufbuild/connect-query": "*", "@bufbuild/protoc-gen-connect-query": "*", - "@bufbuild/protoc-gen-connect-query-react": "*", }, }, }, diff --git a/packages/connect-migrate/src/migrations/v2.0.0.ts b/packages/connect-migrate/src/migrations/v2.0.0.ts index 40f9303ba..8b53ecf22 100644 --- a/packages/connect-migrate/src/migrations/v2.0.0.ts +++ b/packages/connect-migrate/src/migrations/v2.0.0.ts @@ -34,10 +34,10 @@ import { } from "../lib/migrate-bufgenyaml"; import { writeBufGenYamlFile } from "../lib/bufgenyaml"; -export const targetVersionProtobufEs = "2.0.0-beta.3"; -export const targetVersionConnectEs = "2.0.0-alpha.1"; -export const targetVersionConnectQuery = "2.0.0-alpha.1"; -export const targetVersionConnectPlaywright = "0.4.0"; +export const targetVersionProtobufEs = "2.1.0"; +export const targetVersionConnectEs = "2.0.0-alpha.1"; // TODO +export const targetVersionConnectQuery = "2.0.0"; // TODO +export const targetVersionConnectPlaywright = "0.4.0"; // TODO const dependencyMigrations: DependencyMigration[] = [ // https://github.com/bufbuild/protobuf-es @@ -83,15 +83,16 @@ const dependencyMigrations: DependencyMigration[] = [ remove: { name: "@connectrpc/protoc-gen-connect-es", range: "^1.0.0" }, }, - // https://github.com/connectrpc/connect-query-es - { - from: { name: "@connectrpc/connect-query", range: "^1.0.0" }, - to: { version: targetVersionConnectQuery }, - }, - { - from: { name: "@connectrpc/protoc-gen-connect-query", range: "^1.0.0" }, - to: { version: targetVersionConnectQuery }, - }, + // TODO + // // https://github.com/connectrpc/connect-query-es + // { + // from: { name: "@connectrpc/connect-query", range: "^1.0.0" }, + // to: { version: targetVersionConnectQuery }, + // }, + // { + // from: { name: "@connectrpc/protoc-gen-connect-query", range: "^1.0.0" }, + // to: { version: targetVersionConnectQuery }, + // }, // https://github.com/connectrpc/connect-playwright-es { @@ -111,21 +112,14 @@ const bufGenYamlMigrations: BufGenYamlMigration[] = [ updatePlugin: { remote: "buf.build/bufbuild/es", from: "^1.0.0", - to: "2.0.0", - }, - }, - { - updatePlugin: { - remote: "buf.build/connectrpc/es", - from: "^1.0.0", - to: "2.0.0", + to: targetVersionProtobufEs, }, }, { updatePlugin: { remote: "buf.build/connectrpc/query-es", from: "^1.0.0", - to: "2.0.0", + to: "1.4.2", // TODO }, }, ]; @@ -140,7 +134,9 @@ export const v2_0_0: Migration = { ({ yaml }) => migrateBufGenYaml(yaml, bufGenYamlMigrations) !== null, ) || scanned.packageFiles.some( - ({ pkg }) => migrateDependencies(pkg, dependencyMigrations) !== null, + ({ pkg }) => + migrateDependencies(structuredClone(pkg), dependencyMigrations) !== + null, ) ); },