-
Notifications
You must be signed in to change notification settings - Fork 417
feat(upgrade): Add migration guide generation, improve output #7397
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 5042ef6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds a new npm script and accompanying Node.js CLI tool to generate SDK-specific upgrade guides; introduces test fixtures for a Next.js v6 scenario; adds a Changes
Sequence DiagramsequenceDiagram
participant CLI as CLI User
participant Main as generate-guide (main)
participant FS as File System
participant Parser as Gray-Matter
participant Gen as Markdown Generator
participant Stdout as stdout
CLI->>Main: run --version & --sdk
Main->>Main: validate args
Main->>FS: import src/versions/{version}/index.js
FS-->>Main: versionConfig
Main->>FS: read src/versions/{version}/changes/*.md
FS-->>Parser: raw markdown files
Parser-->>Main: parsed front-matter + content
Main->>Main: filter by sdk & group by category
Main->>Gen: build markdown using versionConfig & grouped changes
Gen-->>Main: markdown document
Main->>Stdout: print guide
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (27)
Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/upgrade/scripts/generate-guide.js (2)
34-44: Consider using async file operations.While synchronous file operations (
fs.existsSync) are acceptable for CLI scripts, using the async versions (fs.promises.accessorfs.promises.stat) would be more consistent with modern Node.js patterns.Example:
async function loadVersionConfig(version) { const configPath = path.join(VERSIONS_DIR, version, 'index.js'); - if (!fs.existsSync(configPath)) { + try { + await fs.promises.access(configPath); + } catch { throw new Error(`Version config not found: ${configPath}`); }
46-79: Consider using async file operations.Similar to
loadVersionConfig, this function uses synchronous file operations (fs.existsSync,fs.readdirSync,fs.readFileSync). While acceptable for a CLI script, async versions would be more consistent with modern Node.js patterns.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
packages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
packages/upgrade/package.json(1 hunks)packages/upgrade/scripts/generate-guide.js(1 hunks)packages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/package.json(1 hunks)packages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsx(1 hunks)packages/upgrade/src/cli.js(2 hunks)packages/upgrade/src/codemods/transform-align-experimental-unstable-prefixes.cjs(0 hunks)packages/upgrade/src/runner.js(1 hunks)
💤 Files with no reviewable changes (1)
- packages/upgrade/src/codemods/transform-align-experimental-unstable-prefixes.cjs
🧰 Additional context used
📓 Path-based instructions (14)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
All code must pass ESLint checks with the project's configuration
Files:
packages/upgrade/src/runner.jspackages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsxpackages/upgrade/scripts/generate-guide.jspackages/upgrade/src/cli.js
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/upgrade/src/runner.jspackages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsxpackages/upgrade/package.jsonpackages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/package.jsonpackages/upgrade/scripts/generate-guide.jspackages/upgrade/src/cli.js
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Follow established naming conventions (PascalCase for components, camelCase for variables)
Files:
packages/upgrade/src/runner.jspackages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsxpackages/upgrade/scripts/generate-guide.jspackages/upgrade/src/cli.js
packages/**/src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Implement proper logging with different levels
Files:
packages/upgrade/src/runner.jspackages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsxpackages/upgrade/src/cli.js
**/*.{js,ts,jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Use ESLint with custom configurations tailored for different package types
Files:
packages/upgrade/src/runner.jspackages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsxpackages/upgrade/scripts/generate-guide.jspackages/upgrade/src/cli.js
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Use Prettier for code formatting across all packages
Files:
packages/upgrade/src/runner.jspackages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsxpackages/upgrade/package.jsonpackages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/package.jsonpackages/upgrade/scripts/generate-guide.jspackages/upgrade/src/cli.js
packages/**/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsx
**/*.ts?(x)
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
Files:
packages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.tsx: Use error boundaries in React components
Minimize re-renders in React components
**/*.tsx: Use proper type definitions for props and state in React components
Leverage TypeScript's type inference where possible in React components
Use proper event types for handlers in React components
Implement proper generic types for reusable React components
Use proper type guards for conditional rendering in React components
Files:
packages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsx
**/*.{md,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Update documentation for API changes
Files:
packages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsx
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components (e.g.,UserProfile,NavigationMenu)
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Separate UI components from business logic components
Use useState for simple state management in React components
Use useReducer for complex state logic in React components
Implement proper state initialization in React components
Use proper state updates with callbacks in React components
Implement proper state cleanup in React components
Use Context API for theme/authentication state management
Implement proper state persistence in React applications
Use React.memo for expensive components
Implement proper useCallback for handlers in React components
Use proper useMemo for expensive computations in React components
Implement proper virtualization for lists in React components
Use proper code splitting with React.lazy in React applications
Implement proper cleanup in useEffect hooks
Use proper refs for DOM access in React components
Implement proper event listener cleanup in React components
Use proper abort controllers for fetch in React components
Implement proper subscription cleanup in React components
Use proper HTML elements for semantic HTML in React components
Implement proper ARIA attributes for accessibility in React components
Use proper heading hierarchy in React components
Implement proper form labels in React components
Use proper button types in React components
Implement proper focus management for keyboard navigation in React components
Use proper keyboard shortcuts in React components
Implement proper tab order in React components
Use proper ...
Files:
packages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Implement type guards forunknowntypes using the patternfunction isType(value: unknown): value is Type
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details in classes
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like<T extends { id: string }>
Use utility types likeOmit,Partial, andPickfor data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Useconst assertionswithas constfor literal types
Usesatisfiesoperator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...
Files:
packages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsx
packages/*/package.json
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
packages/*/package.json: Packages should export TypeScript types alongside runtime code
Follow semantic versioning for all packagesAll packages must be published under @clerk namespace
packages/*/package.json: Framework packages should depend on@clerk/clerk-jsfor core functionality
@clerk/sharedshould be a common dependency for most packages in the monorepo
Files:
packages/upgrade/package.json
**/package.json
📄 CodeRabbit inference engine (.cursor/rules/global.mdc)
Use pnpm as the package manager for this monorepo
Files:
packages/upgrade/package.jsonpackages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/package.json
🧬 Code graph analysis (2)
packages/upgrade/src/runner.js (1)
packages/upgrade/src/codemods/index.js (2)
result(61-61)runCodemod(36-80)
packages/upgrade/src/cli.js (1)
packages/upgrade/scripts/generate-guide.js (2)
cli(12-32)cli(157-157)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (27)
- GitHub Check: Integration Tests (quickstart, chrome, 16)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 16)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 16, RQ)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (quickstart, chrome, 15)
- GitHub Check: Integration Tests (handshake:staging, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (sessions:staging, chrome)
- GitHub Check: Integration Tests (handshake, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (machine, chrome, RQ)
- GitHub Check: Integration Tests (billing, chrome, RQ)
- GitHub Check: Integration Tests (custom, chrome)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (12)
packages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/package.json (1)
1-9: LGTM! Test fixture package.json is well-structured.The fixture correctly represents a minimal Next.js 14 project with Clerk Next.js v6, appropriate for testing upgrade scenarios.
packages/upgrade/src/__tests__/fixtures/nextjs-v6-scan-issues/src/app.tsx (3)
3-15: Verify: Are missing TypeScript types intentional for this test fixture?The
Appcomponent is missing TypeScript type annotations for props and return type, which violates coding guidelines. Given this is in ascan-issuesfixture directory, these may be intentional to test the scanner's detection capabilities.If intentional: No action needed.
If not intentional: Add proper types.As per coding guidelines, components should have explicit types:
+import type { ReactNode } from 'react'; + -export default function App({ children }) { +export default function App({ children }: { children: ReactNode }): JSX.Element { return ( <ClerkProvider
17-24: Verify: Is the missing return type intentional?The
SignInPagecomponent lacks an explicit return type annotation, which is required per coding guidelines. This may be intentional for testing scanner behavior.If not intentional, add the return type:
-export function SignInPage() { +export function SignInPage(): JSX.Element { return (
26-30: Verify: Are the unused variable and incomplete implementation intentional?This component has several potential issues:
isSignedInis extracted but never used- The comment suggests missing SAML callback logic
- Missing return type annotation
Given this is in a
scan-issuesfixture, these may be intentional to test the upgrade scanner's detection capabilities.If not intentional, consider:
-export function SamlCallback() { +export function SamlCallback(): JSX.Element { const { isSignedIn } = useAuth(); - // Handle saml callback - return <div>SAML SSO Callback</div>; + + if (!isSignedIn) { + return <div>Authenticating...</div>; + } + + return <div>SAML SSO Callback - Authenticated</div>; }packages/upgrade/src/runner.js (1)
40-46: LGTM! Variable rename improves clarity.The variable rename from
globtopatternsaligns with the parameter name inrunCodemod(as shown incodemods/index.jsline 35), making the code more consistent and easier to follow.packages/upgrade/src/cli.js (2)
57-57: LGTM! ThedryRunflag is properly integrated.The flag is correctly defined, added to the options object, and used throughout the upgrade flow (warning display at line 81-84, and in
performUpgradeat line 182-189).Also applies to: 73-73
63-63: LGTM! TheskipUpgradeflag is properly integrated.The flag is correctly defined, added to the options object, and used in the upgrade flow at line 149 to skip the package upgrade step.
Also applies to: 78-78
packages/upgrade/package.json (1)
24-24: LGTM! Script addition follows established patterns.The new
generate-guidescript is correctly defined and points to the corresponding script file introduced in this PR.packages/upgrade/scripts/generate-guide.js (4)
1-32: LGTM! CLI setup is well-structured.The script correctly sets up the CLI with clear usage examples and properly requires both
versionandsdkflags.
81-102: LGTM! Helper functions are well-implemented.Both
groupByCategoryandgetCategoryHeadinghave clear logic and appropriate fallback behavior.
104-154: LGTM! Markdown generation logic is well-structured.The function correctly handles category ordering with both predefined categories (breaking, deprecation-removal, warning) and any additional categories. The fallback for
versionNameis reasonable.
156-174: LGTM! Main function has appropriate error handling.The orchestration logic is clear, error handling is suitable for a CLI script, and outputting to stdout enables flexible usage (e.g., piping to files as shown in the usage examples).
| for (const file of files) { | ||
| const filePath = path.join(changesDir, file); | ||
| const content = fs.readFileSync(filePath, 'utf8'); | ||
| const parsed = matter(content); | ||
| const fm = parsed.data; | ||
|
|
||
| const packages = fm.packages || ['*']; | ||
| const appliesToSdk = packages.includes('*') || packages.includes(sdk); | ||
|
|
||
| if (!appliesToSdk) { | ||
| continue; | ||
| } | ||
|
|
||
| changes.push({ | ||
| title: fm.title, | ||
| packages, | ||
| category: fm.category || 'breaking', | ||
| content: parsed.content.trim(), | ||
| slug: file.replace('.md', ''), | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate required frontmatter fields.
The code doesn't validate that fm.title exists before using it. If a markdown file is missing the title field in its frontmatter, the generated output will contain "### undefined" (see line 129 where change.title is used).
Apply this fix to validate required fields:
for (const file of files) {
const filePath = path.join(changesDir, file);
const content = fs.readFileSync(filePath, 'utf8');
const parsed = matter(content);
const fm = parsed.data;
+
+ if (!fm.title) {
+ console.warn(`Warning: ${file} is missing a title field, skipping`);
+ continue;
+ }
const packages = fm.packages || ['*'];
const appliesToSdk = packages.includes('*') || packages.includes(sdk);🤖 Prompt for AI Agents
In packages/upgrade/scripts/generate-guide.js around lines 56 to 76, the code
reads frontmatter but doesn't validate required fields like title; add a check
after reading fm to ensure fm.title exists and is non-empty — if missing, either
log a clear error/warning with the file path and skip that file (continue) or
throw an Error to fail the build; update changes.push to only run when the
required fields are present so generated guides never contain "undefined"
titles.
Description
This builds on #7386.
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
New Features
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.