Skip to content

feat(release): add dist directory check for specific packages to optimize the release process #3265

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

Merged
merged 1 commit into from
Apr 8, 2025

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Apr 7, 2025

增加对特定包的 dist 目录检查,优化发布流程

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)

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:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Enhanced the alpha release process by introducing additional checks to ensure that necessary assets are available for selected modules before proceeding with version updates.

Copy link

coderabbitai bot commented Apr 7, 2025

Walkthrough

This change introduces a new array constant, needDistDirPackages, containing the package names ['utils', 'vue-hooks', 'vue-runtime']. In the releaseAlpha function, when iterating over distLists, the code now checks if an item is in needDistDirPackages. If it is, the function verifies the existence of either a dist or dist3 directory using fs.existsSync before calling findAllpage with the appropriate package path and updateVersion. For items not in the constant, findAllpage is invoked directly.

Changes

File Change Summary
internals/cli/.../releaseAlpha.ts Added constant needDistDirPackages (['utils', 'vue-hooks', 'vue-runtime']) and modified releaseAlpha to conditionally check for dist/dist3 directories before calling findAllpage.

Sequence Diagram(s)

sequenceDiagram
    participant R as releaseAlpha
    participant F as fs.existsSync
    participant P as findAllpage

    R->>R: Iterate over distLists
    alt Package in needDistDirPackages?
        R->>F: Check "dist" directory
        alt "dist" exists
            R->>P: Call findAllpage with package path & updateVersion
        else "dist" missing
            R->>F: Check "dist3" directory
            alt "dist3" exists
                R->>P: Call findAllpage with package path & updateVersion
            else
                R->>R: Skip findAllpage call
            end
        end
    else
        R->>P: Directly call findAllpage with package path
    end
Loading

Suggested labels

enhancement

Suggested reviewers

  • kagol

Poem

I'm a clever rabbit, hopping with delight,
In the code garden, everything's looking bright.
With carrots of change in every little byte,
Conditional hops make the release just right.
Celebrating smooth logic with a twitch and a bite!
🥕🐇

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

internals/cli/src/commands/release/releaseAlpha.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ 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 plan to trigger planning for file edits and PR creation.
  • @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 Apr 7, 2025
Copy link

github-actions bot commented Apr 7, 2025

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

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)
internals/cli/src/commands/release/releaseAlpha.ts (1)

81-107: 💡 Verification agent

🧩 Analysis chain

Consider adding tests for the new functionality.

The PR adds new conditional logic to the release process. It would be beneficial to have tests to verify this behavior.


🌐 Web query:

How to write tests for Node.js file system operations with fs-extra?

💡 Result:

To write effective tests for Node.js file system operations using fs-extra, leverage its promise-based API and implement robust setup/teardown workflows. Here's a structured approach:

Core Testing Strategy

  1. Isolate tests using temporary directories
  2. Use async/await for clean promise handling
  3. Verify file operations with explicit assertions
  4. Clean up resources after each test

Example Test Structure (Mocha/Jest)

const fs = require('fs-extra');
const path = require('path');
const { expect } = require('chai');

describe('File System Operations', () => {
  let tempDir;
  
  beforeEach(async () => {
    tempDir = path.join(__dirname, 'temp-' + Date.now());
    await fs.ensureDir(tempDir); // Create unique directory [4][5]
  });

  afterEach(async () => {
    await fs.remove(tempDir); // Cleanup after tests [1][4]
  });

  it('should create and verify file', async () => {
    const testFile = path.join(tempDir, 'test.txt');
    await fs.outputFile(testFile, 'sample content'); // Create file [2][4]
    
    const exists = await fs.pathExists(testFile);
    const content = await fs.readFile(testFile, 'utf8');
    
    expect(exists).to.be.true;
    expect(content).to.equal('sample content');
  });

  it('should handle recursive directory creation', async () => {
    const nestedPath = path.join(tempDir, 'a/b/c');
    await fs.ensureDir(nestedPath); // Create nested directories [1][4]
    
    const dirExists = await fs.pathExists(nestedPath);
    expect(dirExists).to.be.true;
  });
});

Key Best Practices

Test Isolation

  • Create unique temporary directories for each test run (Date.now() in path)
  • Use beforeEach/afterEach hooks for setup/teardown [7]

Error Handling

it('should throw on invalid operations', async () => {
  await expect(fs.readFile('nonexistent.txt'))
    .to.be.rejectedWith('ENOENT');
});

File Contents Verification

  • Use checksum validation for binary files
  • Compare JSON structures with deep equality checks

Cross-Platform Considerations

  • Use path.join() for file paths
  • Test symlink behavior with platform-specific conditions
  • Set CROSS_DEVICE_PATH env var for move operations [1][5]

Advanced Testing Patterns

Benchmarking Operations

it('should meet performance thresholds', async function() {
  this.timeout(5000);
  
  const start = Date.now();
  await fs.copy(largeDir, tempCopyDir);
  const duration = Date.now() - start;
  
  expect(duration).to.be.below(1000);
});

Parallel Execution Safety

  • Use separate directory hierarchies for parallel test runs
  • Avoid shared state between test files

CI Pipeline Setup

  • Add filesystem tests to your continuous integration workflow
  • Include cross-platform testing in matrix builds (Linux, Windows, macOS)

For complex scenarios, consider combining fs-extra with temporary directory libraries like tmp-promise and assertion libraries like sinon for monitoring file system interactions.

Citations:


Action: Enhance Testing Coverage for Conditional Release Logic

The new changes in internals/cli/src/commands/release/releaseAlpha.ts (lines 81–107) introduce additional file system checks to determine which packages trigger the findAllpage function. To ensure the intended behavior:

  • Simulate Various Scenarios: Create tests that mimic conditions where the "dist" or "dist3" directories exist (or not) to validate that packages within needDistDirPackages correctly evaluate the directory existence before calling findAllpage.
  • Cover All Branches: For packages not in needDistDirPackages, confirm that findAllpage is always invoked regardless of the file system state.
  • Leverage fs-extra Best Practices: Use temporary directories (with libraries like fs-extra) along with async/await for clean setup and teardown. This approach will isolate file system operations and help assert the correctness of file existence checks and subsequent function calls.

Adopting a testing strategy, such as the Mocha/Jest examples provided in the recent best practices, will ensure robust verification of these conditional code paths.

🧹 Nitpick comments (3)
internals/cli/src/commands/release/releaseAlpha.ts (3)

94-104: The conditional logic provides an optimization to the release process.

The added check ensures that packages like 'utils', 'vue-hooks', and 'vue-runtime' are only processed if they have the necessary build output (a 'dist' or 'dist3' directory). This prevents unnecessary work when these packages haven't been built yet.

Consider adding a brief comment explaining why these specific packages require the dist directory check for better maintainability:

80 const needDistDirPackages = ['utils', 'vue-hooks', 'vue-runtime']
+
+ // These packages need to have their dist/dist3 directories checked before processing
+ // because they require a build step to generate output files

96-98: Consider adding error handling for file system operations.

While existsSync doesn't throw exceptions, it's good practice to add error handling for file system operations.

- const hasDistDir = fs.existsSync(pathFromPackages(`${item}/dist`))
- const hasDist3Dir = fs.existsSync(pathFromPackages(`${item}/dist3`))
+ let hasDistDir = false;
+ let hasDist3Dir = false;
+ try {
+   hasDistDir = fs.existsSync(pathFromPackages(`${item}/dist`))
+   hasDist3Dir = fs.existsSync(pathFromPackages(`${item}/dist3`))
+ } catch (error) {
+   console.error(`Error checking dist directories for ${item}:`, error)
+ }

94-104: Consider adding a log message for skipped packages.

For debugging purposes, it would be helpful to log when a package is skipped because it doesn't have the required directories.

  if (hasDistDir || hasDist3Dir) {
    findAllpage(pathFromPackages(item), updateVersion)
+ } else {
+   console.log(`Skipping ${item} as it doesn't have dist or dist3 directory`)
  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 27216a9 and 66eb071.

📒 Files selected for processing (1)
  • internals/cli/src/commands/release/releaseAlpha.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
internals/cli/src/commands/release/releaseAlpha.ts

[error] 80-81: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (2)
internals/cli/src/commands/release/releaseAlpha.ts (2)

80-80: New constant created for packages requiring dist directory check.

This constant defines packages that need special handling during the release process. It's a good practice to extract this list as a constant for maintainability.

🧰 Tools
🪛 Biome (1.9.4)

[error] 80-81: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


75-75: Static analysis hint related to delete operator is a false positive.

The static analysis tool flagged the use of delete operator, but this is a standard way to remove properties from objects in JavaScript, and the performance impact is negligible in this context.

@zzcr zzcr merged commit 212c56f into release-3.22.0 Apr 8, 2025
12 checks passed
@kagol kagol deleted the fix-pulish-alpha-error-0407 branch April 14, 2025 12:29
kagol pushed a commit that referenced this pull request Apr 30, 2025
zzcr added a commit that referenced this pull request Apr 30, 2025
* feat(release): add dist directory check for specific packages to optimize the release process (#3265)

* fix(base-select): [select,base-select] fix the highlight style of the selected item icon (#3268)

* fix(base-select): [select,base-select] fix the highlight style of the selected item icon

* feat(base-select): [base-select] modify version number

* chore: release v3.22.1 (#3275)

* chore: added the cdn address of Huicharts component runtime, and updated the version number of docs to 3.22.3

---------

Co-authored-by: ajaxzheng <894103554@qq.com>
Co-authored-by: MomoPoppy <125256456+MomoPoppy@users.noreply.github.com>
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.

1 participant