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

[Lexical][UI Gallery] Fix meta lexical website intern build errors #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

local-dev-korbit-ai-mentor[bot]
Copy link

@local-dev-korbit-ai-mentor local-dev-korbit-ai-mentor bot commented Aug 15, 2024

User description

WHAT

Fix meta lexical website intern build errors

  • Packages/APIs are not imported as is to "Meta Intern". Hence have lexical.dev external links for opening those from intern meta build for lexical website.
  • same for error codes, don't include this page in intern meta build

WHY

  • working on a prototype for UI Gallery which can work for both Intern/Extern Lexical Website

TEST

tested locally, everything works as is for Extern Lexical Website

Screenshot 2024-06-12 at 1 36 12 PM Screenshot 2024-06-12 at 1 43 51 PM

Description by Korbit AI

Note

This feature is in early access. You can enable or disable it in the Korbit Console.

What change is being made?

Fix meta lexical website internal build errors by conditionally requiring packagesManager and adjusting configurations based on the FB_INTERNAL environment variable.

Why are these changes being made?

The internal build process for the meta lexical website was failing due to the unconditional requirement of packagesManager. By making the inclusion of packagesManager and related configurations conditional, we ensure compatibility with both internal and external build environments.


PR Type

enhancement, bug fix


Description

  • Fixed internal build errors by conditionally requiring packagesManager and adjusting configurations based on the FB_INTERNAL environment variable.
  • Updated docusaurus.config.js to handle different configurations for internal and external builds, including entry points and plugins.
  • Modified sidebar configuration in sidebars.js to link to external documentation when building internally.
  • Ensured compatibility with both internal and external build environments by filtering out null plugins and adjusting API links.

Changes walkthrough 📝

Relevant files
Enhancement
docusaurus.config.js
Conditional configuration for internal and external builds

packages/lexical-website/docusaurus.config.js

  • Made packagesManager conditional based on FB_INTERNAL environment
    variable.
  • Adjusted entryPoints and plugins configuration for internal builds.
  • Filtered out null plugins from the configuration.
  • Updated API and error page handling based on build environment.
  • +48/-32 
    sidebars.js
    Conditional sidebar configuration for internal builds       

    packages/lexical-website/sidebars.js

  • Added conditional logic for 'Packages' sidebar based on FB_INTERNAL.
  • Linked to external documentation for internal builds.
  • +15/-9   

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Summary by CodeRabbit

    • New Features

      • Introduced conditional configurations for internal and external environments, enhancing the documentation experience.
      • Modified sidebar to dynamically link to an external documentation site based on user context.
    • Improvements

      • Enhanced flexibility of the Docusaurus setup to adapt based on the FB_INTERNAL environment variable, ensuring appropriate documentation access.

    Copy link
    Author

    Clone of the PR facebook/lexical#6300

    Copy link

    korbit-ai bot commented Aug 15, 2024

    My review is in progress 📖 - I will have feedback for you in a few minutes!

    Copy link

    coderabbitai bot commented Aug 15, 2024

    Walkthrough

    The recent changes enhance the Docusaurus configuration to support flexible documentation setups based on the FB_INTERNAL environment variable. This allows the application to switch between internal and external documentation modes seamlessly, impacting package management, sidebar links, and plugin configurations. The adjustments improve usability for different user contexts without requiring separate configurations, ensuring a more robust and dynamic documentation experience.

    Changes

    Files Change Summary
    packages/lexical-website/docusaurus.config.js Introduced conditional logic for FB_INTERNAL to adjust packagesManager, entry points, plugins, and API sidebar links, enhancing flexibility and usability.
    packages/lexical-website/sidebars.js Modified "Packages" sidebar entry to link externally if FB_INTERNAL is true, improving adaptability for different environments.

    Poem

    🐇 In the code where rabbits play,
    New paths of knowledge pave the way.
    With toggles bright, our docs align,
    For every user, a path divine!
    Jumping through changes, swift and spry,
    A hop to the future, oh my, oh my! 🌟


    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>.
      • 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 generate interesting stats about this repository and render them as a table.
      • @coderabbitai show all the console.log statements in this repository.
      • @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 as 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.

    Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

    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

    @korbit-ai korbit-ai bot left a comment

    Choose a reason for hiding this comment

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

    I have reviewed your code and found 1 potential issue.

    Comment on lines +16 to +18
    const {packagesManager} = process.env.FB_INTERNAL
    ? {}
    : require('../../scripts/shared/packagesManager');
    Copy link

    Choose a reason for hiding this comment

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

    category Functionality

    The current implementation uses a ternary operator to conditionally import the packagesManager based on the FB_INTERNAL environment variable. While this approach works, it might lead to potential issues if the FB_INTERNAL environment variable is not set correctly or if there are differences in the package structure between internal and external builds. Consider using a more robust method for handling environment-specific imports, such as dynamic imports or separate build configurations for internal and external environments. This will ensure that the correct packages are always imported regardless of the build environment.

    Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

    @furwellness
    Copy link
    Owner

    /review

    Copy link

    codiumai-pr-agent-free bot commented Aug 20, 2024

    PR Reviewer Guide 🔍

    (Review updated until commit 1fcc34e)

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Conditional Logic
    The PR introduces multiple conditional checks based on process.env.FB_INTERNAL. This might lead to different behavior between internal and external builds, potentially causing inconsistencies.

    Configuration Change
    The PR modifies the entryPoints configuration for TypeDoc. This change might affect the generated API documentation, potentially omitting some entries in the internal build.

    Navigation Change
    The PR alters the sidebar configuration, potentially changing the navigation structure of the documentation. This might affect user experience and accessibility.

    Copy link

    Persistent review updated to latest commit 1fcc34e

    @furwellness furwellness reopened this Aug 21, 2024
    @furwellness furwellness changed the base branch from cloned_main_25ba4 to main August 21, 2024 04:48
    Copy link

    Persistent review updated to latest commit 1fcc34e

    @furwellness
    Copy link
    Owner

    @coderabbitai full review

    Copy link

    coderabbitai bot commented Aug 21, 2024

    Actions performed

    Full review triggered.

    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Maintainability
    Extract complex conditional logic into a separate function

    Consider extracting the complex conditional logic for entryPoints into a separate
    function to improve readability and maintainability of the code.

    packages/lexical-website/docusaurus.config.js [175-188]

    -entryPoints: process.env.FB_INTERNAL
    -  ? []
    -  : packagesManager
    -      .getPublicPackages()
    -      .flatMap((pkg) =>
    -        pkg
    -          .getExportedNpmModuleEntries()
    -          .map((entry) => [
    -            path.relative(
    -              __dirname,
    -              pkg.resolve('src', entry.sourceFileName),
    -            ),
    -          ]),
    -      ),
    +entryPoints: getEntryPoints(),
     
    +// ... (elsewhere in the file)
    +
    +function getEntryPoints() {
    +  if (process.env.FB_INTERNAL) {
    +    return [];
    +  }
    +  return packagesManager
    +    .getPublicPackages()
    +    .flatMap((pkg) =>
    +      pkg
    +        .getExportedNpmModuleEntries()
    +        .map((entry) => [
    +          path.relative(
    +            __dirname,
    +            pkg.resolve('src', entry.sourceFileName),
    +          ),
    +        ]),
    +    );
    +}
    +
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Extracting the complex conditional logic into a separate function improves readability and maintainability by isolating the logic and reducing clutter in the main configuration object.

    8
    Enhancement
    Use object spread for conditional sidebar item configuration

    Consider using an object literal instead of a ternary operator for the conditional
    sidebar item to improve readability and maintainability.

    packages/lexical-website/sidebars.js [56-71]

    -process.env.FB_INTERNAL
    -  ? {
    -      href: 'https://lexical.dev/docs/packages/lexical',
    -      label: 'Packages',
    -      type: 'link',
    -    }
    -  : {
    -      items: [
    -        {
    -          dirName: 'packages',
    -          type: 'autogenerated',
    -        },
    -      ],
    -      label: 'Packages',
    -      type: 'category',
    -    },
    +{
    +  ...(process.env.FB_INTERNAL
    +    ? {
    +        href: 'https://lexical.dev/docs/packages/lexical',
    +        type: 'link',
    +      }
    +    : {
    +        items: [
    +          {
    +            dirName: 'packages',
    +            type: 'autogenerated',
    +          },
    +        ],
    +        type: 'category',
    +      }),
    +  label: 'Packages',
    +},
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using object spread syntax for conditional configuration improves readability by clearly separating common properties from conditional ones, making the code easier to understand and maintain.

    7

    Copy link

    @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

    Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between 4cbb85f and 1fcc34e.

    Files selected for processing (2)
    • packages/lexical-website/docusaurus.config.js (6 hunks)
    • packages/lexical-website/sidebars.js (1 hunks)
    Additional comments not posted (4)
    packages/lexical-website/sidebars.js (1)

    56-70: Verify the environment variable usage.

    Ensure that the FB_INTERNAL environment variable is set correctly in all environments to avoid misconfigurations in the sidebar.

    Run the following script to check where FB_INTERNAL is set or used in the codebase:

    packages/lexical-website/docusaurus.config.js (3)

    Line range hint 243-272: LGTM! Conditional plugin inclusion is handled well.

    The logic for conditionally including the package-docs plugin and filtering null values is correct.


    390-401: Verify the availability of the external API link.

    Ensure that the external API link (https://lexical.dev/docs/api/) is always available and correct when FB_INTERNAL is true.

    Run the following script to check the availability of the external API link:

    Verification successful

    External API link is available and functioning correctly.

    The external API link (https://lexical.dev/docs/api/) is accessible and returns a successful HTTP 200 status code when checked. This confirms that the link is correctly configured for the FB_INTERNAL condition.

    Scripts executed

    The following scripts were executed for the analysis:

    Script:

    #!/bin/bash
    # Description: Verify the availability of the external API link.
    
    # Test: Check the HTTP status of the external API link. Expect: HTTP 200 OK.
    curl -o /dev/null -s -w "%{http_code}\n" https://lexical.dev/docs/api/
    

    Length of output: 76


    175-188: Verify the functionality of packagesManager.

    Ensure that packagesManager provides the necessary methods and data when FB_INTERNAL is false to correctly populate entryPoints.

    Run the following script to check the implementation of packagesManager:

    Verification successful

    packagesManager is correctly implemented and provides necessary methods.

    The packagesManager is defined in scripts/shared/packagesManager.js and is used extensively across the codebase. It provides methods like getPublicPackages, which are essential for the logic in docusaurus.config.js. No issues found with its implementation or usage.

    Scripts executed

    The following scripts were executed for the analysis:

    Script:

    #!/bin/bash
    # Description: Verify the implementation of packagesManager.
    
    # Test: Search for the implementation of packagesManager. Expect: Correct methods and data structure.
    ast-grep --lang javascript --pattern $'const packagesManager = $_'
    

    Length of output: 67


    Script:

    #!/bin/bash
    # Description: Search for any mention of `packagesManager` across the codebase to understand its implementation or import.
    
    # Test: Search for `packagesManager` definition or import.
    rg 'packagesManager' -A 5
    

    Length of output: 19229

    @furwellness
    Copy link
    Owner

    Zero comments from coderabbit

    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.

    2 participants