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: support cjs and esm both by tshy #27

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

feat: support cjs and esm both by tshy #27

wants to merge 2 commits into from

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jan 3, 2025

BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257

Summary by CodeRabbit

Release Notes

  • Project Configuration

    • Updated Node.js version support to 18, 20, and 22
    • Updated TypeScript configuration to ES2022 and NodeNext module resolution
    • Updated minimum Node.js requirement to version 18
    • Added MIT license
  • Dependencies

    • Upgraded several development dependencies
    • Updated testing and build tools to latest versions
  • Documentation

    • Added Contributors section to README
    • Updated project requirements documentation
  • Maintenance

    • Updated .gitignore to exclude package-lock.json
    • Removed pull request template

BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257
Copy link

coderabbitai bot commented Jan 3, 2025

Walkthrough

This pull request introduces several updates across the project's configuration and dependencies. The changes primarily focus on upgrading Node.js and TypeScript versions, updating package dependencies, modifying workflow configurations, and adjusting TypeScript compiler settings. The modifications span multiple files, including GitHub Actions workflows, package configurations, test files, and project-level configuration files. The updates aim to modernize the project's toolchain and align with the latest ecosystem standards.

Changes

File Change Summary
.github/workflows/nodejs.yml Updated Node.js versions from '16, 18, 20' to '18, 20, 22'
.gitignore & boilerplate/_.gitignore Added package-lock.json and .package-lock.json to ignored files
README.md Added Contributors section with badge
boilerplate/README.md Updated Node.js requirement from 16.x to 18.x, TypeScript from 4.x to 5.x
boilerplate/_package.json Upgraded dependencies, updated scripts, increased Node.js engine requirement
boilerplate/config/* Removed PowerPartial type imports, simplified config type assertions
boilerplate/test/*/controller/*.test.ts Updated mock import from egg-mock/bootstrap to @eggjs/mock/bootstrap
boilerplate/tsconfig.json Added compiler options for ES2022, NodeNext module and resolution
package.json Updated ESLint versions, added MIT license

Poem

🐰 A Rabbit's Ode to Code Renewal 🚀

Versions dance, dependencies leap,
From sixteen to twenty-two we creep,
TypeScript shines, configs align,
Our project grows, line by line!
Hop, hop, hooray for upgrade's design! 🌟

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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

socket-security bot commented Jan 3, 2025

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

Package New capabilities Transitives Size Publisher
npm/[email protected] 🔁 npm/[email protected] Transitive: environment, eval, filesystem, unsafe +177 41.6 MB fengmk2

View full report↗︎

@fengmk2 fengmk2 marked this pull request as ready for review January 11, 2025 07:29
@fengmk2 fengmk2 marked this pull request as draft January 11, 2025 07:30
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: 2

🧹 Nitpick comments (4)
boilerplate/README.md (1)

32-33: Add documentation about CJS/ESM support

While the version requirements are correctly updated, consider adding documentation about:

  • The dual CJS/ESM support feature
  • Any specific configuration needed for each module system
  • Migration guide for users upgrading from Node.js 16.x
package.json (1)

24-25: Consider using more specific version ranges

Using major version numbers alone ("8", "14") might lead to unexpected breaking changes. Consider using more specific version ranges (e.g., "^8.0.0") for better dependency management.

boilerplate/config/config.local.ts (1)

1-1: Document the configuration type changes.

The removal of PowerPartial type affects how developers can define local configurations. This architectural change should be documented in the migration guide, especially since it's part of the transition to support both CJS and ESM.

Consider adding a section in the README or migration guide explaining:

  • Why PowerPartial was removed
  • How to properly type configurations now
  • Any implications for local development

Also applies to: 4-4

boilerplate/config/config.default.ts (1)

Line range hint 12-15: Add type definition for bizConfig.

The bizConfig object should have an explicit type to ensure type safety when spreading into the final config.

Consider adding a type:

-  const bizConfig = {
+  const bizConfig: Partial<EggAppConfig> = {
     sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
   };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4a77f8b and 9431e40.

📒 Files selected for processing (16)
  • .github/PULL_REQUEST_TEMPLATE.md (0 hunks)
  • .github/workflows/nodejs.yml (1 hunks)
  • .gitignore (1 hunks)
  • README.md (1 hunks)
  • boilerplate/README.md (1 hunks)
  • boilerplate/_.gitignore (1 hunks)
  • boilerplate/_package.json (1 hunks)
  • boilerplate/app/module/foo/package.json (1 hunks)
  • boilerplate/config/config.default.ts (1 hunks)
  • boilerplate/config/config.local.ts (1 hunks)
  • boilerplate/config/config.prod.ts (1 hunks)
  • boilerplate/test/app/module/bar/controller/home.test.ts (1 hunks)
  • boilerplate/test/app/module/bar/controller/user.test.ts (1 hunks)
  • boilerplate/test/app/module/foo/service/HelloService.test.ts (1 hunks)
  • boilerplate/tsconfig.json (1 hunks)
  • package.json (1 hunks)
💤 Files with no reviewable changes (1)
  • .github/PULL_REQUEST_TEMPLATE.md
✅ Files skipped from review due to trivial changes (5)
  • boilerplate/app/module/foo/package.json
  • README.md
  • boilerplate/test/app/module/bar/controller/user.test.ts
  • boilerplate/test/app/module/foo/service/HelloService.test.ts
  • boilerplate/_.gitignore
🔇 Additional comments (10)
boilerplate/test/app/module/bar/controller/home.test.ts (2)

Line range hint 4-10: Test implementation is robust and future-proof.

The test uses modern Node.js features (node: imports, async/await) while remaining framework-agnostic. This makes it compatible with both CJS and ESM module systems.


2-2: LGTM! Package import path updated correctly.

The change from 'egg-mock/bootstrap' to '@eggjs/mock/bootstrap' aligns with the modernization effort and supports the dual CJS/ESM compatibility goal.

Let's verify the package compatibility and availability:

✅ Verification successful

Import path change verified and package compatibility confirmed

The @eggjs/mock package properly supports both ESM and CommonJS through conditional exports, and the bootstrap entry point is correctly configured for dual module system compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify @eggjs/mock package compatibility with both CJS and ESM

# Check if package.json exists in node_modules/@eggjs/mock
if [ -f "node_modules/@eggjs/mock/package.json" ]; then
  # Check for "type" field and exports configuration
  cat node_modules/@eggjs/mock/package.json | jq '{type: .type?, exports: .exports?}'
else
  # If not installed, check npm registry
  curl -s https://registry.npmjs.org/@eggjs/mock/latest | jq '{type: .type?, exports: .exports?}'
fi

Length of output: 1021

.gitignore (1)

14-15: Verify: Is ignoring package lock files intentional?

Ignoring package-lock.json and .package-lock.json files is generally not recommended as they ensure consistent dependency installations across different environments. If this is related to the CJS/ESM support, consider documenting the rationale.

✅ Verification successful

Ignoring package lock files is part of the boilerplate pattern

The ignore patterns for package-lock.json and .package-lock.json are consistent with the boilerplate template in boilerplate/_.gitignore. This appears to be an intentional design choice for new projects created from this boilerplate. However, consider documenting the rationale behind this decision in the project documentation to help users understand the implications for dependency management.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if other egg boilerplates ignore package-lock.json
fd -g "*.gitignore" | xargs grep -l "package-lock.json"

Length of output: 79


Script:

#!/bin/bash
# Check the content of the template gitignore and look for any documentation
echo "=== Template .gitignore content ==="
cat boilerplate/_.gitignore

echo -e "\n=== Looking for related documentation ==="
rg -i "package.?lock" -g "!*.gitignore" -g "!package*.json" -A 2 -B 2

Length of output: 513

boilerplate/tsconfig.json (1)

4-6: LGTM! TypeScript configuration aligns with ESM support

The compiler options are well-configured for dual CJS/ESM support:

  • target: "ES2022" is appropriate for Node.js 18.19.0+
  • module and moduleResolution set to "NodeNext" enable proper ESM support
.github/workflows/nodejs.yml (1)

15-15: LGTM! Node.js versions align with requirements

The updated Node.js versions (18, 20, 22) properly align with:

  • The PR's breaking change of dropping support for Node.js < 18.19.0
  • Current Node.js LTS versions
package.json (1)

27-27: LGTM! Added MIT license field

Good addition of the MIT license field, ensuring proper licensing information is available in the package metadata.

boilerplate/_package.json (2)

38-38: Verify Node.js v22 type compatibility.

The upgrade to @types/node v22 is quite forward-looking. While it's good to stay updated, we should ensure it doesn't cause issues with the current Node.js engine requirement.

Let's check for potential compatibility issues:

Also applies to: 40-41, 43-43

✅ Verification successful

@types/node v22 upgrade is safe to proceed

The upgrade to @types/node v22 is safe as it's only used for development, and the codebase shows no usage of Node.js v22 specific features. The TypeScript configuration is version-agnostic and uses stable settings (ES2022, NodeNext).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if any code uses Node.js v22 specific features
fd -e ts -e js -x ast-grep --pattern 'import { $_ } from "node:$_"' {}

Length of output: 74


Script:

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

# Look for common Node.js built-in module usage
rg -l "require\(['\"](?:fs|path|http|crypto|stream|util|events)" --type ts --type js

# Check TypeScript configuration
fd tsconfig.json -x cat {}

Length of output: 410


27-27: Verify breaking changes in egg v4.0.0.

The major version bump of egg to v4.0.0 and the switch to @eggjs/scripts align with the modernization goals. However, we should ensure all breaking changes are addressed.

Let's check for potential breaking changes:

Also applies to: 32-33

✅ Verification successful

The codebase is compatible with egg v4 upgrade

The codebase already follows modern egg.js patterns and uses @eggjs/tegg decorators. No breaking changes from v3 to v4 affect the current implementation. Consider adding a MIGRATION.md guide to document the upgrade process for future contributors.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for egg.js v3 to v4 specific patterns that might need updates
rg -l 'egg-scripts|EggApplication|app.type|agent.type'

# Check if migration guide exists
test -f MIGRATION.md && echo "Migration guide exists" || echo "Consider adding a migration guide for v4"

Length of output: 170


Script:

#!/bin/bash
# Check for egg configuration files and patterns
fd -e js -e ts -e json config
rg -l "config\.(set|get)|plugin\.(enable|disable)"

# Check for egg plugin usage
rg -l "exports.plugin|exports.middleware|exports.schedule"

# Check TypeScript related patterns
rg -l "EggAppConfig|EggPlugin|EggLogger"

Length of output: 552


Script:

#!/bin/bash
# Check configuration files content
echo "=== Config Files ==="
for f in boilerplate/config/config.*.ts; do
  echo "=== $f ==="
  cat "$f"
done

echo -e "\n=== TypeScript Files ==="
echo "=== HelloService.ts ==="
cat "boilerplate/app/module/foo/service/HelloService.ts"
echo -e "\n=== home.ts ==="
cat "boilerplate/app/module/bar/controller/home.ts"

Length of output: 2569

boilerplate/config/config.prod.ts (1)

1-1: Verify the removal of PowerPartial type.

The change from PowerPartial<EggAppConfig> to direct EggAppConfig type assertion means all configuration properties must be fully defined. This could be a breaking change if any code relies on partial configuration objects.

Let's verify the impact:

Also applies to: 4-4

✅ Verification successful

PowerPartial removal is consistent with codebase patterns

The removal of PowerPartial is safe as all config files consistently use direct EggAppConfig assertions and fully defined config objects. No partial config patterns were found in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any partial config usage patterns
rg -l "PowerPartial.*EggAppConfig" .

# Check for any config properties that might be undefined
ast-grep --pattern 'config.$_ = undefined'

Length of output: 83


Script:

#!/bin/bash
# Search for config type patterns and usage
rg -l "type.*Config.*=.*{" .
rg -l "interface.*Config.*{" .

# Look for config object spread/partial assignments
ast-grep --pattern 'const config = { $$$ }'
ast-grep --pattern 'export default { $$$ } as'

# Check config-related files
fd -e ts -e js config

Length of output: 492


Script:

#!/bin/bash
# Check content of all config files
echo "=== config.default.ts ==="
cat boilerplate/config/config.default.ts
echo -e "\n=== config.local.ts ==="
cat boilerplate/config/config.local.ts
echo -e "\n=== config.prod.ts ==="
cat boilerplate/config/config.prod.ts

# Search with fixed regex patterns
rg "type.*Config" || true
rg "interface.*Config" || true

Length of output: 1204

boilerplate/config/config.default.ts (1)

Line range hint 18-21: Ensure type safety for spread operations.

When spreading objects into the final config, ensure all properties align with EggAppConfig. Consider using type assertions or validation to prevent runtime issues.

Let's verify the spread operation safety:

✅ Verification successful

Spread operations are properly type-safe

The implementation already ensures type safety through:

  • Explicit EggAppConfig typing for the config object
  • Simple extension through bizConfig with a single valid property
  • Proper type imports from the egg framework
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other spread operations in configs
rg "\\.\\.\\." . -A 2 -B 2

# Look for potential type mismatches in config properties
ast-grep --pattern 'config.$_ = $_'

Length of output: 1864


Script:

#!/bin/bash
# Check for type definitions and imports
ast-grep --pattern 'import { $_ } from "egg"'

# Look for type annotations and interfaces
ast-grep --pattern 'export interface $_Config extends $_'

# Find bizConfig definition
rg "bizConfig" -A 2 -B 2

# Check for PowerPartial usage
ast-grep --pattern 'PowerPartial<$_>'

Length of output: 742


Script:

#!/bin/bash
# Get the complete content of config.default.ts
cat boilerplate/config/config.default.ts

# Check for any type-related imports or definitions
rg "type|interface|import" boilerplate/config/config.default.ts

Length of output: 759

"typescript": "5"
},
"engines": {
"node": ">=20.10.0"
"node": ">=20.18.1"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Adjust Node.js version requirement.

The current requirement of "node": ">=20.18.1" is more restrictive than necessary. According to the PR objectives, we only need to drop support for Node.js versions below 18.19.0.

Consider updating the engine requirement:

-    "node": ">=20.18.1"
+    "node": ">=18.19.0"
📝 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
"node": ">=20.18.1"
"node": ">=18.19.0"

Comment on lines +10 to +11
"start": "eggctl start --daemon --title=egg-server-{{name}}",
"stop": "eggctl stop --title=egg-server-{{name}}",
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Documentation and dependency missing for eggctl commands

The migration from egg-scripts to eggctl requires proper documentation and dependency specification:

  • Add documentation for eggctl usage in README.md or relevant documentation
  • Specify eggctl as a dependency in package.json
  • Include migration instructions for users upgrading from egg-scripts
🔗 Analysis chain

Scripts updated to use modern egg.js tooling.

The migration from egg-scripts to eggctl and the enhanced script structure with proper pre/post hooks looks good. The clean script is well integrated into the workflow.

Let's verify the eggctl commands are properly documented:

Also applies to: 13-18, 21-22

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if eggctl commands are documented in the project
rg -i "eggctl" README.md || echo "eggctl commands not found in README.md"

Length of output: 111


Script:

#!/bin/bash
# Check for documentation files and eggctl references
fd -e md | xargs rg -i "eggctl" || echo "No eggctl documentation found in markdown files"

# Check if eggctl is listed in dependencies
cat boilerplate/_package.json | grep -i "eggctl"

Length of output: 306

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

Successfully merging this pull request may close these issues.

1 participant