Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to v2 #1295

Merged
merged 60 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
4fa60c8
Swith to protobuf v2
srikrsna-buf Jun 14, 2024
2caeea1
Use string instead of `*n` in bigint test
srikrsna-buf Jun 25, 2024
6a7f30b
V2: Bump protobuf version (#1119)
srikrsna-buf Jun 27, 2024
4406276
V2: Fix skipped tests (#1120)
srikrsna-buf Jun 27, 2024
850cc09
Merge remote-tracking branch 'origin/main' into v2
srikrsna-buf Jun 28, 2024
91df9de
Fix release script
srikrsna-buf Jul 1, 2024
4378268
Release 2.0.0-alpha.1 (#1121)
srikrsna-buf Jul 1, 2024
f7b9194
V2: Update dependencies (#1133)
srikrsna-buf Jul 2, 2024
8288a07
V2: Remove unused .npmignore file (#1134)
timostamm Jul 9, 2024
14ab5f8
V2: Fix connect-migrate tsconfig.json (#1135)
timostamm Jul 9, 2024
45876d5
V2: Support removal of dependencies in connect-migrate (#1137)
timostamm Jul 10, 2024
848dce0
V2: Improve testing codemods in connect-migration (#1138)
timostamm Jul 11, 2024
6a399a6
V2: Support buf.gen.yaml in connect-migrate (#1141)
timostamm Jul 11, 2024
99c2ada
Add migration to v2 (#1142)
timostamm Jul 15, 2024
abbd55b
V2: Update JSDoc for ConnectRouter methods service and rpc (#1147)
timostamm Jul 16, 2024
c919a65
V2: Use base64Encoding options from @bufbuild/protobuf v2 (#1148)
timostamm Jul 17, 2024
baa2f4c
Merge remote-tracking branch 'origin/main' into v2
timostamm Jul 18, 2024
6c4e9a7
V2: Allow inline type imports in linter (#1150)
timostamm Jul 22, 2024
91006d0
V2: Update bundle-size benchmark (#1152)
timostamm Jul 22, 2024
5ac11ec
V2: Update to Protobuf-ES 2.0.0-beta.3 (#1153)
timostamm Jul 24, 2024
938d528
Merge remote-tracking branch 'origin/main' into v2
timostamm Aug 27, 2024
b92b370
V2: Update to Protobuf-ES 2.0.0 (#1189)
timostamm Aug 27, 2024
ef48f10
V2: Correct type inference for ConnectError#findDetails (#1188)
bhollis Aug 28, 2024
f8fd18c
Lint and format (#1191)
timostamm Aug 28, 2024
ee8dcc7
Merge remote-tracking branch 'origin/main' into v2
srikrsna-buf Sep 11, 2024
c482703
Revert changes to Migrate package.json
srikrsna-buf Sep 11, 2024
2670571
V2: Remove protoc-gen-connect-es (#1224)
timostamm Sep 12, 2024
a054d37
V2: Remove Node10 subpath fallbacks (#1227)
timostamm Sep 12, 2024
cabda22
V2: Remove support for Node.js v16 (#1225)
timostamm Sep 12, 2024
7ca8eac
Fix type type error in `bigint` test (#1229)
srikrsna-buf Sep 13, 2024
ab1b7c2
V2: Use `Stream{Request|Response}` types in interceptors for all stre…
srikrsna-buf Sep 13, 2024
ed4b0e5
V2: Bump minimum supported TypeScript version to 4.9.5 (#1231)
timostamm Sep 13, 2024
25ca96e
V2: Don't trigger handler signal on success (#1234)
srikrsna-buf Sep 17, 2024
fe5e10d
V2: Update dependencies (#1239)
timostamm Sep 19, 2024
d0b30f3
Merge remote-tracking branch 'origin/main' into v2
srikrsna-buf Sep 19, 2024
8b25cf3
V2: Remove `createPromiseClient` and `PromiseClient` (#1240)
srikrsna-buf Sep 19, 2024
33be09c
Bump browser versions tested on Browserstack (#1241)
timostamm Sep 19, 2024
d42db7a
V2: Remove "credentials" option from transports (#1242)
timostamm Sep 20, 2024
8356e5a
V2: Run `createPromiseClient` -> `createClient` codemod on all v1 ver…
srikrsna-buf Sep 20, 2024
3ebee77
V2: Update migration versions (#1245)
timostamm Sep 20, 2024
413d0e7
Release 2.0.0-beta.1 (#1246)
timostamm Sep 20, 2024
1e09ec8
V2: Remove obsolete todo (#1254)
srikrsna-buf Oct 3, 2024
f8fc90e
V2: Replace MethodInfo with Descriptor Types (#1255)
srikrsna-buf Oct 3, 2024
77fb02d
V2: Use `DescMethod*` types from `@bufbuild/protobuf` (#1260)
srikrsna-buf Oct 9, 2024
c4b0bf9
Merge remote-tracking branch 'origin/main' into v2
timostamm Oct 9, 2024
f637557
V2: Add Connect-Query v2.0.0-beta.1 to connect-migrate (#1264)
timostamm Oct 10, 2024
bc11967
V2: Fix Connect-Query v2.0.0-beta.1 in connect-migrate (#1266)
timostamm Oct 10, 2024
0f284e4
Release 2.0.0-beta.2 (#1265)
timostamm Oct 10, 2024
3f95330
V2: Fix transform for `createPromiseClient` -> `createClient` in conn…
paul-sachs Oct 10, 2024
d81d475
V2: Fix CI (#1278)
srikrsna-buf Oct 16, 2024
f6c9fac
V2: Require HTTP/2 for the gRPC transport (#1279)
timostamm Oct 17, 2024
00004e3
V2: Ensure that a signal exists for a completed RPC (#1282)
timostamm Oct 18, 2024
075f0e1
Release 2.0.0-rc.1 (#1283)
timostamm Oct 18, 2024
92dcc1a
Allow user-provided User-Agent request header (#1272)
polRk Oct 28, 2024
da706e0
V2: Add support for Next.js v15 (#1290)
timostamm Oct 31, 2024
0323619
Release 2.0.0-rc.2 (#1291)
timostamm Oct 31, 2024
af47285
V2: Update makeAnyClient signature to carry type information to narro…
timostamm Oct 31, 2024
b79668b
Merge remote-tracking branch 'origin/v2' into tstamm/Switch-to-v2
timostamm Nov 4, 2024
df4fb65
Add note in README.md
timostamm Nov 4, 2024
f506f94
Update note in README.md
timostamm Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
V2: Improve testing codemods in connect-migration (#1138)
  • Loading branch information
timostamm authored Jul 11, 2024
commit 848dce02bdff055ab46d828a43f2f4d02aff341b
89 changes: 89 additions & 0 deletions packages/connect-migrate/src/lib/migrate-source-file.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2021-2024 The Connect Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { updateSourceFileInMemory } from "./migrate-source-files";
import j from "jscodeshift";

describe("updateSourceFileInMemory", function () {
it("should return modified = false for unmodified", () => {
const transform: j.Transform = (file, { j }) => {
return j(file.source).toSource();
};
const result = updateSourceFileInMemory(
transform,
`
const foo = 123;
`,
"foo.ts",
);
expect(result.modified).toBe(false);
});
it("should parse js", () => {
const transform: j.Transform = (file, { j }) => {
return j(file.source)
.findVariableDeclarators("foo")
.renameTo("bar")
.toSource();
};
const result = updateSourceFileInMemory(
transform,
`
const foo = 123;
`,
"foo.ts",
);
expect(result.modified).toBe(true);
expect(result.source).toBe(`
const bar = 123;
`);
});
it("should parse ts", () => {
const transform: j.Transform = (file, { j }) => {
return j(file.source)
.findVariableDeclarators("foo")
.renameTo("bar")
.toSource();
};
const result = updateSourceFileInMemory(
transform,
`
const foo: number = 123;
`,
"foo.ts",
);
expect(result.modified).toBe(true);
expect(result.source).toBe(`
const bar: number = 123;
`);
});
it("should parse tsx", () => {
const transform: j.Transform = (file, { j }) => {
return j(file.source)
.findVariableDeclarators("foo")
.renameTo("bar")
.toSource();
};
const result = updateSourceFileInMemory(
transform,
`
const foo = () => (<body>body</body>);
`,
"foo.tsx",
);
expect(result.modified).toBe(true);
expect(result.source).toBe(`
const bar = () => (<body>body</body>);
`);
});
});
70 changes: 68 additions & 2 deletions packages/connect-migrate/src/lib/migrate-source-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// limitations under the License.

import { Scanned } from "./scan";
import j from "jscodeshift";
import { Logger, PrintFn } from "./logger";
import { updateSourceFile } from "./update-source-file";
import j, { Transform } from "jscodeshift";
import { readFileSync, writeFileSync } from "node:fs";

interface MigrateSourceFilesResult {
sourceFileErrors: number;
Expand Down Expand Up @@ -57,3 +57,69 @@ export function migrateSourceFiles(
sourceFileErrors,
};
}

const codeshiftTs = j.withParser("ts");
const codeshiftTsx = j.withParser("tsx");
const codeshiftBabel = j.withParser("babel");

interface UpdateSourceFileResult {
ok: boolean;
modified: boolean;
}

export function updateSourceFile(
transform: Transform,
path: string,
logger?: Logger,
): UpdateSourceFileResult {
logger?.log(`transform ${path}`);
try {
const source = readFileSync(path, "utf8");
const result = updateSourceFileInMemory(transform, source, path);
if (!result.modified) {
logger?.log(`skipped`);
return { ok: true, modified: false };
}
writeFileSync(path, result.source, "utf-8");
logger?.log(`modified`);
return { ok: true, modified: true };
} catch (e) {
logger?.error(`caught error: ${String(e)}`);
if (e instanceof Error && e.stack !== undefined) {
logger?.error(e.stack);
}
return { ok: false, modified: false };
}
}

export function updateSourceFileInMemory(
transform: Transform,
source: string,
path: string,
): { modified: boolean; source: string } {
let jscs: j.JSCodeshift;
if (path.endsWith(".tsx")) {
jscs = codeshiftTsx;
} else if (path.endsWith(".ts")) {
jscs = codeshiftTs;
} else {
jscs = codeshiftBabel;
}
const result = transform(
{ path, source },
{
jscodeshift: jscs,
j: jscs,
stats: () => {},
report: () => {},
},
{},
);
if (typeof result != "string") {
return { modified: false, source };
}
if (result.trim() === source.trim()) {
return { modified: false, source };
}
return { modified: true, source: result };
}
73 changes: 0 additions & 73 deletions packages/connect-migrate/src/lib/update-source-file.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/connect-migrate/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { Scanned } from "./lib/scan";
import { CommandLineArgs } from "./arguments";
import { Logger, PrintFn } from "./lib/logger";
import { updateSourceFile } from "./lib/update-source-file";
import { updateSourceFile } from "./lib/migrate-source-files";
import { writePackageJsonFile } from "./lib/package-json";
import { runInstall } from "./lib/run";

Expand Down
80 changes: 37 additions & 43 deletions packages/connect-migrate/src/migrations/v0.13.1-transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,60 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import jscodeshift from "jscodeshift";
import transform from "./v0.13.1-transform";

function t(
source: string,
parser: "tsx" | "babel" | "ts" | "babylon" | "flow" = "tsx",
) {
const shift = jscodeshift.withParser(parser);
return transform(
{ path: "test-file", source },
{
jscodeshift: shift,
j: shift,
stats: () => {},
report: () => {},
},
{},
);
}
import { updateSourceFileInMemory } from "../lib/migrate-source-files";

describe("modify-imports", () => {
it("should modify import", () => {
const got = `import a from "@bufbuild/connect";`;
const want = `import a from "@connectrpc/connect";`;
expect(t(got)?.trim()).toBe(want.trim());
const input = `import a from "@bufbuild/connect";`;
const output = `import a from "@connectrpc/connect";`;
const result = updateSourceFileInMemory(transform, input, "foo.ts");
expect(result.source).toBe(output);
});
it("should modify type imports", () => {
const got = `import type {a} from "@bufbuild/connect";`;
const want = `import type {a} from "@connectrpc/connect";`;
expect(t(got)?.trim()).toBe(want.trim());
const input = `import type {a} from "@bufbuild/connect";`;
const output = `import type {a} from "@connectrpc/connect";`;
const result = updateSourceFileInMemory(transform, input, "foo.ts");
expect(result.source).toBe(output);
});
it("should modify import with single quotes", () => {
const got = `import a from '@bufbuild/connect';`;
const want = `import a from '@connectrpc/connect';`;
expect(t(got)?.trim()).toBe(want.trim());
const input = `import a from '@bufbuild/connect';`;
const output = `import a from '@connectrpc/connect';`;
const result = updateSourceFileInMemory(transform, input, "foo.ts");
expect(result.source).toBe(output);
});
it("should modify subpath import", () => {
const got = `import a from "@bufbuild/connect/protocol";`;
const want = `import a from "@connectrpc/connect/protocol";`;
expect(t(got)?.trim()).toBe(want.trim());
const input = `import a from "@bufbuild/connect/protocol";`;
const output = `import a from "@connectrpc/connect/protocol";`;
const result = updateSourceFileInMemory(transform, input, "foo.ts");
expect(result.source).toBe(output);
});
it("should not modify irrelevant import", () => {
const got = `import a from "@foobar/connect";`;
expect(t(got)).toBe(got);
const input = `import a from "@foobar/connect";`;
const output = input;
const result = updateSourceFileInMemory(transform, input, "foo.ts");
expect(result.source).toBe(output);
});
it("should modify require", () => {
const got = `const a = require("@bufbuild/connect");`;
const want = `const a = require("@connectrpc/connect");`;
expect(t(got)?.trim()).toBe(want.trim());
const input = `const a = require("@bufbuild/connect");`;
const output = `const a = require("@connectrpc/connect");`;
const result = updateSourceFileInMemory(transform, input, "foo.ts");
expect(result.source).toBe(output);
});
it("should not modify irrelevant require", () => {
const got = `const a = require("@foobar/connect");`;
expect(t(got)).toBe(got);
const input = `const a = require("@foobar/connect");`;
const output = input;
const result = updateSourceFileInMemory(transform, input, "foo.ts");
expect(result.source).toBe(output);
});
it("should modify require with single quotes", () => {
const got = `const a = require('@bufbuild/connect');`;
const want = `const a = require('@connectrpc/connect');`;
expect(t(got)?.trim()).toBe(want.trim());
const input = `const a = require('@bufbuild/connect');`;
const output = `const a = require('@connectrpc/connect');`;
const result = updateSourceFileInMemory(transform, input, "foo.ts");
expect(result.source).toBe(output);
});
it("should parse generics using the ts parser", () => {
const got = `
const input = `
async function doSomething() {
return <UnaryResponse<I, O>>{
stream: false,
Expand All @@ -81,7 +74,7 @@ describe("modify-imports", () => {
trailer,
};
}`;
const want = `
const output = `
async function doSomething() {
return <UnaryResponse<I, O>>{
stream: false,
Expand All @@ -90,6 +83,7 @@ describe("modify-imports", () => {
trailer,
};
}`;
expect(t(got, "ts")?.trim()).toBe(want.trim());
const result = updateSourceFileInMemory(transform, input, "foo.ts");
expect(result.source).toBe(output);
});
});
6 changes: 4 additions & 2 deletions packages/connect-migrate/src/migrations/v0.13.1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import {
DependencyMigration,
migrateDependencies,
} from "../lib/migrate-dependencies";
import { updateSourceFile } from "../lib/update-source-file";
import { migrateSourceFiles } from "../lib/migrate-source-files";
import {
migrateSourceFiles,
updateSourceFile,
} from "../lib/migrate-source-files";
import { migratePackages } from "../lib/migrate-packages";
import { migrateLockFiles } from "../lib/migrate-lock-files";

Expand Down
Loading