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 #5

Merged
merged 2 commits into from
Jan 11, 2025
Merged

feat: support cjs and esm both by tshy #5

merged 2 commits into from
Jan 11, 2025

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jan 11, 2025

BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257

Summary by CodeRabbit

  • Configuration Updates

    • Updated ESLint configuration to improve code quality and consistency
    • Removed legacy configuration files (JSHint, Travis CI)
    • Added TypeScript configuration with strict type checking
  • CI/CD Improvements

    • Replaced Travis CI with GitHub Actions workflows
    • Added automated testing and release processes
    • Configured Node.js version support (18.19.0, 20, 22)
  • Project Maintenance

    • Updated README with modern badges and documentation
    • Simplified package configuration
    • Removed outdated contributor information
  • Development Environment

    • Updated .gitignore to reflect current project structure
    • Added coverage and build-related ignore rules

BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257
Copy link

coderabbitai bot commented Jan 11, 2025

Walkthrough

The pull request introduces a comprehensive modernization of the project's configuration and development infrastructure. It replaces legacy configuration files like .jshintrc and .travis.yml with modern alternatives such as .eslintrc and GitHub Actions workflows. The project transitions to TypeScript, updates its package management, and enhances its build and testing processes. The changes reflect a shift towards more contemporary JavaScript development practices, with improved type safety, linting, and continuous integration setup.

Changes

File/Directory Change Summary
.eslintignore Added test/fixtures and coverage to linting exclusions
.eslintrc New ESLint configuration extending TypeScript and Node.js prefix rules
.github/workflows/nodejs.yml New CI workflow for Node.js testing across multiple versions
.github/workflows/pkg.pr.new.yml New workflow for package publishing automation
.github/workflows/release.yml New workflow for release management
.gitignore Updated with new entries for logs, node modules, coverage, and temporary files
.jshintignore, .jshintrc, .npmignore, .travis.yml, AUTHORS, index.d.ts Removed legacy configuration and metadata files
README.md Updated badges, installation instructions, and code examples
package.json Significant updates to dependencies, scripts, and package configuration
src/index.ts Migrated to TypeScript with improved type definitions
test/index.test.ts Rewrote tests in TypeScript with comprehensive test coverage
tsconfig.json New TypeScript configuration with strict type checking

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant CI as GitHub Actions
    participant NPM as NPM Registry
    participant Codecov as Codecov

    Dev->>CI: Push code
    CI->>CI: Run ESLint
    CI->>CI: Run TypeScript tests
    CI->>Codecov: Upload coverage report
    CI->>NPM: Publish package
    Codecov->>Dev: Provide coverage insights
Loading

Poem

🐰 A Rabbit's Ode to Code Renewal 🔧

Farewell, old configs, make way for the new,
TypeScript and Actions, a developer's brew!
Linting is stricter, our tests are more bright,
Continuous integration shining so tight!
Hop to the future, with code clean and clear! 🚀

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

pkg-pr-new bot commented Jan 11, 2025

Open in Stackblitz

npm i https://pkg.pr.new/node-modules/jsonp-body@5

commit: bb6d6c1

Copy link

codecov bot commented Jan 11, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

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 (5)
src/index.ts (1)

10-10: Consider adding input validation for negative limit values.

While the nullish coalescing operator is a good improvement for handling the limit option, the function should validate that the limit is not negative.

-  const limit = options.limit ?? 512;
+  const limit = Math.max(0, options.limit ?? 512);

Also applies to: 16-16

test/index.test.ts (1)

54-57: Add more test cases for limit validation.

Consider adding test cases for:

  • Zero limit
  • Negative limit
  • Very large limit values
package.json (1)

26-38: Consider pinning dependency versions.

The devDependencies use major version ranges which could lead to unexpected breaking changes. Consider using exact versions or more restrictive ranges.

Example:

-    "@arethetypeswrong/cli": "^0.17.1",
+    "@arethetypeswrong/cli": "0.17.1",
README.md (2)

20-20: Fix grammar in the description.

Change "other web framework" to "other web frameworks" for correct plural form.

-Helper to create more safe jsonp response body for [koa](http://koajs.com/) and other web framework.
+Helper to create more safe jsonp response body for [koa](http://koajs.com/) and other web frameworks.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~20-~20: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ... koa and other web framework. ## Install ```bash npm install jsonp...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)


Line range hint 48-56: Consider adding TypeScript type information.

Since the project now supports TypeScript, consider adding type information to the API documentation.

Example addition:

interface JsonpOptions {
  limit?: number;
  replacer?: (key: string, value: any) => any;
  space?: string | number;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 64616a9 and bb6d6c1.

📒 Files selected for processing (18)
  • .eslintignore (1 hunks)
  • .eslintrc (1 hunks)
  • .github/workflows/nodejs.yml (1 hunks)
  • .github/workflows/pkg.pr.new.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • .gitignore (1 hunks)
  • .jshintignore (0 hunks)
  • .jshintrc (0 hunks)
  • .npmignore (0 hunks)
  • .travis.yml (0 hunks)
  • AUTHORS (0 hunks)
  • README.md (2 hunks)
  • index.d.ts (0 hunks)
  • package.json (2 hunks)
  • src/index.ts (2 hunks)
  • test/index.test.js (0 hunks)
  • test/index.test.ts (1 hunks)
  • tsconfig.json (1 hunks)
💤 Files with no reviewable changes (7)
  • AUTHORS
  • .travis.yml
  • .jshintignore
  • .npmignore
  • .jshintrc
  • index.d.ts
  • test/index.test.js
✅ Files skipped from review due to trivial changes (3)
  • .eslintrc
  • tsconfig.json
  • .eslintignore
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~20-~20: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ... koa and other web framework. ## Install ```bash npm install jsonp...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)

🪛 Biome (1.9.4)
test/index.test.ts

[error] 46-46: eval() exposes to security risks and performance issues.

See the MDN web docs for more details.
Refactor the code so that it doesn't need to call eval().

(lint/security/noGlobalEval)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Node.js / Test (windows-latest, 22)
  • GitHub Check: Node.js / Test (windows-latest, 20)
  • GitHub Check: Node.js / Test (windows-latest, 18.19.0)
🔇 Additional comments (9)
src/index.ts (2)

1-8: LGTM! Well-structured Options interface with clear documentation.

The interface makes good use of TypeScript's utility types for JSON.stringify parameters and includes helpful JSDoc comments.


20-22: LGTM! Proper handling of line terminators.

Good security practice to escape the line terminator characters \u2028 and \u2029.

.gitignore (1)

1-11: LGTM! Comprehensive .gitignore for modern Node.js development.

The file properly excludes build artifacts, dependencies, and development tools while maintaining a clean structure.

.github/workflows/release.yml (1)

1-13: LGTM! Well-structured release workflow.

The workflow properly reuses shared actions and handles secrets correctly. Just ensure that both NPM_TOKEN and GIT_TOKEN secrets are configured in the repository settings.

.github/workflows/nodejs.yml (1)

1-16: LGTM! Node.js versions align with the new requirements.

The workflow configuration correctly tests against Node.js 18.19.0 (minimum supported version), 20, and 22, which aligns with dropping support for older versions.

.github/workflows/pkg.pr.new.yml (1)

1-23: LGTM! Verify package publishing permissions.

The workflow configuration is well-structured for building and publishing. However, ensure that the pkg-pr-new publish command has the necessary permissions to publish packages.

Run this script to verify the package publishing configuration:

package.json (2)

22-24: LGTM! Node.js version requirement aligns with PR objectives.

The engine requirement ">= 18.19.0" correctly implements the breaking change mentioned in the PR objectives.


49-75: LGTM! Excellent dual module support configuration.

The configuration properly supports both ESM and CJS:

  • Uses type: "module" to enable ESM by default
  • Configures exports field for dual package hazard prevention
  • Uses tshy for TypeScript build configuration
  • Correctly specifies entry points for different module systems
README.md (1)

Line range hint 31-43: LGTM! Modern JavaScript syntax in examples.

The usage example has been updated to use:

  • Modern const declarations
  • ES module-style destructuring
  • Async/await syntax
🧰 Tools
🪛 LanguageTool

[style] ~3-~3: Using many exclamation marks might seem excessive (in this case: 5 exclamation marks for a text that’s 933 characters long)
Context: ...y [![NPM version][npm-image]][npm-url] Node.js CI [![Test coverage][codecov-image]][codecov-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][download-url] [![Node.js Version](https://img.shields.io...

(EN_EXCESSIVE_EXCLAMATION)


[uncategorized] ~20-~20: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ... koa and other web framework. ## Install ```bash npm install jsonp...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)

test/index.test.ts Show resolved Hide resolved
@fengmk2 fengmk2 merged commit fa2f0ff into master Jan 11, 2025
20 checks passed
@fengmk2 fengmk2 deleted the egg-v4 branch January 11, 2025 09:07
fengmk2 pushed a commit that referenced this pull request Jan 11, 2025
[skip ci]

## [2.0.0](v1.1.0...v2.0.0) (2025-01-11)

### ⚠ BREAKING CHANGES

* drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Configuration Updates**
  - Updated ESLint configuration to improve code quality and consistency
  - Removed legacy configuration files (JSHint, Travis CI)
  - Added TypeScript configuration with strict type checking

- **CI/CD Improvements**
  - Replaced Travis CI with GitHub Actions workflows
  - Added automated testing and release processes
  - Configured Node.js version support (18.19.0, 20, 22)

- **Project Maintenance**
  - Updated README with modern badges and documentation
  - Simplified package configuration
  - Removed outdated contributor information

- **Development Environment**
  - Updated `.gitignore` to reflect current project structure
  - Added coverage and build-related ignore rules

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

### Features

* support cjs and esm both by tshy ([#5](#5)) ([fa2f0ff](fa2f0ff))
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