Skip to content

chore(repo): Run format through turbo #6291

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

Merged
merged 7 commits into from
Jul 24, 2025
Merged

Conversation

jacekradko
Copy link
Member

@jacekradko jacekradko commented Jul 11, 2025

Description

The primary goal here is to speed up formatting of the repo code by only running the prettier commands on changed packages, instead of all of the non-ignored files in the repo. The total time of formatting the whole repo is about 15 seconds. Executed multiple times a day every day...

Fixes: USER-2409

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

  • Chores
    • Updated formatting configuration by removing the old Prettier config file and introducing a new one.
    • Revised formatting scripts across all packages to use unified commands for formatting and format checking.
    • Added new scripts for formatting and format verification to all package workspaces.
    • Updated ignore patterns for formatting tools.
    • Introduced new scripts to handle formatting of non-workspace files.
    • Enhanced task configuration to ensure consistent formatting and checking across the project.

Copy link

changeset-bot bot commented Jul 11, 2025

🦋 Changeset detected

Latest commit: c9bfd67

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

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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 Jul 11, 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 Jul 24, 2025 3:16pm

@jacekradko jacekradko marked this pull request as ready for review July 24, 2025 15:06
Copy link

pkg-pr-new bot commented Jul 24, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: c9bfd67

Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

📝 Walkthrough

Walkthrough

This change restructures the project's code formatting workflow. The .prettierrc file is removed and replaced with a new prettier.config.mjs module for Prettier configuration. The .prettierignore file is updated to refine ignored patterns. Formatting scripts in the root and all package-level package.json files are updated or added to use new Node.js scripts (scripts/format-package.mjs and scripts/format-non-workspace.mjs) for running Prettier, with support for both formatting and format-checking modes. The root formatting scripts now use Turbo tasks, and turbo.json is updated to define and align formatting-related tasks and their input patterns. Minor cleanup is performed in an unrelated script.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Complexity: Moderate. The changes span configuration, scripting, and task orchestration, but do not alter core application logic or exported entities.
  • Scope: Affects multiple files across the monorepo, including root and package-level configuration, new scripts, and CI/task definitions.
  • Review time: Estimated at 20 minutes for a thorough review of scripting correctness, configuration alignment, and consistency across the monorepo.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7b596ea and c9bfd67.

📒 Files selected for processing (1)
  • .changeset/five-birds-cheer.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/five-birds-cheer.md
⏰ 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). (5)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)

🪧 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: 1

🔭 Outside diff range comments (1)
scripts/format-non-workspace.mjs (1)

1-91: Add tests to cover the script functionality.

According to the coding guidelines, tests should be added to cover changes. This script performs important build automation functionality and would benefit from testing.

Consider adding tests for:

  • getExistingFiles() function with various file patterns
  • formatNonWorkspaceFiles() function with different command-line arguments
  • Error handling scenarios
  • Integration tests for the complete formatting workflow

The tests could be placed in a scripts/__tests__/ directory or similar location.

🧹 Nitpick comments (5)
scripts/1password-keys.mjs (1)

23-25: Do not silently swallow 1Password CLI errors

Removing the err parameter prevents any diagnostics from being surfaced if op read fails for reasons other than a non-zero exit code. Swallowing those details can turn debugging into guesswork.

-  .catch(() => {
-    return null;
-  });
+  .catch(err => {
+    // Log once at debug level – keeps CI output clean but preserves the evidence.
+    console.debug('op read failed:', err?.stderr ?? err);
+    return null;
+  });

Duplicating this change for both reads maintains parity.

No tests exercise this script; consider a small integration test that mocks op and asserts that the script propagates non-zero exit codes / stderr correctly.

Also applies to: 35-37

.prettierignore (1)

11-14: Tests for the new formatting workflow are missing

None of the changes that introduce scripts/format-package.mjs are covered by tests. A minimal check (e.g. spawning the script in --check mode against a fixture) would prevent regressions.

Happy to scaffold a Jest test harness that exercises the formatter end-to-end if helpful.

packages/localizations/package.json (1)

103-105: Consider re-using the new formatter inside the existing “generate” script
You already added the package-level format/format:check scripts, but the “generate” task still calls Prettier directly. Switching to the new formatter keeps one single point of truth:

-    "generate": "tsc src/utils/generate.ts && node src/utils/generate.js && prettier --write src/*.ts",
+    "generate": "tsc src/utils/generate.ts && node src/utils/generate.js && pnpm run format",

Optional, but it avoids diverging CLI flags/config in the future.

scripts/format-package.mjs (1)

7-9: Consider adding --cache flag for consistency.

The script uses --cache only in check mode but not in write mode. For consistency and performance, consider adding --cache to both modes.

  const baseArgs = isCheck
-    ? ['prettier', '--cache', '--check', '--ignore-path', '../../.prettierignore']
-    : ['prettier', '--write', '--ignore-path', '../../.prettierignore'];
+    ? ['prettier', '--cache', '--check', '--ignore-path', '../../.prettierignore']
+    : ['prettier', '--cache', '--write', '--ignore-path', '../../.prettierignore'];

This aligns with the pattern used in scripts/format-non-workspace.mjs where --cache is used in both modes.

scripts/format-non-workspace.mjs (1)

90-90: Ensure proper exit code for unhandled errors.

While the main function handles most errors internally, consider ensuring proper exit code for any unhandled errors at the top level.

-formatNonWorkspaceFiles().catch(console.error);
+formatNonWorkspaceFiles().catch((error) => {
+  console.error(error);
+  process.exit(1);
+});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cfa7882 and 7b596ea.

📒 Files selected for processing (32)
  • .prettierignore (1 hunks)
  • .prettierrc (0 hunks)
  • package.json (1 hunks)
  • packages/agent-toolkit/package.json (1 hunks)
  • packages/astro/package.json (1 hunks)
  • packages/backend/package.json (1 hunks)
  • packages/chrome-extension/package.json (1 hunks)
  • packages/clerk-js/package.json (1 hunks)
  • packages/dev-cli/package.json (1 hunks)
  • packages/elements/package.json (1 hunks)
  • packages/expo-passkeys/package.json (1 hunks)
  • packages/expo/package.json (1 hunks)
  • packages/express/package.json (1 hunks)
  • packages/fastify/package.json (1 hunks)
  • packages/localizations/package.json (1 hunks)
  • packages/nextjs/package.json (1 hunks)
  • packages/nuxt/package.json (1 hunks)
  • packages/react-router/package.json (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/remix/package.json (1 hunks)
  • packages/shared/package.json (1 hunks)
  • packages/tanstack-react-start/package.json (1 hunks)
  • packages/testing/package.json (1 hunks)
  • packages/themes/package.json (1 hunks)
  • packages/types/package.json (1 hunks)
  • packages/upgrade/package.json (1 hunks)
  • packages/vue/package.json (1 hunks)
  • prettier.config.mjs (1 hunks)
  • scripts/1password-keys.mjs (3 hunks)
  • scripts/format-non-workspace.mjs (1 hunks)
  • scripts/format-package.mjs (1 hunks)
  • turbo.json (1 hunks)
💤 Files with no reviewable changes (1)
  • .prettierrc
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/remix/package.json
  • packages/chrome-extension/package.json
  • packages/express/package.json
  • packages/elements/package.json
  • packages/fastify/package.json
  • packages/agent-toolkit/package.json
  • packages/tanstack-react-start/package.json
  • packages/clerk-js/package.json
  • packages/dev-cli/package.json
  • packages/backend/package.json
  • packages/nuxt/package.json
  • packages/expo-passkeys/package.json
  • package.json
  • packages/astro/package.json
  • packages/testing/package.json
  • packages/upgrade/package.json
  • packages/expo/package.json
  • packages/nextjs/package.json
  • packages/localizations/package.json
  • packages/vue/package.json
  • turbo.json
  • packages/react-router/package.json
  • packages/react/package.json
  • packages/themes/package.json
  • packages/types/package.json
  • packages/shared/package.json
packages/*/package.json

📄 CodeRabbit Inference Engine (.cursor/rules/global.mdc)

All publishable packages should be placed under the packages/ directory

packages/*/package.json: All publishable packages must be located in the 'packages/' directory.
All packages must be published under the @clerk namespace on npm.
Semantic versioning must be used across all packages.

Files:

  • packages/remix/package.json
  • packages/chrome-extension/package.json
  • packages/express/package.json
  • packages/elements/package.json
  • packages/fastify/package.json
  • packages/agent-toolkit/package.json
  • packages/tanstack-react-start/package.json
  • packages/clerk-js/package.json
  • packages/dev-cli/package.json
  • packages/backend/package.json
  • packages/nuxt/package.json
  • packages/expo-passkeys/package.json
  • packages/astro/package.json
  • packages/testing/package.json
  • packages/upgrade/package.json
  • packages/expo/package.json
  • packages/nextjs/package.json
  • packages/localizations/package.json
  • packages/vue/package.json
  • packages/react-router/package.json
  • packages/react/package.json
  • packages/themes/package.json
  • packages/types/package.json
  • packages/shared/package.json
**/*

⚙️ CodeRabbit Configuration File

**/*: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Whenever reviewing a pull request, if there are any changes that could impact security, always tag @clerk/security in the PR.

Security-impacting changes include, but are not limited to:

  • Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
  • Any modification to access control, authorization checks, or role-based permissions
  • Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
  • Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
  • Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
  • Modifications to security headers, cookie flags, CORS policies, or CSRF protections
  • Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
  • Changes to rate limiting, abuse prevention, or input validation

If you're unsure whether a change is security-relevant, err on the side of caution and tag @clerk/security.

Any time that you tag @clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.

Files:

  • packages/remix/package.json
  • packages/chrome-extension/package.json
  • packages/express/package.json
  • packages/elements/package.json
  • packages/fastify/package.json
  • packages/agent-toolkit/package.json
  • packages/tanstack-react-start/package.json
  • packages/clerk-js/package.json
  • packages/dev-cli/package.json
  • packages/backend/package.json
  • packages/nuxt/package.json
  • packages/expo-passkeys/package.json
  • package.json
  • packages/astro/package.json
  • packages/testing/package.json
  • scripts/format-non-workspace.mjs
  • prettier.config.mjs
  • packages/upgrade/package.json
  • packages/expo/package.json
  • scripts/1password-keys.mjs
  • packages/nextjs/package.json
  • packages/localizations/package.json
  • packages/vue/package.json
  • turbo.json
  • packages/react-router/package.json
  • packages/react/package.json
  • packages/themes/package.json
  • packages/types/package.json
  • packages/shared/package.json
  • scripts/format-package.mjs
scripts/**

📄 CodeRabbit Inference Engine (.cursor/rules/global.mdc)

Build automation and utility scripts should be placed under the scripts/ directory

Files:

  • scripts/format-non-workspace.mjs
  • scripts/1password-keys.mjs
  • scripts/format-package.mjs
scripts/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Build and automation scripts must be located in the 'scripts/' directory.

Files:

  • scripts/format-non-workspace.mjs
  • scripts/1password-keys.mjs
  • scripts/format-package.mjs
packages/localizations/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Localization files must be placed in 'packages/localizations/'.

Files:

  • packages/localizations/package.json
🧬 Code Graph Analysis (1)
scripts/format-package.mjs (2)
scripts/format-non-workspace.mjs (2)
  • isCheck (53-53)
  • baseArgs (55-57)
scripts/notify.mjs (1)
  • process (6-6)
⏰ 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). (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 (30)
.prettierignore (1)

11-14: LGTM – sensible ignore additions

Adding *.map, *.min.js, and *.bundle.js keeps Prettier from wasting cycles on generated artefacts, and the duplicate coverage entry is gone. ✅

packages/clerk-js/package.json (1)

47-48: Formatting scripts added – looks good

The package now delegates to the shared formatter, ensuring consistent behaviour across the monorepo.

packages/remix/package.json (1)

70-71: Formatting scripts added – looks good

Consistent with other packages and the new tooling.

packages/elements/package.json (1)

66-67: Formatting scripts added – looks good

Brings the package in line with the monorepo-wide formatting workflow.

packages/backend/package.json (1)

96-97: Formatting scripts added – LGTM

The format and format:check scripts correctly point two levels up to the shared scripts/format-package.mjs, ensuring package-local formatting is now unified with the monorepo’s new workflow. No issues spotted.

packages/fastify/package.json (1)

58-60: Consistent formatting workflow – looks good

These new scripts mirror the pattern adopted across the repo and resolve to the root formatter without hard-coding Prettier flags in each package. No action needed.

packages/agent-toolkit/package.json (1)

42-44: Unified format scripts – approved

Scripts are correctly wired to the shared formatter, keeping the package in sync with monorepo conventions. Implementation is sound.

packages/express/package.json (1)

60-61: Format commands added – looks correct

The relative path resolves cleanly from packages/express, and the separation between write and check modes matches other packages. All good.

packages/chrome-extension/package.json (1)

41-42: Formatting integration – no concerns

format / format:check scripts align with the new monorepo standard; pathing and flags are correct. ✅

packages/themes/package.json (1)

37-38: Add standardized format/format:check scripts – looks correct

The relative path (../../scripts/format-package.mjs) resolves correctly from packages/themes, and the flags mirror the convention adopted across the repo. No further action needed.

packages/react-router/package.json (1)

75-76: Formatting scripts aligned with monorepo convention – good to merge

The added scripts are consistent with other workspaces and will pick up the centralized Prettier config. 👍

packages/upgrade/package.json (1)

22-23: Consistent formatting hooks added – LGTM

The format and format:check targets match the new tooling pipeline; no issues spotted.

packages/nuxt/package.json (1)

62-63: Uniform Prettier scripts – implementation correct

The invocation path and --check flag are accurate; integrates cleanly with the updated workflow.

packages/tanstack-react-start/package.json (1)

62-63: Formatting scripts added successfully

Scripts follow the shared pattern; confirms to monorepo standards.

packages/react/package.json (1)

82-83: Consistent formatting scripts added – LGTM

The new format and format:check scripts follow the convention adopted across the monorepo and correctly reference the shared scripts/format-package.mjs. No issues spotted.

packages/expo/package.json (1)

74-75: Formatting scripts align with monorepo convention

The added scripts are accurate and will resolve to the repo-root formatter from packages/expo. Looks good.

packages/vue/package.json (1)

51-52: Formatting scripts look correct

Pathing (../../) correctly reaches the repo root from packages/vue; nothing else to address.

packages/expo-passkeys/package.json (1)

28-29: LGTM – matches standardized formatter hook

No functional or structural issues detected with the added scripts.

packages/testing/package.json (1)

72-73: Formatter scripts added correctly

Scripts are consistent with the rest of the workspace and will keep package formatting in sync.

packages/dev-cli/package.json (1)

22-24: Consistent formatting hook added – looks good
Scripts correctly point two levels up to the shared scripts/format-package.mjs, matching the repo layout and keeping formatting logic DRY.

packages/shared/package.json (1)

134-136: Formatting scripts added – alignment with monorepo workflow
Path and flags match the new shared formatter; nothing else to flag.

packages/types/package.json (1)

37-39: Formatting scripts added – looks correct
The package inherits Node 18 which supports .mjs; scripts are consistent with the rest of the workspace.

packages/nextjs/package.json (1)

72-74: Formatting scripts integrated – all good
Correct relative path, consistent with other packages, no further action needed.

packages/astro/package.json (1)

83-84: LGTM! Consistent formatting script integration.

The new formatting scripts correctly reference the shared format-package.mjs script and follow the established pattern with the --check flag for format verification.

prettier.config.mjs (1)

1-12: Well-structured Prettier configuration.

The ESM configuration correctly exports standard Prettier options with appropriate plugins for the repository's needs. The settings are reasonable and consistent with modern formatting practices.

scripts/format-package.mjs (1)

11-21: Solid error handling and execution logic.

The script properly handles both success and error cases with appropriate logging and exit codes. The use of zx for command execution is clean and the relative path handling is correct.

package.json (1)

15-16: Well-designed two-phase formatting approach.

The updated scripts effectively split formatting responsibilities: Turbo handles workspace packages (with caching and parallelization), while the separate script handles non-workspace files. This should achieve the PR's goal of improved formatting performance.

turbo.json (1)

146-194: Comprehensive and well-structured turbo formatting tasks.

The new format task and updated format:check task have identical, comprehensive input patterns that appropriately cover all formattable file types while excluding generated files. Including the prettier configuration files in inputs ensures proper cache invalidation when formatting rules change.

scripts/format-non-workspace.mjs (2)

1-12: LGTM! Well-structured imports and file patterns.

The shebang, ESM imports, and file pattern definitions are correctly implemented. The patterns appropriately target root-level files and non-workspace directories while covering relevant file extensions for formatting.


52-88: Excellent implementation with comprehensive error handling.

The function is well-structured with:

  • Proper command-line argument parsing
  • Informative user feedback with appropriate messaging
  • Good error handling with proper exit codes
  • Helpful verbose output for debugging

The use of zx's $ template for command execution is appropriate and the prettier arguments are correctly configured for both check and write modes.

Comment on lines +14 to +50
async function getExistingFiles() {
const existingFiles = [];

for (const pattern of ROOT_FILE_PATTERNS) {
try {
const matches = await globby(pattern, {
ignore: ['node_modules/**', '**/node_modules/**', 'packages/**'],
});
existingFiles.push(...matches);
} catch {
// Pattern didn't match any files, skip it
}
}

for (const pattern of NON_WORKSPACE_PATTERNS) {
try {
const matches = await globby(pattern, {
ignore: [
'node_modules/**',
'**/node_modules/**',
'**/dist/**',
'**/build/**',
'**/coverage/**',
'**/.turbo/**',
'**/.next/**',
'**/.tsup/**',
'**/.cache/**',
],
});
existingFiles.push(...matches);
} catch {
// Pattern didn't match any files, skip it
}
}

return existingFiles.filter(Boolean);
}
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

Improve error handling specificity.

The try-catch blocks are too broad and will catch all errors, not just cases where patterns don't match files. This could hide legitimate errors like permission issues or invalid glob patterns.

Consider more specific error handling:

    try {
      const matches = await globby(pattern, {
        ignore: ['node_modules/**', '**/node_modules/**', 'packages/**'],
      });
      existingFiles.push(...matches);
-   } catch {
-     // Pattern didn't match any files, skip it
+   } catch (error) {
+     // Only skip if it's a pattern matching issue, otherwise re-throw
+     if (error.code !== 'ENOENT' && !error.message.includes('no matches')) {
+       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
async function getExistingFiles() {
const existingFiles = [];
for (const pattern of ROOT_FILE_PATTERNS) {
try {
const matches = await globby(pattern, {
ignore: ['node_modules/**', '**/node_modules/**', 'packages/**'],
});
existingFiles.push(...matches);
} catch {
// Pattern didn't match any files, skip it
}
}
for (const pattern of NON_WORKSPACE_PATTERNS) {
try {
const matches = await globby(pattern, {
ignore: [
'node_modules/**',
'**/node_modules/**',
'**/dist/**',
'**/build/**',
'**/coverage/**',
'**/.turbo/**',
'**/.next/**',
'**/.tsup/**',
'**/.cache/**',
],
});
existingFiles.push(...matches);
} catch {
// Pattern didn't match any files, skip it
}
}
return existingFiles.filter(Boolean);
}
async function getExistingFiles() {
const existingFiles = [];
for (const pattern of ROOT_FILE_PATTERNS) {
try {
const matches = await globby(pattern, {
ignore: ['node_modules/**', '**/node_modules/**', 'packages/**'],
});
existingFiles.push(...matches);
} catch (error) {
// Only skip if it's a pattern-matching issue, otherwise re-throw
if (error.code !== 'ENOENT' && !error.message.includes('no matches')) {
throw error;
}
}
}
for (const pattern of NON_WORKSPACE_PATTERNS) {
try {
const matches = await globby(pattern, {
ignore: [
'node_modules/**',
'**/node_modules/**',
'**/dist/**',
'**/build/**',
'**/coverage/**',
'**/.turbo/**',
'**/.next/**',
'**/.tsup/**',
'**/.cache/**',
],
});
existingFiles.push(...matches);
} catch {
// Pattern didn't match any files, skip it
}
}
return existingFiles.filter(Boolean);
}
🤖 Prompt for AI Agents
In scripts/format-non-workspace.mjs between lines 14 and 50, the current
try-catch blocks catch all errors broadly, which can mask real issues like
permission errors or invalid patterns. Refactor the error handling to catch only
the specific errors related to no matches found or handle the globby call
results without relying on exceptions for control flow. You can check if matches
are empty instead of using try-catch, or inspect error types before deciding to
ignore them, ensuring legitimate errors are not suppressed.

@jacekradko jacekradko changed the title chore/turbo-prettier chore(repo): run format through turbo Jul 24, 2025
@jacekradko jacekradko changed the title chore(repo): run format through turbo chore(repo): Run format through turbo Jul 24, 2025
@jacekradko jacekradko merged commit 0371fbd into main Jul 24, 2025
39 of 40 checks passed
@jacekradko jacekradko deleted the jr.chore/format-turbo branch July 24, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants