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 #8

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

Conversation

korbit-ai[bot]
Copy link

@korbit-ai korbit-ai bot commented Aug 13, 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?

These changes address build errors encountered in the internal Meta environment by ensuring that certain configurations and plugins are only applied when not in the internal environment. This approach maintains compatibility with both internal and external builds, preventing unnecessary failures.


PR Type

enhancement


Description

  • Added conditional logic to the docusaurus.config.js to handle internal Meta environment builds by checking the FB_INTERNAL environment variable.
  • Modified the entryPoints and plugins configuration to exclude certain elements when in the internal environment.
  • Updated the sidebar configuration in sidebars.js to use external links for 'Packages' when in the internal environment.
  • Ensured compatibility with both internal and external builds by filtering out null plugins.

Changes walkthrough 📝

Relevant files
Enhancement
docusaurus.config.js
Conditional configuration for internal Meta environment   

packages/lexical-website/docusaurus.config.js

  • Conditionally require packagesManager based on FB_INTERNAL environment
    variable.
  • Adjust entryPoints and plugins configuration for internal builds.
  • Exclude certain plugins and configurations when FB_INTERNAL is true.
  • Filter out null plugins from the plugins array.
  • +48/-32 
    sidebars.js
    Adjust sidebar configuration for internal builds                 

    packages/lexical-website/sidebars.js

  • Modify sidebar configuration based on FB_INTERNAL environment
    variable.
  • Use external links for 'Packages' when in internal environment.
  • +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

      • Introduction of conditional logic in the documentation configuration for improved adaptability based on the deployment environment.
      • Enhanced sidebar configuration allowing dynamic linking to documentation based on internal or external context.
    • Bug Fixes

      • Resolved issues related to the display of plugins based on the environment variable, ensuring correct loading of necessary components.
    • Chores

      • General improvements to maintainability and flexibility of the Docusaurus setup.

    Copy link
    Author

    korbit-ai bot commented Aug 13, 2024

    Clone of the PR facebook/lexical#6300

    Copy link
    Author

    korbit-ai bot commented Aug 13, 2024

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

    Copy link

    coderabbitai bot commented Aug 13, 2024

    Walkthrough

    The changes introduce conditional logic in the Docusaurus configuration files based on the FB_INTERNAL environment variable. This affects the import and configuration of modules, plugins, and sidebar items, allowing the documentation setup to differentiate between internal and external environments. The adjustments include modifying package management, plugin configurations, and sidebar structures to adapt to the specified environment.

    Changes

    Files Change Summary
    packages/lexical-website/docusaurus.config.js, packages/lexical-website/sidebars.js Conditional logic based on FB_INTERNAL for importing packages, configuring plugins, and rendering sidebar items. Adjustments include API links and the structure of the "Packages" section.

    Poem

    In a garden where code rabbits play,
    Configs shift like clouds in May.
    With FB_INTERNAL, paths are new,
    Linking docs in a clever view.
    Hop along, dear friends, and cheer,
    For flexible docs are finally here! 🐇✨


    🪧 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
    Author

    @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 3 potential issues.

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

    Choose a reason for hiding this comment

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

    category Systems and Environment

    I noticed that you're using environment variables to conditionally import packages and configure the application. This is a good practice for separating configuration from code, but it's important to ensure that these environment variables are correctly set in all environments where the application will be run. I recommend adding error handling to provide clear error messages if the required environment variables are not set. This will make it easier to diagnose and fix any issues related to environment configuration.

    Chat with Korbit for more details or suggestions by mentioning @korbit-ai in your reply, and don't forget to give a 👍 or 👎 to help Korbit improve your reviews.

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

    Choose a reason for hiding this comment

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

    category Functionality

    The conditional import of packagesManager could be improved for better error handling and maintainability. Consider using a dynamic import or a try-catch block to handle cases where the import might fail, especially in the FB_INTERNAL environment. This would make the code more robust and prevent potential runtime errors.

    Chat with Korbit for more details or suggestions by mentioning @korbit-ai in your reply, and don't forget to give a 👍 or 👎 to help Korbit improve your reviews.

    Comment on lines +243 to +259
    process.env.FB_INTERNAL
    ? null
    : [
    './plugins/package-docs',
    /** @type {import('./plugins/package-docs').PackageDocsPluginOptions} */
    {
    baseDir: path.resolve(__dirname, '..'),
    editUrl: `${GITHUB_REPO_URL}/tree/main/packages/`,
    packageFrontMatter: {
    lexical: [
    'sidebar_position: 1',
    'sidebar_label: lexical (core)',
    ].join('\n'),
    },
    targetDir: path.resolve(__dirname, 'docs/packages'),
    },
    ],
    Copy link
    Author

    Choose a reason for hiding this comment

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

    category Error Handling

    The code is using process.env.FB_INTERNAL to conditionally include or exclude certain plugins and configurations based on whether the build is internal or not. However, it does not handle the case where FB_INTERNAL is undefined. This could lead to runtime errors if that environment variable is not set. To fix this, provide a default value using the nullish coalescing operator (??) to default undefined values to false. For example, change process.env.FB_INTERNAL ? null : [ ... ] to (process.env.FB_INTERNAL ?? false) ? null : [ ... ].

    Chat with Korbit for more details or suggestions by mentioning @korbit-ai in your reply, and don't forget to give a 👍 or 👎 to help Korbit improve your reviews.

    @furwellness
    Copy link
    Owner

    @coderabbitai review

    Copy link

    coderabbitai bot commented Aug 13, 2024

    Actions performed

    Review triggered.

    Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

    @furwellness
    Copy link
    Owner

    /review

    Copy link

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

    PR Reviewer Guide 🔍

    (Review updated until commit 56a7734)

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

    Conditional Logic
    The PR introduces conditional logic based on the FB_INTERNAL environment variable. This might lead to different behavior between internal and external builds, potentially causing issues if not properly tested in both environments.

    API Documentation
    The PR changes how API documentation is handled for internal builds. This could potentially lead to discrepancies in documentation between internal and external versions.

    Copy link

    Persistent review updated to latest commit 56a7734

    @furwellness furwellness reopened this Aug 21, 2024
    @furwellness furwellness changed the base branch from cloned_main_25ba4 to main August 21, 2024 19:58
    @codiumai-pr-agent-free codiumai-pr-agent-free bot added the enhancement New feature or request label Aug 21, 2024
    @furwellness
    Copy link
    Owner

    @coderabbitai full review

    Copy link

    coderabbitai bot commented Aug 21, 2024

    Actions performed

    Full review triggered.

    Copy link

    Persistent review updated to latest commit 56a7734

    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.

    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(),
     
    +// ... (outside the object)
    +
    +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 simplifying the main configuration object.

    8
    Enhancement
    Use object spread for cleaner conditional object creation

    Consider using an object literal instead of a ternary operator for better
    readability when conditionally setting the 'Packages' sidebar item.

    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 object creation can improve readability by clearly separating shared properties from conditional ones.

    7
    Simplify conditional assignment using a ternary operator

    Consider using a ternary operator instead of an if-else statement for better
    readability and conciseness when assigning the packagesManager variable.

    packages/lexical-website/docusaurus.config.js [16-18]

    -const {packagesManager} = process.env.FB_INTERNAL
    -  ? {}
    -  : require('../../scripts/shared/packagesManager');
    +const {packagesManager} = process.env.FB_INTERNAL ? {} : require('../../scripts/shared/packagesManager');
     
    • Apply this suggestion
    Suggestion importance[1-10]: 3

    Why: The suggestion to use a ternary operator is already implemented in the existing code, so the suggestion does not provide any improvement.

    3

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

    Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between 4cbb85f and 56a7734.

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

    56-70: Verify the environment variable setup for FB_INTERNAL.

    The conditional logic for the "Packages" section in the sidebar is based on the FB_INTERNAL environment variable. Ensure that this variable is set correctly in all environments where the application is deployed to avoid runtime issues.

    Run the following script to verify the usage of the FB_INTERNAL environment variable across the codebase:

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

    243-259: Ensure error handling for undefined environment variables.

    The plugins configuration should handle cases where FB_INTERNAL is undefined to prevent runtime errors.

    Consider using a default value with the nullish coalescing operator (??) to handle undefined values:

     plugins: (process.env.FB_INTERNAL ?? false)
       ? null
       : [
           './plugins/package-docs',
           /** @type {import('./plugins/package-docs').PackageDocsPluginOptions} */
           {
             baseDir: path.resolve(__dirname, '..'),
             editUrl: `${GITHUB_REPO_URL}/tree/main/packages/`,
             packageFrontMatter: {
               lexical: [
                 'sidebar_position: 1',
                 'sidebar_label: lexical (core)',
               ].join('\n'),
             },
             targetDir: path.resolve(__dirname, 'docs/packages'),
           },
         ],

    Likely invalid or redundant comment.

    Comment on lines +390 to +401
    process.env.FB_INTERNAL
    ? {
    href: 'https://lexical.dev/docs/api/',
    label: 'API',
    position: 'left',
    }
    : {
    label: 'API',
    position: 'left',
    sidebarId: 'api',
    type: 'docSidebar',
    },
    Copy link

    Choose a reason for hiding this comment

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

    Ensure error handling for undefined environment variables.

    The API link configuration should handle cases where FB_INTERNAL is undefined to prevent runtime errors.

    Consider using a default value with the nullish coalescing operator (??) to handle undefined values:

     process.env.FB_INTERNAL ?? false
       ? {
           href: 'https://lexical.dev/docs/api/',
           label: 'API',
           position: 'left',
         }
       : {
           label: 'API',
           position: 'left',
           sidebarId: 'api',
           type: 'docSidebar',
         },
    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
    process.env.FB_INTERNAL
    ? {
    href: 'https://lexical.dev/docs/api/',
    label: 'API',
    position: 'left',
    }
    : {
    label: 'API',
    position: 'left',
    sidebarId: 'api',
    type: 'docSidebar',
    },
    process.env.FB_INTERNAL ?? false
    ? {
    href: 'https://lexical.dev/docs/api/',
    label: 'API',
    position: 'left',
    }
    : {
    label: 'API',
    position: 'left',
    sidebarId: 'api',
    type: 'docSidebar',
    },

    Comment on lines +175 to +188
    entryPoints: process.env.FB_INTERNAL
    ? []
    : packagesManager
    .getPublicPackages()
    .flatMap((pkg) =>
    pkg
    .getExportedNpmModuleEntries()
    .map((entry) => [
    path.relative(
    __dirname,
    pkg.resolve('src', entry.sourceFileName),
    ),
    ]),
    ),
    Copy link

    Choose a reason for hiding this comment

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

    Ensure error handling for undefined environment variables.

    The entryPoints configuration should handle cases where FB_INTERNAL is undefined to prevent runtime errors.

    Consider using a default value with the nullish coalescing operator (??) to handle undefined values:

     entryPoints: (process.env.FB_INTERNAL ?? false)
       ? []
       : packagesManager
           .getPublicPackages()
           .flatMap((pkg) =>
             pkg
               .getExportedNpmModuleEntries()
               .map((entry) => [
                 path.relative(
                   __dirname,
                   pkg.resolve('src', entry.sourceFileName),
                 ),
               ]),
           ),
    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
    entryPoints: process.env.FB_INTERNAL
    ? []
    : packagesManager
    .getPublicPackages()
    .flatMap((pkg) =>
    pkg
    .getExportedNpmModuleEntries()
    .map((entry) => [
    path.relative(
    __dirname,
    pkg.resolve('src', entry.sourceFileName),
    ),
    ]),
    ),
    entryPoints: (process.env.FB_INTERNAL ?? false)
    ? []
    : packagesManager
    .getPublicPackages()
    .flatMap((pkg) =>
    pkg
    .getExportedNpmModuleEntries()
    .map((entry) => [
    path.relative(
    __dirname,
    pkg.resolve('src', entry.sourceFileName),
    ),
    ]),
    ),

    @kavitaganeshan
    Copy link

    @coderabbitai full review

    Copy link

    coderabbitai bot commented Oct 17, 2024

    ✅ Actions performed

    Full review triggered.

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

    🧹 Outside diff range and nitpick comments (1)
    packages/lexical-website/sidebars.js (1)

    56-70: Conditional rendering for "Packages" section looks good, but consider some improvements.

    The implementation successfully differentiates between internal and external builds, which aligns with the PR objectives. However, there are a few suggestions for improvement:

    1. The indentation of the new code block seems off. Consider adjusting it for better readability.
    2. Using process.env.FB_INTERNAL directly in the sidebar configuration might not be the most maintainable approach. Consider extracting this logic to a separate configuration file or utility function.
    3. The external URL is hardcoded. It might be better to define it as a constant or configuration variable for easier maintenance.

    Here's a suggested refactor to address these points:

    const config = require('./config');
    
    // ... (rest of the file)
    
    const sidebars = {
      // ... (other sidebar items)
      config.isInternalBuild()
        ? {
            href: config.EXTERNAL_PACKAGES_URL,
            label: 'Packages',
            type: 'link',
          }
        : {
            items: [
              {
                dirName: 'packages',
                type: 'autogenerated',
              },
            ],
            label: 'Packages',
            type: 'category',
          },
      // ... (rest of the sidebar items)
    };

    This approach improves maintainability and readability while preserving the intended functionality.

    📜 Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    📥 Commits

    Files that changed from the base of the PR and between 4cbb85f and 56a7734.

    📒 Files selected for processing (2)
    • packages/lexical-website/docusaurus.config.js (6 hunks)
    • packages/lexical-website/sidebars.js (1 hunks)
    🧰 Additional context used

    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.

    🛠️ Refactor suggestion

    Refactor to use a constant for process.env.FB_INTERNAL

    To improve readability and maintainability, consider defining a constant to store the value of process.env.FB_INTERNAL and reuse it throughout the file. This reduces redundancy and makes future updates easier.

    Define the constant at the beginning of the file:

    +const IS_FB_INTERNAL = Boolean(process.env.FB_INTERNAL);

    Then update the conditional statements:

    -const {packagesManager} = process.env.FB_INTERNAL
    +const {packagesManager} = IS_FB_INTERNAL
       ? {}
       : require('../../scripts/shared/packagesManager');
    -  entryPoints: process.env.FB_INTERNAL
    +  entryPoints: IS_FB_INTERNAL
          ? []
          : packagesManager
              .getPublicPackages()
              .flatMap((pkg) =>
                pkg
                  .getExportedNpmModuleEntries()
                  .map((entry) => [
                    path.relative(
                      __dirname,
                      pkg.resolve('src', entry.sourceFileName),
                    ),
                  ]),
              ),
    -    process.env.FB_INTERNAL
    +    IS_FB_INTERNAL
           ? null
           : [
               './plugins/package-docs',
               /** @type {import('./plugins/package-docs').PackageDocsPluginOptions} */
               {
                 baseDir: path.resolve(__dirname, '..'),
                 editUrl: `${GITHUB_REPO_URL}/tree/main/packages/`,
                 packageFrontMatter: {
                   lexical: [
                     'sidebar_position: 1',
                     'sidebar_label: lexical (core)',
                   ].join('\n'),
                 },
                 targetDir: path.resolve(__dirname, 'docs/packages'),
               },
             ],
    -          process.env.FB_INTERNAL
    +          IS_FB_INTERNAL
                 ? {
                     href: 'https://lexical.dev/docs/api/',
                     label: 'API',
                     position: 'left',
                   }
                 : {
                     label: 'API',
                     position: 'left',
                     sidebarId: 'api',
                     type: 'docSidebar',
                   },

    Also applies to: 175-188, 243-259, 390-401

    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.

    3 participants