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

feat: add preserveConfigExtension option #232

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

huntabyte
Copy link

@huntabyte huntabyte commented Oct 5, 2024

Closes #231

Summary by Sourcery

Add a new preserveConfigExtension option to the build process, which allows users to preserve the file extension of the velite.config file in the output. This is particularly useful for environments using "moduleResolution": "NodeNext" where extension-less files are not supported. Update the API documentation to reflect this new option.

New Features:

  • Introduce the preserveConfigExtension option to the build process, allowing the preservation of the velite.config file extension in the output index.d.ts file.

Documentation:

  • Update the API documentation to include the new preserveConfigExtension option, explaining its purpose and default value.

Summary by CodeRabbit

  • New Features

    • Introduced a new optional parameter, preserveConfigExtension, in the API reference for the build function, allowing users to retain the extension of the velite.config file in the output.
  • Documentation

    • Updated API documentation to include details about the new preserveConfigExtension parameter and its default value.

Copy link

sourcery-ai bot commented Oct 5, 2024

Reviewer's Guide by Sourcery

This pull request adds a new preserveConfigExtension option to the build process, allowing users to preserve the extension of the velite.config file in the output index.d.ts file. This feature is particularly useful for projects using "moduleResolution": "NodeNext" where extension-less files aren't supported.

Class diagram for updated Options interface

classDiagram
    class Options {
        boolean strict
        boolean preserveConfigExtension
    }

    class build {
        +build(options: Options): Promise<Record<string, unknown>>
    }

    Options <|-- build: uses

    class outputEntry {
        +outputEntry(dest: string, configPath: string, collections: Collections, preserveConfigExtension: boolean): Promise<void>
    }

    build --> outputEntry: calls
Loading

File-Level Changes

Change Details Files
Add preserveConfigExtension option to the Options interface
  • Add new boolean property preserveConfigExtension to the Options interface
  • Add JSDoc comment explaining the purpose and default value of the new option
src/build.ts
docs/reference/api.md
Implement preserveConfigExtension option in the build process
  • Destructure preserveConfigExtension from options with a default value of false
  • Pass preserveConfigExtension to the outputEntry function
src/build.ts
Update outputEntry function to handle preserveConfigExtension option
  • Add preserveConfigExtension parameter to outputEntry function with a default value of false
  • Conditionally remove the file extension from configModPath based on preserveConfigExtension value
src/output.ts
Update API documentation
  • Add preserveConfigExtension option to the Options interface documentation
  • Include explanation of the option's purpose and default value
docs/reference/api.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

coderabbitai bot commented Oct 5, 2024

Walkthrough

The pull request introduces a new optional parameter, preserveConfigExtension, to the Options interface in the API documentation and the build function. This parameter allows users to control whether the extension of the velite.config file is preserved in the output index.d.ts file, specifically when using the "moduleResolution": "NodeNext" option. The default value for this parameter is set to false. The changes also include updates to the outputEntry function to accommodate this new parameter, modifying its behavior based on the value provided.

Changes

File Change Summary
docs/reference/api.md Updated documentation for build function to include new optional parameter preserveConfigExtension.
src/build.ts Added preserveConfigExtension to Options interface and updated build function to integrate this option.
src/output.ts Modified outputEntry function to include preserveConfigExtension parameter and adjusted logic accordingly.

Assessment against linked issues

Objective Addressed Explanation
Support moduleResolution: "NodeNext" (#231)

Possibly related PRs

  • docs: improvements #201: Focuses on documentation improvements but does not relate to the modifications made in this PR.

Poem

In the land of code where rabbits hop,
A new option added, we won't stop!
Preserve the config, oh what a delight,
With extensions intact, our future is bright!
So let’s build and create, with joy in our hearts,
For every new feature, a masterpiece starts! 🐇✨


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

@sourcery-ai sourcery-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.

Hey @huntabyte - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

* Useful if `"moduleResolution": "NodeNext"` where extension-less files aren't supported.
* @default false
*/
preserveConfigExtension?: boolean
Copy link

Choose a reason for hiding this comment

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

suggestion (documentation): Consider adding an explicit type annotation for consistency

Other options in this interface, like logLevel, have explicit type annotations. Adding : boolean here would maintain consistency.

Suggested change
preserveConfigExtension?: boolean
preserveConfigExtension?: boolean;

Copy link
Author

Choose a reason for hiding this comment

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

Adding the semicolon makes it inconsistent with the rest of the interface.

Copy link

Choose a reason for hiding this comment

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

Thank you for your feedback, we will generate fewer comments like this in the future according to the following instructions:

- Ensure the comment addresses a significant issue or improvement in the code or documentation.
- Avoid comments that suggest minor stylistic changes unless they significantly impact readability or maintainability.
- Check if the comment provides a clear rationale for the suggestion and if it aligns with existing code conventions or guidelines.

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 (3)
docs/reference/api.md (1)

104-109: LGTM! Documentation for the new parameter is clear and addresses the PR objectives.

The addition of the preserveConfigExtension parameter to the Options interface is well-documented and aligns perfectly with the PR objectives. It provides a clear solution for users who need to support moduleResolution: "NodeNext".

Consider adding a cross-reference to the related configuration in the TypeScript documentation for moduleResolution. This could provide users with more context on when and why they might need to use this option. For example:

 /**
  * If true, preserves the extension of the `velite.config.[ts|js]` file in the output `index.d.ts` file.
  * Useful if `"moduleResolution": "NodeNext"` where extension-less files aren't supported.
+ * For more information, see: https://www.typescriptlang.org/tsconfig#moduleResolution
  * @default false
  */
 preserveConfigExtension?: boolean
src/output.ts (1)

33-42: Consider updating tests and documentation.

The changes to the outputEntry function look good. However, to ensure comprehensive coverage:

  1. Update any existing unit tests for this function to include cases with preserveConfigExtension set to both true and false.
  2. If there's separate documentation for the API, make sure to update it to reflect this new parameter and its behavior.
src/build.ts (1)

244-249: LGTM: New option preserveConfigExtension added.

The new option is well-documented and addresses the issue mentioned in the PR objectives. It provides a solution for users using "moduleResolution": "NodeNext".

Consider adding a link to the relevant documentation or issue in the comment for future reference:

 /**
  * If true, preserves the extension of the `velite.config` file in the output `index.d.ts` file.
  * Useful if `"moduleResolution": "NodeNext"` where extension-less files aren't supported.
+ * @see https://github.com/zce/velite/issues/231
  * @default false
  */
 preserveConfigExtension?: boolean
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e56c5d4 and ba1cc3d.

📒 Files selected for processing (3)
  • docs/reference/api.md (1 hunks)
  • src/build.ts (3 hunks)
  • src/output.ts (1 hunks)
🔇 Additional comments (6)
docs/reference/api.md (1)

Line range hint 1-109: Overall, the documentation update is well-implemented and focused.

The addition of the preserveConfigExtension parameter to the Options interface is the only change in this document, which aligns well with the PR objectives. The new parameter is clearly documented, and its purpose is well-explained. The rest of the document remains unchanged, maintaining consistency and focus on the specific feature addition.

src/output.ts (3)

31-33: LGTM! New parameter added to support moduleResolution: 'NodeNext'.

The addition of the preserveConfigExtension parameter with a default value of false is a good approach. It addresses the issue described in #231 while maintaining backward compatibility. The JSDoc comment clearly explains the purpose of the new parameter.


40-42: Conditional logic correctly implements the new feature.

The new conditional logic effectively handles the configModPath based on the preserveConfigExtension parameter. When true, it preserves the file extension, and when false, it removes it as before. This implementation aligns well with the PR objectives.


31-42: Summary: New option successfully implements requested feature.

The changes in this file successfully implement the preserveConfigExtension option as requested in issue #231. The implementation is backward-compatible and localized to the outputEntry function. This new feature will allow users to preserve the file extension when using moduleResolution: 'NodeNext', addressing the reported issue without affecting existing functionality.

Great job on this implementation!

src/build.ts (2)

3-4: LGTM: Import statement rearrangement.

The rearrangement of import statements is a minor change that doesn't affect functionality. It likely aligns with code style or linting rules.


Line range hint 1-291: Summary: Implementation of preserveConfigExtension option looks good.

The changes in this file successfully implement the new preserveConfigExtension option as described in the PR objectives. The implementation is minimal, focused, and maintains backward compatibility.

Next steps:

  1. Review the results of the verification script to ensure complete implementation.
  2. Update or add tests for the new option.
  3. Update the documentation to include information about this new option.
  4. Consider adding a changelog entry for this feature.

}

/**
* Build contents
* @param options build options
*/
export const build = async (options: Options = {}): Promise<Record<string, unknown>> => {
const { config: configFile, clean, logLevel, strict } = options
const { config: configFile, clean, logLevel, strict, preserveConfigExtension = false } = options
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Action Required: Add Tests for preserveConfigExtension Option

The preserveConfigExtension option is implemented in the build and output functions and is documented in the API reference. However, no tests have been found to verify its functionality.

  • Implementation Locations:
    • src/build.ts
    • src/output.ts
    • docs/reference/api.md

Recommendation:
Please add tests to ensure that the preserveConfigExtension option behaves as expected and maintains the desired functionality.

🔗 Analysis chain

LGTM: preserveConfigExtension option implemented in build function.

The changes correctly implement the new option in the build function and pass it to the outputEntry function. The default value of false ensures backward compatibility.

To ensure the preserveConfigExtension option is correctly implemented throughout the codebase, let's verify its usage:

Please review the results of these checks to ensure the option is fully implemented and tested.

Also applies to: 281-281


Action Required: Update and Re-run Verification Scripts

The previous verification scripts failed because ripgrep does not recognize typescript as a valid file type. Please use ts instead. Below are the updated scripts:

Please execute these updated scripts to continue the verification process.


Action Required: Further Verification Needed for preserveConfigExtension Implementation

The recent verification did not locate any instances of preserveConfigExtension within the src or test directories. To thoroughly confirm its implementation, please execute the following comprehensive search scripts:

Please run these scripts to gather additional information on the usage and implementation of the preserveConfigExtension option.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of preserveConfigExtension option

# Test 1: Check if outputEntry function signature has been updated
echo "Test 1: Checking outputEntry function signature"
rg --type typescript "function outputEntry.*preserveConfigExtension" src

# Test 2: Verify preserveConfigExtension is used in the output generation logic
echo "Test 2: Checking usage of preserveConfigExtension in output generation"
rg --type typescript "preserveConfigExtension.*\.js[\"']?" src

# Test 3: Ensure tests have been updated or added for the new option
echo "Test 3: Checking for updated or new tests"
rg --type typescript "test.*preserveConfigExtension" test

Length of output: 655


Script:

#!/bin/bash
# Description: Verify the implementation of preserveConfigExtension option with corrected file types

# Test 1: Check if outputEntry function signature has been updated
echo "Test 1: Checking outputEntry function signature"
rg --type ts "function outputEntry.*preserveConfigExtension" src

# Test 2: Verify preserveConfigExtension is used in the output generation logic
echo "Test 2: Checking usage of preserveConfigExtension in output generation"
rg --type ts "preserveConfigExtension.*\.js['\"]?" src

# Test 3: Ensure tests have been updated or added for the new option
echo "Test 3: Checking for updated or new tests"
rg --type ts "test.*preserveConfigExtension" test

Length of output: 526


Script:

#!/bin/bash
# Description: Comprehensive search for 'preserveConfigExtension' usage across the entire codebase

echo "Test 1: Searching for 'preserveConfigExtension' in all files"
rg "preserveConfigExtension" .

echo "Test 2: Searching for 'preserveConfigExtension' in non-TypeScript files"
rg "preserveConfigExtension" --type-not ts

echo "Test 3: Searching for any references or related configurations"
rg "preserveConfigExtension" src || rg "preserveConfigExtension" test

Length of output: 1901

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.

Support moduleResolution: "NodeNext"
1 participant