Skip to content

Commit

Permalink
V2: Fix transform for createPromiseClient -> createClient in conn…
Browse files Browse the repository at this point in the history
…ect-migrate (#1268)
  • Loading branch information
paul-sachs authored Oct 10, 2024
1 parent 0f284e4 commit 3f95330
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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

0 comments on commit 3f95330

Please sign in to comment.