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 the function of automatically importing single component packages to speed up user compilation and building #1

Merged
merged 3 commits into from
Feb 13, 2025

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Feb 12, 2025

添加自动导入单组件包功能,加快用户编译和构建速度

Summary by CodeRabbit

  • Documentation
    • Expanded guides with new sections detailing both the recommended and alternative methods for importing components.
    • Added clear examples and tips for projects using pnpm to manage component dependencies.
  • New Features
    • Introduced an optimized component resolution strategy to enhance build and compile speeds.
  • Chores
    • Updated several dependency versions and added new packages.
    • Added a development startup command for easier local testing and setup.
    • Introduced a new GitHub labeler configuration for better issue and pull request organization.

…packages to speed up user compilation and building
Copy link

coderabbitai bot commented Feb 12, 2025

Walkthrough

The changes update documentation and module declarations related to the @opentiny/unplugin-tiny-vue plugin. New sections in the README provide guidance on single- and multi-component import approaches, along with usage tips for pnpm. Several type declaration files have been adjusted to reference default exports from more specific packages. The dependency versions and package entries have been updated and new ones added. Additionally, the Vite configuration now uses a new resolver, and a new function has been introduced in src/index.ts that supports mode-based resolver selection.

Changes

File(s) Summary of Changes
README.md Added new sections: "单组件按需引入(推荐用法…)", "温馨提示", and "多组件按需引入(不推荐用法…)" with usage examples and guidelines.
example/auto-imports.d.ts,
example/components.d.ts
Updated exported declarations to reference default exports from specific packages (e.g., @opentiny/vue-loading, @opentiny/vue-modal, @opentiny/vue-button, etc.).
example/package.json Upgraded @opentiny/vue and @opentiny/vue-icon versions; added dependencies for @opentiny/vue-modal, @opentiny/vue-button, @opentiny/vue-loading, and @opentiny/vue-notify.
example/vite.config.js Replaced TinyVueResolver with TinyVueSingleResolver in both Components and AutoImport plugin configurations.
package.json Added a new script entry: "start": "pnpm -F my-vue-app dev".
src/index.ts Introduced TinyVueSingleResolver function; updated default export to accept a second parameter mode to choose the resolver dynamically.
.github/labeler.yaml Added a new configuration file defining labels for categorizing issues and pull requests.

Sequence Diagram(s)

sequenceDiagram
    participant U as User/Build System
    participant P as Plugin (src/index.ts)
    participant R as Resolver Function

    U->>P: Call default function(name, mode)
    alt mode indicates single import
       P->>R: Invoke TinyVueSingleResolver(name)
    else other mode
       P->>R: Invoke TinyVueResolver(name)
    end
    R-->>P: Return formatted import path
    P-->>U: Return resolver result
Loading

Poem

I'm a bunny with hops so spry,
Skipping through code as days fly by.
New sections and resolvers in my den,
Bringing order to imports again.
I nibble on updates with carrot cheer,
Hopping to a brighter code frontier!
🥕🐰 Happy coding, my dear!


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

🧹 Nitpick comments (1)
src/index.ts (1)

34-47: Add error handling for invalid component names.

The TinyVueSingleResolver implementation looks good but could be improved with error handling.

Consider adding error handling:

 export const TinyVueSingleResolver = (componentName: string) => {
+  if (!componentName || typeof componentName !== 'string') {
+    throw new Error('Component name must be a non-empty string')
+  }
+
   const importName = `@opentiny/vue-${kebabCase(componentName.slice(4))}`
   if (TinyVueFunc.includes(componentName)) {
     return importName
   }

   if (componentName.startsWith('Tiny') && !componentName.startsWith('TinyIcon')) {
     return importName
   }
+  return null
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4272a56 and 7153cd4.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • README.md (1 hunks)
  • example/auto-imports.d.ts (1 hunks)
  • example/components.d.ts (1 hunks)
  • example/package.json (2 hunks)
  • example/vite.config.js (1 hunks)
  • package.json (2 hunks)
  • src/index.ts (2 hunks)
🔇 Additional comments (8)
example/auto-imports.d.ts (1)

9-11: LGTM! Type declarations updated for single component imports.

The changes correctly update the type declarations to reference default exports from individual packages, which aligns with the PR objective of enabling single component imports for better build performance.

example/components.d.ts (1)

12-13: LGTM! Type declarations updated for single component imports.

The changes correctly update the type declarations to reference default exports from individual packages, maintaining consistency with auto-imports.d.ts.

example/vite.config.js (1)

6-6: LGTM! Configuration updated for single component imports.

The changes correctly configure both Components and AutoImport plugins to use TinyVueSingleResolver, enabling single component imports as intended.

Also applies to: 14-14, 17-17

example/package.json (1)

12-17: LGTM! Dependencies updated consistently.

All @opentiny dependencies are consistently updated to version ~3.21.0, which aligns with the new single component import feature.

Let's verify the compatibility of these versions:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Check for compatibility issues between dependencies

# Check if all packages are available on npm with specified version
for pkg in "@opentiny/vue" "@opentiny/vue-modal" "@opentiny/vue-button" "@opentiny/vue-loading" "@opentiny/vue-notify" "@opentiny/vue-icon"; do
  echo "Checking $pkg..."
  npm view "$pkg@~3.21.0" version
done

Length of output: 1687


Verified: Dependencies are consistent and align with the required version range.

  • The shell script confirms that each package is available with the ~3.21.0 semver range.
  • For @opentiny/vue, the output shows patch updates (3.21.0, 3.21.1, 3.21.2), which is expected with the tilde operator.
  • All other dependencies (@opentiny/vue-modal, @opentiny/vue-button, @opentiny/vue-loading, @opentiny/vue-notify, @opentiny/vue-icon) are available at version 3.21.0.
package.json (1)

18-18: LGTM! Added workspace-aware start script.

The new script correctly uses pnpm workspace feature to target the example app.

Let's verify the workspace setup:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Verify pnpm workspace configuration

# Check if pnpm-workspace.yaml exists
if [ -f "pnpm-workspace.yaml" ]; then
  echo "Found workspace config"
  cat pnpm-workspace.yaml
else
  echo "Warning: pnpm-workspace.yaml not found"
fi

# Check if example directory is properly configured
if [ -d "example" ]; then
  echo "Found example directory"
  if [ -f "example/package.json" ]; then
    echo "Found example package.json"
    cat example/package.json | grep "name"
  fi
fi

Length of output: 441


Workspace configuration verified: pnpm-workspace.yaml and example app are set up correctly.

  • pnpm-workspace.yaml exists with the "example" package defined.
  • The example/package.json confirms the package name "my-vue-app", matching the filter used in the start script.
README.md (3)

16-40: LGTM! Clear documentation for recommended single component imports.

The documentation effectively explains the recommended approach using TinyVueSingleResolver with clear examples for both Vite and Webpack configurations.


64-77: LGTM! Important note about pnpm dependencies.

The documentation properly addresses the phantom dependencies issue in pnpm projects and provides clear guidance on declaring component dependencies.


79-125: LGTM! Documentation for alternative multi-component imports.

The documentation clearly explains why this approach is not recommended (tree-shaking limitations for non-js files) and provides configuration examples.

Comment on lines +57 to 64
export default (name, mode) => {
// 兼容webpack/vite的差异
const autoPlugin = supportMap[name].default || supportMap[name]
const Resolver = mode === 'single' ? TinyVueSingleResolver : TinyVueResolver

return autoPlugin({
resolvers: [TinyVueResolver]
resolvers: [Resolver]
})
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add type definition and validation for mode parameter.

The mode parameter needs proper TypeScript type definition and validation.

Consider adding type definition and validation:

-export default (name, mode) => {
+type BuilderName = keyof typeof supportMap
+type ResolverMode = 'single' | undefined
+
+export default (name: BuilderName, mode?: ResolverMode) => {
   // 兼容webpack/vite的差异
   const autoPlugin = supportMap[name].default || supportMap[name]
+  if (mode && mode !== 'single') {
+    throw new Error('Invalid mode. Expected "single" or undefined')
+  }
   const Resolver = mode === 'single' ? TinyVueSingleResolver : TinyVueResolver

   return autoPlugin({
     resolvers: [Resolver]
   })
 }
📝 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
export default (name, mode) => {
// 兼容webpack/vite的差异
const autoPlugin = supportMap[name].default || supportMap[name]
const Resolver = mode === 'single' ? TinyVueSingleResolver : TinyVueResolver
return autoPlugin({
resolvers: [TinyVueResolver]
resolvers: [Resolver]
})
type BuilderName = keyof typeof supportMap
type ResolverMode = 'single' | undefined
export default (name: BuilderName, mode?: ResolverMode) => {
// 兼容webpack/vite的差异
const autoPlugin = supportMap[name].default || supportMap[name]
if (mode && mode !== 'single') {
throw new Error('Invalid mode. Expected "single" or undefined')
}
const Resolver = mode === 'single' ? TinyVueSingleResolver : TinyVueResolver
return autoPlugin({
resolvers: [Resolver]
})
}

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

11-11: ⚠️ Potential issue

Fix the yarn installation command.

The yarn command is incorrect. It should use add instead of i.

-yarn i @opentiny/unplugin-tiny-vue -D
+yarn add @opentiny/unplugin-tiny-vue -D
🧹 Nitpick comments (1)
README.md (1)

68-70: Consider using more restrictive version ranges.

While using ~3.x.x allows patch updates, it might be safer to use more specific version ranges to prevent unexpected breaking changes.

-    "@opentiny/vue-button": "~3.x.x",
-    "@opentiny/vue-alert": "~3.x.x",
-    "@opentiny/vue-input": "~3.x.x",
+    "@opentiny/vue-button": "^3.0.0",
+    "@opentiny/vue-alert": "^3.0.0",
+    "@opentiny/vue-input": "^3.0.0",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7153cd4 and 0189b16.

📒 Files selected for processing (1)
  • README.md (1 hunks)
🔇 Additional comments (2)
README.md (2)

16-59: Well-documented recommended approach!

The single component import section is well-structured and provides clear examples for both Vite and Webpack configurations. The recommendation to use TinyVueSingleResolver for improved compilation and build speed is valuable.


76-119: Clear explanation of the non-recommended approach!

The multi-component import section effectively communicates the limitations of this approach, particularly regarding tree-shaking of non-js files, while still providing complete documentation for both Vite and Webpack configurations.

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

🧹 Nitpick comments (2)
.github/labeler.yaml (2)

3-28: Consider adding descriptions for the labels.

The label matchers correctly follow conventional commit format. However, adding descriptions would improve maintainability and help contributors understand the purpose of each label.

 labels:
   - label: "enhancement"
     sync: true
+    description: "New features and improvements"
     matcher:
       title: "^feat.*: ?.*"
       commit: "^feat.*: ?.*"
   - label: "bug"
     sync: true
+    description: "Bug fixes and patches"
     matcher:
       title: "^fix.*: ?.*"
       commit: "^fix.*: ?.*"
   - label: "documentation"
     sync: true
+    description: "Documentation updates"
     matcher:
       title: "^docs?: ?.*"
       commit: "^docs?: ?.*"
   - label: "refactoring"
     sync: true
+    description: "Code refactoring without feature changes"
     matcher:
       title: "^refactor.*: ?.*"
       commit: "^refactor.*: ?.*"
   - label: "chore"
     sync: true
+    description: "Maintenance tasks and dependency updates"
     matcher:
       title: "^chore.*: ?.*"
       commit: "^chore.*: ?.*"

1-33: Consider adding more comprehensive commit types.

The current configuration covers basic commit types, but you might want to add more conventional commit types for better categorization.

 labels:
+  - label: "breaking"
+    sync: true
+    description: "Breaking changes"
+    matcher:
+      title: "^breaking.*: ?.*"
+      commit: "^breaking.*: ?.*"
+  - label: "test"
+    sync: true
+    description: "Test additions or updates"
+    matcher:
+      title: "^test.*: ?.*"
+      commit: "^test.*: ?.*"
+  - label: "ci"
+    sync: true
+    description: "CI/CD changes"
+    matcher:
+      title: "^ci.*: ?.*"
+      commit: "^ci.*: ?.*"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0189b16 and d5669d5.

📒 Files selected for processing (2)
  • .github/labeler.yaml (1 hunks)
  • example/vite.config.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • example/vite.config.js
🔇 Additional comments (2)
.github/labeler.yaml (2)

1-2: LGTM! Version declaration is correct.

The version declaration follows the standard format for GitHub Actions labeler configuration.


29-33:

❓ Verification inconclusive

Verify the base branch pattern for OSPP 2024.

The ospp-2024 label uses a base branch pattern. Please ensure this aligns with your branching strategy for the Open Source Promotion Plan 2024.


🏁 Script executed:

#!/bin/bash
# Check if any branches match the OSPP 2024 pattern
git branch -r | grep -E "ospp-2024/"

Length of output: 36


OSPP 2024 Base Branch Verification Required

The current baseBranch pattern for the ospp-2024 label (“^ospp-2024/.*”) did not match any remote branches based on your script output. Please manually verify that this naming pattern aligns with your intended branch strategy for the Open Source Promotion Plan 2024. If branches are expected to follow a different naming convention or are yet to be created, adjust the pattern or update the branch names accordingly.

@kagol kagol changed the title feat: added the function of automatically importing single component packages to speed up user compilation and building feat: add the function of automatically importing single component packages to speed up user compilation and building Feb 13, 2025
@kagol kagol merged commit 30beb36 into main Feb 13, 2025
0 of 2 checks passed
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.

2 participants