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

V2: Fix transform for createPromiseClient -> createClient in connect-migrate #1268

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Add handling of unchanged imports for migration
Signed-off-by: Paul Sachs <psachs@buf.build>
  • Loading branch information
paul-sachs committed Oct 10, 2024
commit 2bfc679c3d69a16fd1c034ce2b8ce85b7dd4dfc1
24 changes: 24 additions & 0 deletions packages/connect-migrate/src/migrations/v1.6.0-transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ describe("rename symbols using", () => {
`;
expect(t(got)?.trim()).toBe(want.trim());
});

it("handles other imports", () => {
const input = `
import { Code, ConnectError, createPromiseClient } from "@connectrpc/connect";
const promiseClient = createPromiseClient(ResourceService, transport);
`;
const want = `
import { Code, ConnectError, createClient } from "@connectrpc/connect";
const promiseClient = createClient(ResourceService, transport);
`;

expect(t(input)?.trim()).toBe(want.trim());
});
});
describe("'require' with", () => {
it("const", () => {
Expand Down Expand Up @@ -184,6 +197,17 @@ describe("rename symbols using", () => {
`;
expect(t(got)?.trim()).toBe(want.trim());
});

it("handles other imports", () => {
const got = `
const { Code, createPromiseClient } = require("@connectrpc/connect");
`;
const want = `
const { Code, createClient } = require("@connectrpc/connect");
`;
expect(t(got)?.trim()).toBe(want.trim());
});

it("let", () => {
const got = `
let connect;
Expand Down
4 changes: 3 additions & 1 deletion packages/connect-migrate/src/migrations/v1.6.0-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ const transform: j.Transform = (file, { j }, options) => {
specifiers: [
{
type: "ImportSpecifier",
imported: { name: (name) => [fromFunction, fromType].includes(name) },
},
],
})
.forEach((path) => {
path.value.specifiers?.forEach((s) => {
s = s as j.ImportSpecifier;
if (![fromFunction, fromType].includes(s.imported.name)) {
return;
}
// import { createPromiseClient as <local> } from "@connectrpc/connect";
//
// We should just rename createPromiseClient here and user code will continue to use local.
Expand Down
Loading