Skip to content

feat: 追加 npmrc 文件的生成#1243

Open
Ljhhhhhh wants to merge 1 commit intoopentiny:developfrom
Ljhhhhhh:feature-npmrc
Open

feat: 追加 npmrc 文件的生成#1243
Ljhhhhhh wants to merge 1 commit intoopentiny:developfrom
Ljhhhhhh:feature-npmrc

Conversation

@Ljhhhhhh
Copy link
Contributor

@Ljhhhhhh Ljhhhhhh commented Mar 22, 2025

根据组件schema 的 npm.npmrc 配置信息生成内容到 npmrc 文件,以满足私有组件库的自动镜像配置生成

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

给组件 schema 增加 npmrc 配置信息后,可以自动生成 .npmrc 配置文件,解决出码后私有组件库无法安装的问题

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Introduced an automated npm configuration generator that creates a configuration file based on project dependencies and settings.
    • Enhanced the app's configuration generator with a new plugin, expanding customization options for npm settings.

根据组件schema 的 npm.npmrc 配置信息生成内容到 npmrc 文件,以满足私有组件库的自动镜像配置生成
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 22, 2025

Walkthrough

The changes introduce a new plugin, genNpmrcPlugin, into the Vue generator. The generateApp function now integrates the npmrc plugin into its default and custom plugins handling. A new file implements the plugin’s logic for generating .npmrc files based on schema analysis, while the plugins index is updated to export this new module.

Changes

File(s) Change Summary
packages/vue-generator/src/generator/generateApp.js Updated to integrate the new npmrc plugin into default and custom plugin merging logic.
packages/vue-generator/src/plugins/genNpmrcPlugin.js, packages/vue-generator/src/plugins/index.js Introduced genNpmrcPlugin to generate .npmrc files based on schema analysis and updated exports to include the new plugin.

Sequence Diagram(s)

sequenceDiagram
    participant GA as generateApp
    participant DP as DefaultPlugins
    participant GN as genNpmrcPlugin
    participant FS as FileSystem

    GA->>DP: Merge default and custom plugins (includes npmrc)
    alt npmrc plugin is configured
        GA->>GN: Invoke run method with schema
        GN->>FS: Write .npmrc file with generated content
    end
Loading

Suggested labels

enhancement

Suggested reviewers

  • hexqi
  • chilingling

Poem

I’m a little rabbit, hopping with delight,
In code burrows deep, new plugins take flight.
With genNpmrc magic, our files sing,
Dependencies and mirrors now perfectly cling.
Cheers to the changes that brighten our night!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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.

@github-actions github-actions bot added the enhancement New feature or request label Mar 22, 2025
Copy link
Contributor

@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)
packages/vue-generator/src/plugins/genNpmrcPlugin.js (2)

70-73: Add validation for empty npmrc entries

The current implementation doesn't validate that the npmrc entries are not empty or undefined. Also, consider handling the case where the resulting file would be empty.

run(schema) {
  const npmMirrorList = parseSchema(schema)
- this.addFile({ fileType: 'npmrc', fileName, path, fileContent: Array.from(npmMirrorList).join('\n') }, true)
+ const validEntries = Array.from(npmMirrorList).filter(entry => entry)
+ if (validEntries.length > 0) {
+   this.addFile({ fileType: 'npmrc', fileName, path, fileContent: validEntries.join('\n') }, true)
+ }
}

24-55: Consider handling possible newlines in npmrc values

If any of the npmrc values already contain newlines, joining them with \n could result in an improperly formatted .npmrc file.

Consider sanitizing the npmrc entries before adding them to the result set:

function sanitizeNpmrc(npmrc) {
  // Remove any existing newlines and trim whitespace
  return npmrc ? npmrc.replace(/\n/g, ' ').trim() : '';
}

// Then use this function when adding to resNpmMirror
resNpmMirror.add(sanitizeNpmrc(npmrc))
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cb59aa0 and 10b6bb7.

📒 Files selected for processing (3)
  • packages/vue-generator/src/generator/generateApp.js (4 hunks)
  • packages/vue-generator/src/plugins/genNpmrcPlugin.js (1 hunks)
  • packages/vue-generator/src/plugins/index.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
🔇 Additional comments (11)
packages/vue-generator/src/plugins/index.js (1)

13-13: LGTM!

The addition of the genNpmrcPlugin export follows the established pattern of the other plugin exports in this file.

packages/vue-generator/src/generator/generateApp.js (4)

13-15: LGTM!

The import of genNpmrcPlugin is correctly added to the existing list of plugin imports.


36-37: LGTM!

The npmrc plugin is properly added to the defaultPlugins object, following the same pattern as other plugins.


52-52: LGTM!

The npmrc property is correctly added to the destructured customPlugins object.


64-64: LGTM!

The npmrc plugin is properly included in the mergeWithDefaultPlugin object, using the same pattern as other plugins.

packages/vue-generator/src/plugins/genNpmrcPlugin.js (6)

1-7: LGTM!

The imports and default options are properly defined for the plugin.


9-22: LGTM!

The getComponentsSet helper function correctly extracts component names from the page and block schemas and returns a unique set of components.


29-33: Check the condition in the componentsMap loop

There's a logical inconsistency here. You're checking if !resNpmMirror.has(packageName) but then adding npmrc to the set, not packageName. This could lead to duplicated npmrc entries if different packages have the same npmrc configuration.

Consider modifying the code to either:

  1. Keep track of both packageName and npmrc to properly avoid duplicates
  2. Verify that this behavior is intentional
- if (packageName && !resNpmMirror.has(packageName) && componentsSet.has(componentName)) {
+ if (packageName && npmrc && !resNpmMirror.has(npmrc) && componentsSet.has(componentName)) {
  resNpmMirror.add(npmrc)
}

35-41: Similar inconsistency in the packages loop

The same issue exists in this loop. You check !resNpmMirror.has(packageName) but add npmrc to the set.

- if (packageName && !resNpmMirror.has(packageName)) {
+ if (packageName && npmrc && !resNpmMirror.has(npmrc)) {
  resNpmMirror.add(npmrc)
}

43-52: Similar issue in the utils loop

Again, there's a mismatch between what's checked (packageName) and what's added to the set (npmrc).

- if (type !== 'npm' || resNpmMirror.has(packageName)) {
+ if (type !== 'npm' || !npmrc || resNpmMirror.has(npmrc)) {
  continue
}

57-77: LGTM!

The main plugin function follows the correct structure for plugins in this system, with name, description, and a run method that handles the file generation.

@chilingling
Copy link
Member

需要 .npmrc 的场景可能不多?而且还可以通过 npm config set registry xxx 的方式直接在环境上设置。

可以考虑抽取出来作为独立的出码插件,用户按需配置。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


There may not be many scenarios that require .npmrc? It can also be set directly on the environment through npm config set registry xxx.

It can be considered to extract it as an independent code output plug-in and configure it on demand by users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants