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 uni-ku-root plugin #72

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

feat: add uni-ku-root plugin #72

wants to merge 3 commits into from

Conversation

Skiyee
Copy link
Member

@Skiyee Skiyee commented Oct 31, 2024

Description 描述

添加模拟虚拟根组件插件 uni-ku-root

Linked Issues 关联的 Issues

close: #60

Summary by CodeRabbit

  • New Features

    • Introduced a new plugin option, uni-ku-root, enhancing component management capabilities.
    • Added a new development dependency for @uni-ku/root, enabling additional functionalities during development.
    • Updated the README to include the uni-ku-root plugin and clarified Node.js version requirements for Vite.
  • Improvements

    • Implemented a function to streamline plugin integration, enhancing the configuration process.
    • Enhanced CI workflow with additional testing parameters for improved plugin testing.

Copy link

coderabbitai bot commented Oct 31, 2024

Walkthrough

The changes in this pull request involve the addition of a new plugin entry for @uni-ku/root in the src/question/plugin/choices.ts file, enhancing the available options for component management. Additionally, the package.json file in template/plugin/root/ has been updated to include @uni-ku/root as a development dependency. Furthermore, a new function getData has been introduced in template/plugin/root/vite.config.js.data.mjs, which modifies the plugins array to incorporate the new root plugin.

Changes

File Change Summary
src/question/plugin/choices.ts Added new entry for uni-ku-root with title, value, and description in the exported array.
template/plugin/root/package.json Added @uni-ku/root as a new dependency in devDependencies.
template/plugin/root/vite.config.js.data.mjs Introduced getData function to modify the plugins array and include the new root plugin.
.github/workflows/ci.yml Updated flag-for-plugin array to include -p root for testing.
README.md Added uni-ku-root to the plugin list and updated Node.js version requirements.
template/plugin/root/src/App.ku.vue Introduced a new template structure with KuRootView component.

Assessment against linked issues

Objective Addressed Explanation
Add @uni-ku/root to the plugin list (#60)

🐇 In the garden, I hop with glee,
A new plugin added, oh what a spree!
With roots that grow and colors bright,
Our code blooms lovely, a pure delight!
Let's code 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

@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 (2)
template/plugin/root/vite.config.js.data.mjs (1)

1-1: Add parameter validation for oldData.

Consider adding validation to ensure oldData and oldData.plugins exist to prevent runtime errors.

 export default function getData({ oldData }) {
+  if (!oldData?.plugins) {
+    throw new Error('oldData.plugins is required')
+  }
src/question/plugin/choices.ts (1)

41-43: Consider using a more specific value identifier.

The current value 'root' is quite generic. Consider using a more descriptive value like 'uni-ku-root' or 'virtual-root' to:

  1. Maintain consistency with the package name
  2. Avoid potential naming conflicts with future plugins
  3. Make the configuration more self-documenting
  {
    title: rgb(146, 220, 210)('uni-ku-root'),
-   value: 'root',
+   value: 'uni-ku-root',
    description: '模拟虚拟根组件(支持SFC的App.vue)',
  },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 90be28c and b85aff4.

📒 Files selected for processing (3)
  • src/question/plugin/choices.ts (1 hunks)
  • template/plugin/root/package.json (1 hunks)
  • template/plugin/root/vite.config.js.data.mjs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • template/plugin/root/package.json
🔇 Additional comments (2)
template/plugin/root/vite.config.js.data.mjs (1)

9-14: 🛠️ Refactor suggestion

Review plugin injection strategy.

The current implementation has several potential issues to consider:

  1. It assumes a plugin with id: 'uni' exists. Consider handling the case when it doesn't.
  2. The root plugin is always inserted before the 'uni' plugin. Verify if this order is important for functionality.
  3. The spread operator might override important properties from oldData.
#!/bin/bash
# Look for other files that might depend on plugin order
rg -l "plugins.*uni" --type js

# Check for any documentation about plugin ordering
fd -e md -e txt . -x grep -l "plugin.*order"

Consider a more robust implementation:

   return {
     ...oldData,
-    plugins: oldData.plugins.flatMap(plugin =>
-      plugin.id === 'uni' ? [rootPlugin, plugin] : plugin,
-    ),
+    plugins: oldData.plugins.some(p => p.id === 'uni')
+      ? oldData.plugins.flatMap(plugin =>
+          plugin.id === 'uni' ? [rootPlugin, plugin] : plugin
+        )
+      : [...oldData.plugins, rootPlugin],
   }
src/question/plugin/choices.ts (1)

40-44: LGTM! The new plugin entry maintains consistency with existing entries.

The entry follows the established pattern with proper color coding, structure, and typing.

Comment on lines +2 to +7
const rootPlugin = {
id: 'root',
importer: `import UniRoot from '@uni-ku/root'`,
initializer: `// https://github.com/uni-ku/root
UniRoot()`,
}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Package is properly configured, but documentation could be improved

The @uni-ku/root package is correctly listed as a dependency in template/plugin/root/package.json, but there's no specific documentation about the plugin configuration. Consider adding documentation about the root plugin's purpose and configuration options.

  • Add documentation in a README.md file within the template/plugin/root/ directory explaining:
    • The purpose of the root plugin
    • Configuration options (if any)
    • Usage examples
🔗 Analysis chain

Verify package availability and add documentation.

The plugin configuration looks good, but let's ensure:

  1. The @uni-ku/root package is properly listed in dependencies
  2. The plugin configuration is documented
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if @uni-ku/root is listed in package.json files
rg -l "@uni-ku/root" --type json

# Look for any existing documentation about plugin configuration
fd -e md -e txt . -x grep -l "uni-ku/root"

Length of output: 173


Script:

#!/bin/bash
# Check package.json files for dependencies
fd package.json -x cat {} \; | jq -r '.dependencies, .devDependencies'

# Look for any imports or usage of uni-ku/root
rg "@uni-ku/root"

# Check for plugin documentation in markdown files
fd -e md -x cat {}

Length of output: 7406

@FliPPeDround
Copy link
Member

FliPPeDround commented Oct 31, 2024

哇🎊,
要是能在template下写入App.vue文件和root.ku.vue文件就更好啦,在生产模版的时候create-uni会做覆盖写入
ci 里也加上吧,每次更新都能做一次检查
README.md也加上介绍吧

@Skiyee
Copy link
Member Author

Skiyee commented Oct 31, 2024

哇🎊, 要是能在template下写入App.vue文件和root.ku.vue文件就更好啦,在生产模版的时候create-uni会做覆盖写入 ci 里也加上吧,每次更新都能做一次检查 README.md也加上介绍吧

我在v1.0.0做了一个更新,支持自定义的文件名
默认下还是采用 App.ku.vue,这是问题?需要在 vite.config 配置里做文件名更改?

ci 里也加上吧
这里是指?

@FliPPeDround
Copy link
Member

FliPPeDround commented Oct 31, 2024

哇🎊, 要是能在template下写入App.vue文件和root.ku.vue文件就更好啦,在生产模版的时候create-uni会做覆盖写入 ci 里也加上吧,每次更新都能做一次检查 README.md也加上介绍吧

我在v1.0.0做了一个更新,支持自定义的文件名 默认下还是采用 App.ku.vue,这是问题?需要在 vite.config 配置里做文件名更改?

都行,看你愿意
我的意思是
目前这样只是引入了uni-ku-root的依赖,最后生成的模版里,并没有示例代码。你可以在template文件夹下,添加示例代码,可以参照UI里的代码

@FliPPeDround
Copy link
Member

哇🎊, 要是能在template下写入App.vue文件和root.ku.vue文件就更好啦,在生产模版的时候create-uni会做覆盖写入 ci 里也加上吧,每次更新都能做一次检查 README.md也加上介绍吧

我在v1.0.0做了一个更新,支持自定义的文件名 默认下还是采用 App.ku.vue,这是问题?需要在 vite.config 配置里做文件名更改?

ci 里也加上吧
这里是指?

https://github.com/uni-helper/create-uni/blob/main/.github/workflows/ci.yml
这里有一个ci,可以在106行,添加上,每次更新就可以跑一遍测试

@pull-request-size pull-request-size bot added size/M and removed size/S labels Oct 31, 2024
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

🧹 Outside diff range and nitpick comments (4)
template/plugin/root/src/App.ku.vue (2)

1-9: LGTM! Consider adding English translations to comments.

The template structure is well-organized and correctly implements the KuRootView component. The comments effectively communicate the placement options and constraints.

Consider adding English translations to the comments for better international accessibility:

 <template>
-  <!-- 👇 顶级 KuRootView 👇 -->
+  <!-- 👇 Top-level KuRootView (顶级 KuRootView) 👇 -->
   <!-- <KuRootView /> -->

-  <!-- 👇 或内部 KuRootView,无论放置哪一个层级都被允许,但仅可有一个!👇  -->
+  <!-- 👇 Or internal KuRootView - can be placed at any level, but only one instance is allowed! 
+       (或内部 KuRootView,无论放置哪一个层级都被允许,但仅可有一个!) 👇  -->
   <div>
     <KuRootView />
   </div>
 </template>

1-9: Consider adding usage documentation.

Since this is a template file demonstrating the plugin's usage, it would be helpful to add more comprehensive documentation.

Consider adding a script section with comments explaining:

  • How to properly set up and use the KuRootView component
  • The purpose and benefits of using a virtual root component
  • Any configuration options available
  • Common use cases and best practices
<script>
/**
 * @uni-ku/root Plugin Template
 * 
 * This template demonstrates the usage of KuRootView component which simulates
 * a virtual root component. The component can be placed either at the top level
 * or nested within other elements, but only one instance is allowed per application.
 * 
 * Key Features:
 * - Virtual root component simulation
 * - Flexible placement options
 * - Single instance enforcement
 * 
 * @see https://github.com/uni-ku/root for full documentation
 */
</script>
.github/workflows/ci.yml (1)

106-106: LGTM! The CI matrix has been updated correctly.

The addition of -p root to the plugin matrix ensures that the new uni-ku-root plugin will be tested in combination with other plugins and configurations.

Consider adding specific test cases for the root plugin's functionality:

  1. Add a test job that verifies the virtual root component is correctly generated
  2. Add tests for custom file names (App.vue and root.ku.vue) as discussed in PR comments

Example test job structure:

test-root-plugin:
  needs: build
  runs-on: ubuntu-latest
  steps:
    - name: Test root plugin
      run: |
        # Create project with root plugin
        node ./dist/outfile.cjs test-root -p root
        
        # Verify file generation
        test -f test-root/src/App.ku.vue
        
        # Test custom file names
        mv test-root/src/App.ku.vue test-root/src/root.ku.vue
        pnpm build
README.md (1)

69-69: Consider enhancing the plugin description.

While the current description is clear, consider adding more details to help users understand the plugin's capabilities better:

  • Mention CLI/HBX project support
  • Add example use cases
  • Include basic usage instructions

Example enhanced description:

-| [uni-ku-root](https://github.com/uni-ku/root) | 模拟虚拟根组件(支持SFC的App.vue) | root |
+| [uni-ku-root](https://github.com/uni-ku/root) | 模拟虚拟根组件(支持SFC的App.vue),支持CLI和HBX创建的项目。可自定义App.vue和root.ku.vue文件名。 | root |
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b85aff4 and 5414882.

📒 Files selected for processing (3)
  • .github/workflows/ci.yml (1 hunks)
  • README.md (1 hunks)
  • template/plugin/root/src/App.ku.vue (1 hunks)
🔇 Additional comments (2)
template/plugin/root/src/App.ku.vue (1)

1-9: Verify KuRootView import and component registration.

The template uses KuRootView but there's no visible import or component registration. Let's verify if this is handled by the plugin setup.

✅ Verification successful

Let me gather more information about the plugin setup by checking the vite config and package files.


KuRootView component is properly handled by the plugin setup

The @uni-ku/root plugin is correctly configured in both the vite config and package.json. The plugin automatically registers the KuRootView component globally, which explains why no explicit import is needed in App.ku.vue.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if KuRootView is properly imported/registered in the project setup

# Look for KuRootView import statements or component registrations
rg -l "KuRootView"

# Check vite config for plugin registration
rg -l "@uni-ku/root"

# Look for any documentation about KuRootView setup
fd -g "README*" -x cat {}

Length of output: 4320


Script:

#!/bin/bash
# Check vite.config.js for plugin setup
cat template/plugin/root/vite.config.js.data.mjs

# Check package.json for dependencies
cat template/plugin/root/package.json

Length of output: 507

README.md (1)

69-69: LGTM! Plugin entry follows the established format.

The new entry for uni-ku-root is well-structured and maintains consistency with other plugin entries in the table.

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)
README.md (1)

69-69: LGTM! Consider enhancing the plugin documentation.

The plugin entry follows the correct format and provides basic information. However, consider enhancing the documentation with:

  • Version compatibility information
  • Basic usage examples
  • Common configuration options
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b85aff4 and 5414882.

📒 Files selected for processing (3)
  • .github/workflows/ci.yml (1 hunks)
  • README.md (1 hunks)
  • template/plugin/root/src/App.ku.vue (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • template/plugin/root/src/App.ku.vue
🔇 Additional comments (1)
README.md (1)

69-69: Add example usage in the template.

Based on the PR discussion, it would be beneficial to include example code in the template folder to demonstrate how to use the plugin effectively. This would help users understand the proper implementation of the virtual root component.

Let's check if there are any example files in the template directory:

@@ -103,7 +103,7 @@ jobs:
matrix:
flag-for-ts: ['', --ts]
flag-for-eslint: ['', -e]
flag-for-plugin: ['', -p import -p pages -p layouts -p manifest -p filePlatform -p platformModifier -p middleware -m pinia -m unocss -m uniNetwork -m uniUse -m uniPromises]
flag-for-plugin: ['', -p import -p pages -p layouts -p manifest -p filePlatform -p platformModifier -p middleware -p root -m pinia -m unocss -m uniNetwork -m uniUse -m uniPromises]
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

CI configuration needs additional test coverage for the root plugin

The current CI setup includes the root plugin in the test matrix (-p root), but there are gaps in test coverage:

  • No dedicated test files exist for the root plugin functionality
  • The plugin is only tested through the general build and dev process
  • No specific test cases verify the KuRootView component's behavior

Recommended actions:

  • Add unit tests for the root plugin in a dedicated test file
  • Include test cases for KuRootView component's placement restrictions
  • Add integration tests to verify plugin initialization and registration
  • Consider adding test cases for plugin configuration validation
🔗 Analysis chain

LGTM! The CI configuration properly integrates testing for the new plugin.

The addition of -p root to the test matrix ensures that the uni-ku-root plugin is tested across various configurations, including:

  • Different platforms (H5 and WeChat Mini Program)
  • Different development modes (build and dev)
  • Various combinations with other plugins and UI frameworks

Let's verify if all necessary test scenarios are covered:

Consider adding plugin-specific test cases if none are found by the verification script.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there are any plugin-specific test files or configurations that should be added

# Test 1: Check for plugin-specific test files
echo "Checking for plugin-specific test files..."
fd -t f "root.test" -t f "root.spec"

# Test 2: Check if the plugin is properly referenced in test configurations
echo "Checking test configurations..."
rg -l "uni-ku-root|@uni-ku/root" "test/" "tests/" "**/*.test.*" "**/*.spec.*"

Length of output: 572


Script:

#!/bin/bash
# Let's try a different approach to find test-related files and configurations

# Check for any files containing 'test' in their name
echo "Looking for test files across the repository..."
fd -t f "test"

# Search for test-related patterns in the entire codebase
echo "Searching for test-related patterns..."
rg -l "describe|test\(|it\(|expect\("

# Look specifically in template directory for root plugin files
echo "Checking template directory for root plugin..."
fd -t f . "template/plugin/root"

# Search for plugin registration or configuration patterns
echo "Searching for plugin configurations..."
rg -l "registerPlugin|createPlugin|plugin.*root"

Length of output: 806


Script:

#!/bin/bash
# Let's examine the plugin configuration and test coverage in more detail

# Check the content of vite config to understand plugin setup
echo "Examining vite config for root plugin..."
cat template/plugin/root/vite.config.js.data.mjs

# Check CI workflow file to understand test coverage
echo "Examining CI workflow..."
cat .github/workflows/ci.yml

# Look for any plugin-related test utilities or helpers
echo "Searching for plugin test utilities..."
rg -l "plugin.*test|test.*plugin"

# Check if there are any example or test cases in the root plugin template
echo "Checking root plugin template files..."
cat template/plugin/root/src/App.ku.vue

Length of output: 4905

@FliPPeDround
Copy link
Member

@FliPPeDround
Copy link
Member

uni-helper/vite-plugin-uni-components#13 这个pr应该能解决类似问题

@Skiyee
Copy link
Member Author

Skiyee commented Nov 11, 2024

awesome job!

等components那边的PR合并了,我一并更改代码!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[询问] 请问是否能加入 @uni-ku/root 至 插件列表?
2 participants