Skip to content

feat: support cjs and esm both #1

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
Jun 8, 2024
Merged

feat: support cjs and esm both #1

merged 1 commit into from
Jun 8, 2024

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jun 8, 2024

BREAKING CHANGE: drop Node.js < 18 support

eggjs/egg#5257

Summary by CodeRabbit

  • New Features

    • Introduced Node.js CI workflow for automated testing and releases.
    • Added TypeScript support and enforced node prefix rules in ESLint configuration.
  • Documentation

    • Updated README with new badges and revised installation/usage instructions.
  • Chores

    • Updated .gitignore to include dist directory and .tshy* files.
    • Updated package.json with new dependencies, scripts, and metadata.
  • Tests

    • Added tests for caching content types functionality.

BREAKING CHANGE: drop Node.js < 18 support

eggjs/egg#5257
Copy link

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

Package New capabilities Transitives Size Publisher
npm/@types/node@20.14.2 None +1 2.16 MB types
npm/egg-bin@6.9.0 environment Transitive: eval, filesystem, network, shell, unsafe +159 10.9 MB fengmk2
npm/eslint-config-egg@13.1.0 Transitive: environment, eval, filesystem, unsafe +179 23 MB fengmk2
npm/eslint@8.57.0 environment, filesystem Transitive: eval, shell, unsafe +96 10.7 MB eslintbot
npm/mm@3.4.0 network, shell +7 97.9 kB fengmk2
npm/typescript@5.4.5 None 0 32.4 MB typescript-bot

🚮 Removed packages: npm/egg-bin@4.20.0, npm/egg-ci@1.19.1, npm/eslint-config-egg@7.5.1, npm/eslint@5.16.0, npm/mm@2.5.0

View full report↗︎

Copy link

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSource
Install scripts npm/egg-bin@6.9.0
  • Install script: postinstall
  • Source: node scripts/postinstall.js
Install scripts npm/core-js@2.6.12
  • Install script: postinstall
  • Source: node -e "try{require('./postinstall')}catch(e){}"
Install scripts npm/egg-ci@1.19.1
Install scripts npm/es5-ext@0.10.64
  • Install script: postinstall
  • Source: node -e "try{require('./_postinstall')}catch(e){}" || exit 0
Protestware/Troll package npm/es5-ext@0.10.64
  • Note: This package prints a protestware console message on install regarding Ukraine for users with Russian language locale

View full report↗︎

Next steps

What is an install script?

Install scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.

Packages should not be running non-essential scripts during install and there are often solutions to problems people solve with install scripts that can be run at publish time instead.

What is protestware?

This package is a joke, parody, or includes undocumented or hidden behavior unrelated to its primary function.

Consider that consuming this package my come along with functionality unrelated to its primary purpose.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

  • @SocketSecurity ignore npm/egg-bin@6.9.0
  • @SocketSecurity ignore npm/core-js@2.6.12
  • @SocketSecurity ignore npm/egg-ci@1.19.1
  • @SocketSecurity ignore npm/es5-ext@0.10.64

Copy link

coderabbitai bot commented Jun 8, 2024

Walkthrough

The project underwent significant updates, including enhanced ESLint configurations for TypeScript and Node.js, the addition of CI/CD workflows for testing and releasing with GitHub Actions, and expanded .gitignore entries. The package.json file saw numerous updates in dependencies, scripts, and metadata. New TypeScript files were introduced for the main functionality and tests, and the README.md was updated to reflect these changes.

Changes

File/Path Change Summary
.eslintrc Extended ESLint configuration for TypeScript and enforced node prefix rules.
.github/workflows/nodejs.yml Introduced Node.js CI workflow for pushes and pull requests to the master branch.
.github/workflows/release.yml Added GitHub Actions workflow for releasing Node.js projects on pushes to the master branch.
.gitignore Updated to include dist directory and .tshy* files.
README.md Updated badges, installation, and usage instructions for cache-content-type module.
package.json Numerous updates in metadata, dependencies, devDependencies, scripts, and export paths.
src/index.ts Introduced getType function for retrieving MIME types using an LRU cache.
test/index.test.ts Added tests for caching content types, including retrieval and cache behavior.
tsconfig.json Extended @eggjs/tsconfig and set strict typing, no implicit any, targeting ES2022, and NodeNext module.

Poem

In the land of code, where changes bloom,
New TypeScript files dispel the gloom.
With workflows set and ESLint tight,
Our project's future shines so bright.
Dependencies updated, tests in place,
We hop ahead with a steady pace.
CodeRabbit smiles, ears held high,
For in this code, no bugs shall lie.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@fengmk2 fengmk2 merged commit 2683290 into master Jun 8, 2024
5 of 6 checks passed
@fengmk2 fengmk2 deleted the support-esm branch June 8, 2024 11: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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8a43ff8 and e835707.

Files selected for processing (9)
  • .eslintrc (1 hunks)
  • .github/workflows/nodejs.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • .gitignore (1 hunks)
  • README.md (1 hunks)
  • package.json (2 hunks)
  • src/index.ts (1 hunks)
  • test/index.test.ts (1 hunks)
  • tsconfig.json (1 hunks)
Files skipped from review due to trivial changes (5)
  • .github/workflows/nodejs.yml
  • .github/workflows/release.yml
  • .gitignore
  • test/index.test.ts
  • tsconfig.json
Additional context used
LanguageTool
README.md

[style] ~3-~3: Using many exclamation marks might seem excessive (in this case: 3 exclamation marks for a text that’s 454 characters long) (EN_EXCESSIVE_EXCLAMATION)
Context: ...e [![NPM version][npm-image]][npm-url] Node.js CI [![Test coverage][codecov-image]][codecov-url] [![Known Vulnerabilities][snyk-image]][sny...

Additional comments not posted (3)
.eslintrc (1)

2-5: Updated ESLint configuration to support TypeScript and enforce node prefix rules.

README.md (1)

1-32: Updated README with new badges and ES module installation instructions.

Tools
LanguageTool

[style] ~3-~3: Using many exclamation marks might seem excessive (in this case: 3 exclamation marks for a text that’s 454 characters long) (EN_EXCESSIVE_EXCLAMATION)
Context: ...e [![NPM version][npm-image]][npm-url] Node.js CI [![Test coverage][codecov-image]][codecov-url] [![Known Vulnerabilities][snyk-image]][sny...

package.json (1)

Line range hint 4-69: Updated package.json to support new Node.js engine, enhance scripts, and update dependencies.

Comment on lines +6 to +16
export function getType(type: string): string | false {
if (!typeLRUCache) {
typeLRUCache = new LRU(100);
}
let mimeType = typeLRUCache.get<string | false>(type);
if (mimeType === undefined) {
mimeType = mimeTypes.contentType(type);
typeLRUCache.set(type, mimeType);
}
return mimeType;
}
Copy link

Choose a reason for hiding this comment

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

Ensure typeLRUCache is initialized before use to prevent runtime errors.

- let typeLRUCache: LRU;
+ let typeLRUCache: LRU = new LRU(100);
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.

Suggested change
export function getType(type: string): string | false {
if (!typeLRUCache) {
typeLRUCache = new LRU(100);
}
let mimeType = typeLRUCache.get<string | false>(type);
if (mimeType === undefined) {
mimeType = mimeTypes.contentType(type);
typeLRUCache.set(type, mimeType);
}
return mimeType;
}
export function getType(type: string): string | false {
let typeLRUCache: LRU = new LRU(100);
let mimeType = typeLRUCache.get<string | false>(type);
if (mimeType === undefined) {
mimeType = mimeTypes.contentType(type);
typeLRUCache.set(type, mimeType);
}
return mimeType;
}

fengmk2 pushed a commit that referenced this pull request Jun 8, 2024
[skip ci]

## [2.0.0](v1.0.1...v2.0.0) (2024-06-08)

### ⚠ BREAKING CHANGES

* drop Node.js < 18 support

eggjs/egg#5257

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

## Summary by CodeRabbit

- **New Features**
  - Introduced Node.js CI workflow for automated testing and releases.
- Added TypeScript support and enforced node prefix rules in ESLint
configuration.

- **Documentation**
- Updated README with new badges and revised installation/usage
instructions.

- **Chores**
  - Updated `.gitignore` to include `dist` directory and `.tshy*` files.
  - Updated `package.json` with new dependencies, scripts, and metadata.

- **Tests**
  - Added tests for caching content types functionality.

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

### Features

* support cjs and esm both ([#1](#1)) ([2683290](2683290))
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