Skip to content
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

Disable devtools #383

Merged
merged 1 commit into from
Oct 25, 2024
Merged

Disable devtools #383

merged 1 commit into from
Oct 25, 2024

Conversation

hackerwins
Copy link
Member

@hackerwins hackerwins commented Oct 25, 2024

What this PR does / why we need it:

Disable devtools

This commit temporarily disabled Devtools for performance testing.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced linting process for frontend and backend changes during commits, improving error handling and control flow.
  • Improvements

    • Modified the createYorkieDocument function to disable development tools, potentially impacting debugging capabilities.

Copy link
Contributor

coderabbitai bot commented Oct 25, 2024

Walkthrough

The pull request modifies the .husky/pre-commit script to improve the linting process for frontend and backend changes by introducing flags to detect modifications in respective directories. It executes linting commands based on these flags and handles errors accordingly. Additionally, the createYorkieDocument function in the useYorkieDocument hook is updated to disable the enableDevtools option in the Yorkie document instantiation, affecting debugging capabilities while maintaining existing logic and error handling.

Changes

File Change Summary
.husky/pre-commit Enhanced linting process by introducing LINT_FRONTEND and LINT_BACKEND flags to detect changes, executing npx lint-staged for respective directories, and improving error handling. Corrected formatting issue in backend section.
frontend/src/hooks/useYorkieDocument.ts Modified createYorkieDocument function to set enableDevtools option to false, impacting debugging tools during the document's lifecycle while preserving existing logic.

Possibly related PRs

Poem

🐰 In the burrow, changes bloom,
Linting now clears all the gloom.
Frontend, backend, flags in tow,
Errors caught, the code will flow.
Yorkie's doc, devtools take a rest,
Hopping forward, we code our best! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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: 0

🧹 Outside diff range and nitpick comments (4)
.husky/pre-commit (3)

Line range hint 13-21: Add safeguards for directory navigation

The current implementation assumes the script is run from the repository root. This could fail if the hook is triggered from a different working directory.

Consider adding these safety measures:

 if [ "$LINT_FRONTEND" = true ]; then
   echo "Changes detected in the frontend. Linting & Formatting frontend..."
-  cd frontend
+  if [ ! -d "frontend" ]; then
+    echo "Error: frontend directory not found. Are you in the repository root?"
+    exit 1
+  fi
+  pushd frontend > /dev/null || exit 1
   npx lint-staged
   if [ $? -ne 0 ]; then
     echo "Frontend Linting & Formatting failed. Commit aborted."
     exit 1
   fi
-  cd ..
+  popd > /dev/null
 fi

Line range hint 23-34: Improve error handling and shell script practices

Several improvements can be made to make the script more robust and maintainable.

Consider these enhancements:

 if [ "$LINT_BACKEND" = true ]; then
  echo "Changes detected in the backend. Linting & Formatting backend..."
-  cd backend
+  if [ ! -d "backend" ]; then
+    echo "Error: backend directory not found. Are you in the repository root?"
+    exit 1
+  fi
+  pushd backend > /dev/null || exit 1
   npx lint-staged
-  if [ $? -ne 0 ]; then
+  LINT_EXIT_CODE=$?
+  popd > /dev/null
+  if [ $LINT_EXIT_CODE -ne 0 ]; then
     echo "Backend Linting & Formatting failed. Commit aborted."
     exit 1
   fi
-  cd ..
- fi
+ fi

Note: The indentation of the closing fi has been corrected.


Add checks for both package manager and lint-staged configuration

The verification reveals several important points:

  • Both frontend and backend have lint-staged configurations that use pnpm commands
  • The project uses pnpm as the package manager (evidenced by root pnpm-lock.yaml)
  • The pre-commit hook uses npx which may not work correctly with pnpm

Consider this revised version:

+# Check for required commands
+command -v pnpm >/dev/null 2>&1 || { echo "Error: pnpm is required but not installed."; exit 1; }
+
+# Verify lint-staged configurations exist
+[ ! -f "frontend/package.json" ] && { echo "Error: frontend/package.json not found"; exit 1; }
+[ ! -f "backend/package.json" ] && { echo "Error: backend/package.json not found"; exit 1; }
+
 CHANGED_FILES=$(git diff --cached --name-only)
...
 if [ "$LINT_FRONTEND" = true ]; then
   echo "Changes detected in the frontend. Linting & Formatting frontend..."
   cd frontend
-  npx lint-staged
+  pnpm exec lint-staged
   if [ $? -ne 0 ]; then
...
 if [ "$LINT_BACKEND" = true ]; then
   echo "Changes detected in the backend. Linting & Formatting backend..."
   cd backend
-  npx lint-staged
+  pnpm exec lint-staged
   if [ $? -ne 0 ]; then
🔗 Analysis chain

Line range hint 1-34: Consider adding error handling for npx commands

The script assumes npx is available and lint-staged is properly configured in both directories.

Let's verify the presence of necessary configuration:

Consider adding checks for the required tools:

+# Check for required commands
+command -v npx >/dev/null 2>&1 || { echo "Error: npx is required but not installed."; exit 1; }
+
 CHANGED_FILES=$(git diff --cached --name-only)

Let me verify if pnpm is being used in the project by checking the lockfiles and package manager configuration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify lint-staged configuration in both directories

echo "Checking for lint-staged configuration..."
for dir in frontend backend; do
  if [ -f "${dir}/package.json" ]; then
    echo "=== ${dir}/package.json lint-staged config ==="
    jq '.["lint-staged"]' "${dir}/package.json"
  else
    echo "Warning: ${dir}/package.json not found"
  fi
done

Length of output: 662


Script:

#!/bin/bash
# Check for package manager configuration and lockfiles
echo "=== Checking for package manager files ==="
ls -la pnpm-lock.yaml package-lock.json yarn.lock 2>/dev/null || true

echo -e "\n=== Checking frontend directory ==="
ls -la frontend/pnpm-lock.yaml frontend/package-lock.json frontend/yarn.lock 2>/dev/null || true

echo -e "\n=== Checking backend directory ==="
ls -la backend/pnpm-lock.yaml backend/package-lock.json backend/yarn.lock 2>/dev/null || true

echo -e "\n=== Checking for .npmrc ==="
find . -name ".npmrc" -type f -exec cat {} \;

Length of output: 680

frontend/src/hooks/useYorkieDocument.ts (1)

44-44: Consider making devtools configuration environment-dependent.

While disabling devtools aligns with the PR objective, consider making this configuration environment-dependent to maintain debugging capabilities during development.

You could use environment variables to control this setting:

->(yorkieDocumentId, { enableDevtools: false });
+>(yorkieDocumentId, { 
+  enableDevtools: import.meta.env.DEV || import.meta.env.MODE === 'development'
+});

This way, devtools would be:

  • Enabled in development for better debugging
  • Disabled in production for security and performance
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between eda0444 and dfa2450.

📒 Files selected for processing (2)
  • .husky/pre-commit (1 hunks)
  • frontend/src/hooks/useYorkieDocument.ts (1 hunks)
🔇 Additional comments (1)
.husky/pre-commit (1)

Line range hint 1-11: LGTM: File change detection logic is sound

The implementation correctly detects changes in frontend and backend directories using git diff and regex matching.

@devleejb devleejb merged commit f45c03d into main Oct 25, 2024
2 checks passed
@devleejb devleejb deleted the disable-devtools branch October 25, 2024 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants