Skip to content

Commit

Permalink
Fix transform for createPromiseClient -> createClient in connect-…
Browse files Browse the repository at this point in the history
…migrate (#1269)
  • Loading branch information
timostamm authored Oct 10, 2024
1 parent eb21c01 commit 3d10191
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 3d10191

Please sign in to comment.