Skip to content

Conversation

dstaley
Copy link
Member

@dstaley dstaley commented Jun 24, 2025

Description

This PR adds a warning when Turbopack usage has been detected during clerk-dev setup, and logs the correct value to set for outputFileTracingRoot.

Screenshot 2025-06-24 at 3 02 36 PM

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features

    • Added a warning message to alert users when Turbopack is detected in the development script, guiding them to set the appropriate configuration for output file tracing.
  • Bug Fixes

    • Improved framework detection and dependency handling for more reliable setup and watch commands.
  • Chores

    • Updated internal utilities for reading package information to enhance consistency and maintainability.

@dstaley dstaley requested a review from a team June 24, 2025 22:02
Copy link

changeset-bot bot commented Jun 24, 2025

🦋 Changeset detected

Latest commit: ad9684d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clerk/dev-cli Patch

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

Copy link

vercel bot commented Jun 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2025 10:02pm

Copy link
Contributor

coderabbitai bot commented Jun 24, 2025

📝 Walkthrough

Walkthrough

A new changeset was added to document a patch update for the @clerk/dev-cli package, specifically noting a new warning message related to Turbopack usage. The detectFramework function in the setup command was refactored to be synchronous and now takes a package.json object as input. A new asynchronous utility, getOutputFileTracingRoot, was introduced to help with Turbopack configuration. The codebase replaced the old getDependencies utility with a new getPackageJSON function, which reads and parses the entire package.json file. The old getDependencies utility was removed. The watch command was updated to use the new utility accordingly.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/dev-cli/src/commands/setup.js (1)

62-90: Consider simplifying the path resolution logic.

The getOutputFileTracingRoot function works correctly but is quite complex. Consider using Node.js built-in utilities for better readability and maintainability.

 async function getOutputFileTracingRoot() {
   const monorepoRoot = await getMonorepoRoot();
   if (!monorepoRoot) {
     throw new Error(NULL_ROOT_ERROR);
   }
-  const p1 = path.resolve(monorepoRoot);
-  const p2 = path.resolve(process.cwd());
-
-  const root1 = path.parse(p1).root;
-  const root2 = path.parse(p2).root;
-
-  if (root1 !== root2) return null;
-
-  const parts1 = p1.slice(root1.length).split(path.sep);
-  const parts2 = p2.slice(root2.length).split(path.sep);
-
-  const len = Math.min(parts1.length, parts2.length);
-  const common = [];
-  for (let i = 0; i < len; i++) {
-    if (parts1[i] === parts2[i]) common.push(parts1[i]);
-    else break;
-  }
-
-  return common.length ? path.join(root1, ...common) : root1;
+  
+  const resolved1 = path.resolve(monorepoRoot);
+  const resolved2 = path.resolve(process.cwd());
+  
+  // Find common path using path.relative and checking if it goes up
+  const relative = path.relative(resolved1, resolved2);
+  if (relative.startsWith('..')) {
+    // Current dir is not within monorepo root, find common ancestor
+    const relative2 = path.relative(resolved2, resolved1);
+    if (relative2.startsWith('..')) {
+      // Both paths have different roots, find lowest common denominator
+      return path.dirname(path.resolve(resolved1, relative.split(path.sep).filter(p => p === '..').map(() => '..').join(path.sep)));
+    }
+  }
+  
+  return resolved1;
 }

Or consider using a well-tested library like find-common-dir if available in the project dependencies.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1be1fe and ad9684d.

📒 Files selected for processing (5)
  • .changeset/easy-papers-hug.md (1 hunks)
  • packages/dev-cli/src/commands/setup.js (6 hunks)
  • packages/dev-cli/src/commands/watch.js (2 hunks)
  • packages/dev-cli/src/utils/getDependencies.js (0 hunks)
  • packages/dev-cli/src/utils/getPackageJSON.js (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/dev-cli/src/utils/getDependencies.js
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.{js,ts,tsx,jsx}`: All code must pass ESLint checks with the project's configuration. Use Prettier for consistent code formatting.

**/*.{js,ts,tsx,jsx}: All code must pass ESLint checks with the project's configuration.
Use Prettier for consistent code formatting.

  • packages/dev-cli/src/commands/watch.js
  • packages/dev-cli/src/utils/getPackageJSON.js
  • packages/dev-cli/src/commands/setup.js
`packages/**`: All publishable packages under the @clerk namespace must be located in the packages/ directory.

packages/**: All publishable packages under the @clerk namespace must be located in the packages/ directory.

  • packages/dev-cli/src/commands/watch.js
  • packages/dev-cli/src/utils/getPackageJSON.js
  • packages/dev-cli/src/commands/setup.js
🪛 Biome (1.9.4)
packages/dev-cli/src/commands/setup.js

[error] 254-254: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
.changeset/easy-papers-hug.md (1)

1-6: LGTM!

The changeset properly documents the patch update with a clear description of the new Turbopack warning functionality.

packages/dev-cli/src/commands/watch.js (1)

8-8: LGTM!

The refactor to use getPackageJSON instead of the removed getDependencies utility is clean and maintains the same functionality.

Also applies to: 17-17

packages/dev-cli/src/commands/setup.js (3)

39-43: Excellent refactoring of detectFramework to be synchronous.

Making detectFramework synchronous and accepting a pkgJSON parameter improves testability and follows the single responsibility principle. The function is now pure and easier to reason about.


254-259: LGTM! Excellent implementation of Turbopack detection and warning.

The logic correctly detects Turbopack usage in the Next.js dev script and provides a helpful warning with the computed outputFileTracingRoot value. This addresses the PR objectives perfectly.


195-195: LGTM!

The update to use getPackageJSON instead of getDependencies maintains the same functionality while using the new centralized utility.

Comment on lines +8 to +11
export async function getPackageJSON(pathToPackageJSON) {
const packageJSON = await readFile(pathToPackageJSON, 'utf-8');
return JSON.parse(packageJSON);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for file operations and JSON parsing.

The function lacks error handling for common failure scenarios such as file not found or invalid JSON syntax. Consider adding try-catch blocks to provide more meaningful error messages.

 export async function getPackageJSON(pathToPackageJSON) {
-  const packageJSON = await readFile(pathToPackageJSON, 'utf-8');
-  return JSON.parse(packageJSON);
+  try {
+    const packageJSON = await readFile(pathToPackageJSON, 'utf-8');
+    return JSON.parse(packageJSON);
+  } catch (error) {
+    if (error.code === 'ENOENT') {
+      throw new Error(`package.json not found at: ${pathToPackageJSON}`);
+    }
+    if (error instanceof SyntaxError) {
+      throw new Error(`Invalid JSON in package.json at: ${pathToPackageJSON}`);
+    }
+    throw error;
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function getPackageJSON(pathToPackageJSON) {
const packageJSON = await readFile(pathToPackageJSON, 'utf-8');
return JSON.parse(packageJSON);
}
export async function getPackageJSON(pathToPackageJSON) {
try {
const packageJSON = await readFile(pathToPackageJSON, 'utf-8');
return JSON.parse(packageJSON);
} catch (error) {
if (error.code === 'ENOENT') {
throw new Error(`package.json not found at: ${pathToPackageJSON}`);
}
if (error instanceof SyntaxError) {
throw new Error(`Invalid JSON in package.json at: ${pathToPackageJSON}`);
}
throw error;
}
}
🤖 Prompt for AI Agents
In packages/dev-cli/src/utils/getPackageJSON.js around lines 8 to 11, the
function getPackageJSON lacks error handling for file reading and JSON parsing
failures. Wrap the file reading and JSON.parse calls in a try-catch block, and
in the catch block, throw or log a meaningful error message indicating whether
the failure was due to file access issues or invalid JSON syntax.

@@ -217,6 +250,13 @@ export async function setup({ js = true, skipInstall = false }) {
CLERK_SECRET_KEY: instance.secretKey,
...(js ? { NEXT_PUBLIC_CLERK_JS_URL: 'http://localhost:4000/npm/clerk.browser.js' } : {}),
});

if (pkgJSON.scripts?.dev && pkgJSON.scripts.dev.includes('--turbo')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix optional chaining as suggested by static analysis.

The static analysis tool correctly identified that pkgJSON.scripts.dev should use optional chaining to prevent potential runtime errors when scripts is undefined.

-      if (pkgJSON.scripts?.dev && pkgJSON.scripts.dev.includes('--turbo')) {
+      if (pkgJSON.scripts?.dev?.includes('--turbo')) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (pkgJSON.scripts?.dev && pkgJSON.scripts.dev.includes('--turbo')) {
if (pkgJSON.scripts?.dev?.includes('--turbo')) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 254-254: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🤖 Prompt for AI Agents
In packages/dev-cli/src/commands/setup.js at line 254, the code accesses
pkgJSON.scripts.dev without optional chaining, which can cause runtime errors if
scripts is undefined. Update the condition to use optional chaining on scripts
as well, changing pkgJSON.scripts.dev to pkgJSON.scripts?.dev to safely handle
cases where scripts might be undefined.

Copy link

pkg-pr-new bot commented Jun 24, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6189

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6189

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6189

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6189

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6189

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6189

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6189

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6189

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6189

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6189

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6189

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6189

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6189

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6189

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6189

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6189

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6189

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6189

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6189

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6189

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6189

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6189

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6189

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6189

commit: ad9684d

@dstaley dstaley merged commit d8f2b5c into main Jun 25, 2025
92 of 94 checks passed
@dstaley dstaley deleted the ds.fix/warn-turbopack branch June 25, 2025 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants