Skip to content

Commit 794bf7f

Browse files
committed
feat(upgrade): prop removal code mods
1 parent 5ef929b commit 794bf7f

File tree

3 files changed

+728
-0
lines changed

3 files changed

+728
-0
lines changed
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
export const fixtures = [
2+
{
3+
name: 'ClerkProvider legacy redirect props',
4+
source: `
5+
import { ClerkProvider } from '@clerk/nextjs';
6+
7+
export function App({ children }) {
8+
return (
9+
<ClerkProvider
10+
afterSignInUrl='/dashboard'
11+
afterSignUpUrl='/welcome'
12+
>
13+
{children}
14+
</ClerkProvider>
15+
);
16+
}
17+
`,
18+
output: `
19+
import { ClerkProvider } from '@clerk/nextjs';
20+
21+
export function App({ children }) {
22+
return (
23+
<ClerkProvider
24+
signInFallbackRedirectUrl='/dashboard'
25+
signUpFallbackRedirectUrl='/welcome'
26+
>
27+
{children}
28+
</ClerkProvider>
29+
);
30+
}
31+
`,
32+
},
33+
{
34+
name: 'SignIn legacy props',
35+
source: `
36+
import { SignIn as MySignIn } from '@clerk/nextjs';
37+
38+
export const Page = () => (
39+
<MySignIn
40+
afterSignInUrl='/home'
41+
afterSignUpUrl='/after-sign-up'
42+
fallbackRedirectUrl='/existing'
43+
/>
44+
);
45+
`,
46+
output: `
47+
import { SignIn as MySignIn } from '@clerk/nextjs';
48+
49+
export const Page = () => (
50+
<MySignIn
51+
signUpFallbackRedirectUrl='/after-sign-up'
52+
fallbackRedirectUrl='/existing' />
53+
);
54+
`,
55+
},
56+
{
57+
name: 'SignUp legacy props',
58+
source: `
59+
import { SignUp } from '@clerk/react';
60+
61+
export function Example() {
62+
return (
63+
<SignUp afterSignUpUrl='/done' afterSignInUrl='/in' />
64+
);
65+
}
66+
`,
67+
output: `
68+
import { SignUp } from '@clerk/react';
69+
70+
export function Example() {
71+
return (<SignUp fallbackRedirectUrl='/done' signInFallbackRedirectUrl='/in' />);
72+
}
73+
`,
74+
},
75+
{
76+
name: 'ClerkProvider redirectUrl only',
77+
source: `
78+
import { ClerkProvider } from '@clerk/react';
79+
80+
export const Provider = ({ children }) => (
81+
<ClerkProvider redirectUrl='/legacy'>{children}</ClerkProvider>
82+
);
83+
`,
84+
output: `
85+
import { ClerkProvider } from '@clerk/react';
86+
87+
export const Provider = ({ children }) => (
88+
<ClerkProvider signInFallbackRedirectUrl="/legacy" signUpFallbackRedirectUrl="/legacy">{children}</ClerkProvider>
89+
);
90+
`,
91+
},
92+
{
93+
name: 'SignIn redirectUrl only',
94+
source: `
95+
import { SignIn } from '@clerk/nextjs';
96+
97+
export const Page = () => <SignIn redirectUrl='/legacy' />;
98+
`,
99+
output: `
100+
import { SignIn } from '@clerk/nextjs';
101+
102+
export const Page = () => <SignIn fallbackRedirectUrl="/legacy" />;
103+
`,
104+
},
105+
{
106+
name: 'UserButton and organization props',
107+
source: `
108+
import { UserButton, OrganizationSwitcher, CreateOrganization } from '@clerk/react';
109+
110+
export const Actions = () => (
111+
<>
112+
<UserButton afterSignOutUrl='/bye' afterMultiSessionSingleSignOutUrl='/multi' />
113+
<OrganizationSwitcher hideSlug afterSwitchOrganizationUrl='/org' />
114+
<CreateOrganization hideSlug />
115+
</>
116+
);
117+
`,
118+
output: `
119+
import { UserButton, OrganizationSwitcher, CreateOrganization } from '@clerk/react';
120+
121+
export const Actions = () => (
122+
<>
123+
<UserButton />
124+
<OrganizationSwitcher afterSelectOrganizationUrl='/org' />
125+
<CreateOrganization />
126+
</>
127+
);
128+
`,
129+
},
130+
{
131+
name: 'Object literals and destructuring',
132+
source: `
133+
const config = {
134+
afterSignInUrl: '/one',
135+
afterSignUpUrl: '/two',
136+
activeSessions,
137+
};
138+
139+
const { afterSignInUrl, afterSignUpUrl: custom, activeSessions: current } = config;
140+
`,
141+
output: `
142+
const config = {
143+
signInFallbackRedirectUrl: '/one',
144+
signUpFallbackRedirectUrl: '/two',
145+
signedInSessions: activeSessions,
146+
};
147+
148+
const { signInFallbackRedirectUrl: afterSignInUrl, signUpFallbackRedirectUrl: custom, signedInSessions: current } = config;
149+
`,
150+
},
151+
{
152+
name: 'Member expressions and optional chaining',
153+
source: `
154+
const signInTarget = options.afterSignInUrl;
155+
const signUpTarget = options?.afterSignUpUrl;
156+
const fallback = options['afterSignInUrl'];
157+
const hasSessions = client?.activeSessions?.length > 0 && client['activeSessions'];
158+
`,
159+
output: `
160+
const signInTarget = options.signInFallbackRedirectUrl;
161+
const signUpTarget = options?.signUpFallbackRedirectUrl;
162+
const fallback = options["signInFallbackRedirectUrl"];
163+
const hasSessions = client?.signedInSessions?.length > 0 && client["signedInSessions"];
164+
`,
165+
},
166+
{
167+
name: 'setActive beforeEmit callback',
168+
source: `
169+
await setActive({
170+
session: '123',
171+
beforeEmit: handleBeforeEmit,
172+
});
173+
`,
174+
output: `
175+
await setActive({
176+
session: '123',
177+
navigate: params => handleBeforeEmit(params.session),
178+
});
179+
`,
180+
},
181+
{
182+
name: 'ClerkMiddlewareAuthObject type rename',
183+
source: `
184+
import type { ClerkMiddlewareAuthObject } from '@clerk/nextjs/server';
185+
186+
type Handler = (auth: ClerkMiddlewareAuthObject) => void;
187+
`,
188+
output: `
189+
import type { ClerkMiddlewareSessionAuthObject } from '@clerk/nextjs/server';
190+
191+
type Handler = (auth: ClerkMiddlewareSessionAuthObject) => void;
192+
`,
193+
},
194+
{
195+
name: 'Namespace import support',
196+
source: `
197+
import * as Clerk from '@clerk/nextjs';
198+
199+
export const Provider = ({ children }) => (
200+
<Clerk.ClerkProvider redirectUrl='/deep' />
201+
);
202+
`,
203+
output: `
204+
import * as Clerk from '@clerk/nextjs';
205+
206+
export const Provider = ({ children }) => (
207+
<Clerk.ClerkProvider signInFallbackRedirectUrl="/deep" signUpFallbackRedirectUrl="/deep" />
208+
);
209+
`,
210+
},
211+
];
212+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { applyTransform } from 'jscodeshift/dist/testUtils';
2+
import { describe, expect, it } from 'vitest';
3+
4+
import transformer from '../transform-remove-deprecated-props.cjs';
5+
import { fixtures } from './__fixtures__/transform-remove-deprecated-props.fixtures';
6+
7+
describe('transform-remove-deprecated-props', () => {
8+
it.each(fixtures)('$name', ({ source, output }) => {
9+
const result = applyTransform(transformer, {}, { source });
10+
11+
expect(result).toEqual(output.trim());
12+
});
13+
});
14+

0 commit comments

Comments
 (0)