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: auto copy egg meta properties #3

Merged
merged 1 commit into from
Dec 22, 2024
Merged

feat: auto copy egg meta properties #3

merged 1 commit into from
Dec 22, 2024

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Dec 22, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced documentation in the README with new sections and badges for better visibility.
    • Added eggPlugin and egg properties to the output package metadata.
    • Introduced configuration options for Egg.js integration in package-init.json.
  • Bug Fixes

    • Improved test coverage with additional assertions for the generated package structure.
  • Chores

    • Updated Node.js version support in CI workflow.
    • Updated dependency versions in package.json.

Copy link

coderabbitai bot commented Dec 22, 2024

Walkthrough

This pull request introduces updates to the project's CI configuration, documentation, and source code. The changes primarily focus on expanding Node.js version support in GitHub Actions, updating dependencies, and adding Egg.js-related metadata to the package configuration. The modifications enhance the project's compatibility, documentation, and testing, with a particular emphasis on improving support for the Egg.js framework.

Changes

File Change Summary
.github/workflows/nodejs.yml Added Node.js version 23 to CI testing matrix
README.md Added badges for NPM version, CI status, downloads, and Node.js version; Included new sections for "Auto copy egg meta properties" and "License"
package.json Updated @types/node to ^22.10.2 and tshy to ^3.0.2
src/index.ts Added eggPlugin and egg properties to dist/package.json; Implemented replaceImportMetaUrl and copyFiles functions
test/fixtures/demo/package-init.json Added eggPlugin section with "egg-mock" name and egg section with framework: true
test/index.test.ts Added assertions to verify eggPlugin and egg properties in dist/package.json

Sequence Diagram

sequenceDiagram
    participant CI as GitHub Actions
    participant Build as Build Process
    participant Package as dist/package.json
    participant Test as Test Suite

    CI->>Build: Trigger build with multiple Node.js versions
    Build->>Package: Copy metadata
    Build->>Package: Add Egg.js properties
    Package->>Test: Verify package configuration
    Test-->>CI: Report test results
Loading

Poem

🐰 A rabbit's tale of code so bright,
Versions dancing, CI's delight!
Egg.js metadata, smooth and clean,
Dependencies updated, a developer's dream!
Hop along, pull request, take flight! 🚀


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

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@types/node@22.10.2 None +1 2.37 MB types
npm/tshy@3.0.2 environment, filesystem, shell Transitive: unsafe +50 27.6 MB isaacs

🚮 Removed packages: npm/@types/node@20.17.10, npm/tshy@2.0.1

View full report↗︎

Copy link

pkg-pr-new bot commented Dec 22, 2024

Open in Stackblitz

npm i https://pkg.pr.new/node-modules/tshy-after@3

commit: 157422f

@fengmk2 fengmk2 merged commit 8b1be69 into master Dec 22, 2024
16 checks passed
@fengmk2 fengmk2 deleted the copy-egg-meta branch December 22, 2024 14:56
fengmk2 pushed a commit that referenced this pull request Dec 22, 2024
[skip ci]

## [1.3.0](v1.2.0...v1.3.0) (2024-12-22)

### Features

* auto copy egg meta properties ([#3](#3)) ([8b1be69](8b1be69))
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 (4)
test/fixtures/demo/package-init.json (1)

35-37: Document the egg metadata purpose

Consider adding documentation to explain the purpose and impact of setting "framework": true in the egg configuration.

Would you like me to help draft documentation for these new egg metadata properties?

test/index.test.ts (1)

60-69: Add test cases for missing egg meta properties

The current test only covers the happy path where both eggPlugin and egg properties exist. Consider adding test cases for:

  • Missing eggPlugin property
  • Missing egg property
  • Empty/invalid property values

Example test cases:

it('should handle missing egg meta properties', async () => {
  // Setup package.json without egg meta properties
  const pkgWithoutEgg = { ...pkg };
  delete pkgWithoutEgg.eggPlugin;
  delete pkgWithoutEgg.egg;
  fs.writeFileSync(packageFile, JSON.stringify(pkgWithoutEgg));

  // Run the build
  await coffee.spawn('tshy', { cwd })
    .expect('code', 0)
    .end();

  // Verify dist/package.json doesn't contain the properties
  const distPkg = JSON.parse(fs.readFileSync(path.join(cwd, 'dist/package.json'), 'utf-8'));
  assert.equal(distPkg.eggPlugin, undefined);
  assert.equal(distPkg.egg, undefined);
});
README.md (2)

42-44: Enhance egg meta properties documentation

The current documentation briefly mentions the feature but lacks examples and structure details. Consider adding:

  • Example package.json with egg meta properties
  • Description of property structure and purpose
  • Use cases or scenarios where this is useful

Example addition:

## Auto-copy egg meta properties

Copies `eggPlugin` and `egg` properties from package.json to dist/package.json. This is useful for Egg.js plugins and frameworks.

Example package.json:
```json
{
  "eggPlugin": {
    "name": "your-plugin",
    "exports": {
      "import": "./dist/esm",
      "require": "./dist/commonjs"
    }
  },
  "egg": {
    "framework": true
  }
}
🧰 Tools
🪛 LanguageTool

[uncategorized] ~42-~42: It appears that a hyphen is missing (if ‘auto’ is not used in the context of ‘cars’).
Context: ...eURLToPath(import.meta.url)); } ``` ## Auto copy egg meta properties package.json Copy ...

(AUTO_HYPHEN)


12-12: Fix hyphenation in headings

Add hyphens to compound modifiers:

  • "Auto set" → "Auto-set"
  • "Auto copy" → "Auto-copy"

Also applies to: 42-42

🧰 Tools
🪛 LanguageTool

[uncategorized] ~12-~12: It appears that a hyphen is missing (if ‘auto’ is not used in the context of ‘cars’).
Context: ...: https://npmjs.org/package/tshy-after Auto set package.json after [tshy](https://githu...

(AUTO_HYPHEN)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 262e73c and 157422f.

📒 Files selected for processing (6)
  • .github/workflows/nodejs.yml (1 hunks)
  • README.md (2 hunks)
  • package.json (1 hunks)
  • src/index.ts (1 hunks)
  • test/fixtures/demo/package-init.json (1 hunks)
  • test/index.test.ts (1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~12-~12: It appears that a hyphen is missing (if ‘auto’ is not used in the context of ‘cars’).
Context: ...: https://npmjs.org/package/tshy-after Auto set package.json after [tshy](https://githu...

(AUTO_HYPHEN)


[uncategorized] ~42-~42: It appears that a hyphen is missing (if ‘auto’ is not used in the context of ‘cars’).
Context: ...eURLToPath(import.meta.url)); } ``` ## Auto copy egg meta properties package.json Copy ...

(AUTO_HYPHEN)

🔇 Additional comments (3)
.github/workflows/nodejs.yml (1)

15-15: LGTM! Verify Node.js 23 compatibility

Adding Node.js 23 to the test matrix improves coverage. However, let's verify there are no compatibility warnings.

✅ Verification successful

Node.js 23 compatibility verified

The codebase uses stable Node.js features:

  • Standard node: protocol imports for core modules
  • import.meta.url with proper fallback for CJS
  • No experimental features or deprecated APIs detected
  • Dev dependencies including @types/node@^22.10.2 are compatible
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any Node.js compatibility warnings in the codebase
rg -i "deprecated|warning|node.*compatibility" 

Length of output: 48


Script:

#!/bin/bash
# Check package.json for Node.js version requirements and dependencies
cat package.json | jq '.engines, .dependencies, .devDependencies'

# Look for any specific Node.js version requirements in README
fd README.md --exec cat {}

Length of output: 1780


Script:

#!/bin/bash
# Check for any import.meta.url usage which might need Node.js version compatibility checks
ast-grep --pattern 'import.meta.url'

# Check for any experimental features or Node.js specific APIs
rg -i "experimental|--experimental|node:|node-api"

Length of output: 713

package.json (1)

30-30: Verify breaking changes in dependency updates

The major version updates warrant careful review:

  • @types/node: ^20.6.2 → ^22.10.2
  • tshy: ^2.0.0 → ^3.0.2

Also applies to: 33-33

test/fixtures/demo/package-init.json (1)

28-34: Verify the egg-mock plugin name

The eggPlugin configuration uses "egg-mock" as the plugin name. Please verify if this is the intended name for this package.

✅ Verification successful

The initial results show "egg-mock" is used in the test file and fixture. Let's examine the test file and other package configurations to better understand if this is intentionally used as a test case.


"egg-mock" is intentionally used as a test fixture name

The test file confirms that "egg-mock" is deliberately used in test assertions to verify the copying of egg metadata properties. This is a test fixture specifically designed to verify the functionality of copying egg-related metadata, and the plugin name "egg-mock" is part of the test case expectations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for egg-mock references in the codebase
rg "egg-mock"

# Check if this is a test fixture by looking for test files
fd -t f "test" -e ts -e js

Length of output: 165


Script:

#!/bin/bash
# Check the content of the test file to understand the context
cat test/index.test.ts

# Check if there are any other package.json files in fixtures
fd package.json test/fixtures

Length of output: 2511

Comment on lines +16 to +17
eggPlugin: pkg.eggPlugin,
egg: pkg.egg,
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 validation for egg meta properties

The code directly copies eggPlugin and egg properties without checking if they exist in the source package.json. This could lead to undefined properties being copied to dist/package.json.

Consider adding validation:

writeFileSync('dist/package.json', JSON.stringify({
  name: pkg.name,
  version: pkg.version,
-  eggPlugin: pkg.eggPlugin,
-  egg: pkg.egg,
+  ...(pkg.eggPlugin && { eggPlugin: pkg.eggPlugin }),
+  ...(pkg.egg && { egg: pkg.egg }),
}, null, 2) + '\n')
📝 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
eggPlugin: pkg.eggPlugin,
egg: pkg.egg,
...(pkg.eggPlugin && { eggPlugin: pkg.eggPlugin }),
...(pkg.egg && { egg: pkg.egg }),

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.

1 participant