Skip to content

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jan 12, 2025

BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257

Summary by CodeRabbit

  • New Features

    • Added static cache middleware for Koa.
    • Introduced TypeScript support for the package.
    • Implemented comprehensive configuration for package management.
  • Infrastructure

    • Updated GitHub Actions workflows for CI/CD.
    • Added ESLint configuration.
    • Updated project build and testing configurations.
  • Documentation

    • Refreshed README with new badges and installation instructions.
    • Updated package description and licensing.
  • Maintenance

    • Upgraded Node.js engine support to version 18.19.0+.
    • Migrated package to @eggjs/koa-static-cache.
    • Removed legacy Travis CI configuration.
    • Added new TypeScript configuration file.
    • Removed unnecessary files and configurations, streamlining the project structure.

BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257
@coderabbitai
Copy link

coderabbitai bot commented Jan 12, 2025

Warning

Rate limit exceeded

@fengmk2 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 18 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8cb3cbd and 8bad413.

📒 Files selected for processing (2)
  • src/index.ts (1 hunks)
  • test/index.test.ts (1 hunks)

Walkthrough

This pull request represents a comprehensive refactoring and modernization of the koa-static-cache package. The project has been transformed from a JavaScript-based implementation to a TypeScript-based solution, with significant updates to its configuration, testing, and deployment infrastructure. The changes include migrating to a scoped package (@eggjs/koa-static-cache), introducing modern JavaScript and TypeScript practices, updating dependencies, and implementing robust CI/CD workflows using GitHub Actions.

Changes

File Change Summary
.eslintignore Added test/fixtures and coverage to excluded directories
.eslintrc New ESLint configuration extending TypeScript and Node.js prefix rules
.github/workflows/nodejs.yml Added CI workflow for Node.js testing across multiple versions
.github/workflows/pkg.pr.new.yml Added workflow for package publishing
.github/workflows/release.yml Added release workflow for automated package releases
.gitignore Updated with new entries for logs, coverage, build artifacts
LICENSE Added MIT License with current year and original copyright
README.md Updated badges, installation, and API documentation
package.json Renamed to @eggjs/koa-static-cache, updated dependencies and scripts
src/index.ts Completely new TypeScript implementation of static cache middleware
test/index.test.ts Added comprehensive tests for static caching middleware
tsconfig.json Added TypeScript configuration with strict type checking
index.js Removed existing JavaScript implementation
Makefile Removed Makefile with testing and cleaning targets
.travis.yml Deleted Travis CI configuration file

Sequence Diagram

sequenceDiagram
    participant Client
    participant KoaServer
    participant StaticCache
    participant FileSystem

    Client->>KoaServer: HTTP Request
    KoaServer->>StaticCache: Process Static File Request
    StaticCache->>FileSystem: Check File Existence
    alt File Exists
        FileSystem-->>StaticCache: Return File Metadata
        StaticCache->>Client: Serve File with Caching Headers
    else File Not Found
        StaticCache->>Client: 404 Not Found
    end
Loading

Poem

🐰 A Rabbit's Ode to Static Cache Delight
In TypeScript's embrace, our middleware takes flight
Caching files with speed, making servers bright
GitHub Actions dance, tests running clean
From old to new, a transformation serene
Hop, hop, hooray for code so light! 🚀


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.

@socket-security
Copy link

socket-security bot commented Jan 12, 2025

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

Package New capabilities Transitives Size Publisher
npm/ylru@2.0.0 🔁 npm/ylru@1.4.0 None 0 26.3 kB fengmk2

🚮 Removed packages: npm/bluebird@3.7.2, npm/debug@3.2.7, npm/istanbul@0.4.5, npm/koa@2.15.3, npm/mocha@2.5.3, npm/mz@2.7.0, npm/should-http@0.0.4, npm/should@8.4.0, npm/supertest@1.2.0

View full report↗︎

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 12, 2025

Open in Stackblitz

npm i https://pkg.pr.new/eggjs/koa-static-cache/@eggjs/koa-static-cache@1

commit: 8bad413

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: 4

🧹 Nitpick comments (5)
.gitignore (1)

1-11: Consider retaining Windows-specific ignore patterns.

The removal of Windows-specific patterns (Thumbs.db, ehthumbs.db) might affect Windows users. Consider keeping these patterns for better cross-platform compatibility.

 logs/
 npm-debug.log
 node_modules/
 coverage/
 test/fixtures/**/run
 .DS_Store
 .tshy*
 .eslintcache
 dist
 package-lock.json
 .package-lock.json
+Thumbs.db
+ehthumbs.db
src/index.ts (2)

194-194: Simplify conditional logic using optional chaining

To enhance readability, you can simplify the condition using optional chaining.

Apply this diff:

-        if (options.alias && options.alias[filename]) {
+        if (options.alias?.[filename]) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 194-194: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


325-325: Avoid assignments within expressions for better clarity

Assigning values within expressions can reduce code clarity and lead to potential errors. It's better to separate the assignments.

Apply this diff:

-      const filename = obj.path = path.join(dir, name);
+      obj.path = path.join(dir, name);
+      const filename = obj.path;
🧰 Tools
🪛 Biome (1.9.4)

[error] 325-325: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

README.md (2)

30-30: Fix bare URL in documentation.

Replace the bare URL with proper markdown link syntax.

-Forked from https://github.com/koajs/static-cache, refactor with TypeScript to support CommonJS and ESM both.
+Forked from [koajs/static-cache](https://github.com/koajs/static-cache), refactored with TypeScript to support both CommonJS and ESM.
🧰 Tools
🪛 Markdownlint (0.37.0)

30-30: null
Bare URL used

(MD034, no-bare-urls)


126-133: Fix grammar in LRU cache documentation.

There's a grammatical error in the LRU cache description.

-You can pass in a lru cache instance which has tow methods: `get(key)` and `set(key, value)`.
+You can pass in an LRU cache instance which has two methods: `get(key)` and `set(key, value)`.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1d964fc and d139402.

📒 Files selected for processing (16)
  • .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)
  • .travis.yml (0 hunks)
  • LICENSE (1 hunks)
  • Makefile (0 hunks)
  • README.md (4 hunks)
  • index.js (1 hunks)
  • package.json (2 hunks)
  • src/index.ts (1 hunks)
  • test/index.js (0 hunks)
  • test/index.test.ts (1 hunks)
  • tsconfig.json (1 hunks)
💤 Files with no reviewable changes (3)
  • .travis.yml
  • test/index.js
  • Makefile
✅ Files skipped from review due to trivial changes (4)
  • .eslintignore
  • .eslintrc
  • LICENSE
  • tsconfig.json
🧰 Additional context used
🪛 Markdownlint (0.37.0)
README.md

30-30: null
Bare URL used

(MD034, no-bare-urls)

🪛 LanguageTool
README.md

[misspelling] ~121-~121: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...ge = 60 * 60 * 24 * 30; ``` #### Using a LRU cache to avoid OOM when dynamic mod...

(EN_A_VS_AN)

🪛 Biome (1.9.4)
src/index.ts

[error] 194-194: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 325-325: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

index.js

[error] 1-1: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 1-1: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 1-1: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 1-1: expected ( but instead found the

Remove the

(parse)


[error] 1-1: expected ; but instead the file ends

the file ends here

(parse)

⏰ 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 (5)
.gitignore (1)

10-11: Reconsider ignoring package lock files.

It's generally recommended to commit the package-lock.json file to version control as it ensures consistent dependency installations across different environments and helps prevent "works on my machine" issues.

test/index.test.ts (1)

1-611: Comprehensive and well-structured test suite

The test cases are thorough and cover a wide range of scenarios, ensuring robust validation of the middleware's functionality.

.github/workflows/nodejs.yml (1)

1-16: LGTM! Well-structured CI workflow.

The workflow configuration is properly set up with:

  • Appropriate Node.js versions (18.19.0, 20, 22) aligning with the new version requirements
  • Integration with CodeCov for test coverage reporting
  • Reuse of standardized workflow from node-modules/github-actions
package.json (2)

67-79: LGTM! Well-structured dual module configuration.

The exports field is correctly configured to support both ESM and CommonJS:

  • Proper type definitions for both formats
  • Correct entry points for both module systems
  • Package.json exports are properly mapped

26-29: Verify dependency version constraints.

The dependencies use caret ranges which could lead to compatibility issues:

✅ Verification successful

Dependencies are using appropriate version constraints

All dependencies are using their latest versions with caret ranges, which is the recommended approach for Node.js packages. This allows for compatible minor version updates while preventing breaking changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for known vulnerabilities in dependencies
npm audit --json | jq '.advisories'

# Check latest versions of dependencies
echo "Current vs Latest versions:"
for pkg in compressible fs-readdir-recursive mime-types utility; do
  current=$(npm view $pkg version)
  echo "$pkg: ^2.0.18 vs $current"
done

Length of output: 1207

@codecov
Copy link

codecov bot commented Jan 12, 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: 0

🧹 Nitpick comments (3)
src/index.ts (3)

325-325: Improve readability by separating assignment.

The assignment within the expression can be confusing and harder to maintain.

-  const filename = obj.path = path.join(dir, name);
+  obj.path = path.join(dir, name);
+  const filename = obj.path;
🧰 Tools
🪛 Biome (1.9.4)

[error] 325-325: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


194-196: Use optional chaining for safer alias access.

Replace the conditional check with optional chaining for better TypeScript idioms.

-  if (options.alias && options.alias[filename]) {
-    filename = options.alias[filename];
+  const aliasPath = options.alias?.[filename];
+  if (aliasPath) {
+    filename = aliasPath;
   }
🧰 Tools
🪛 Biome (1.9.4)

[error] 194-194: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


319-341: Consider using async file operations for better performance.

The loadFile function uses synchronous file operations (statSync, readFileSync) which could block the event loop for large files.

Consider refactoring to use async operations:

-function loadFile(name: string, dir: string, options: Options, fileManager: FileManager) {
+async function loadFile(name: string, dir: string, options: Options, fileManager: FileManager) {
   const pathname = path.normalize(path.join(options.prefix!, name));
   if (!fileManager.get(pathname)) {
     fileManager.set(pathname, {});
   }
   const obj = fileManager.get(pathname) as FileMeta;
   const filename = obj.path = path.join(dir, name);
-  const stats = statSync(filename);
-  const buffer = readFileSync(filename);
+  const stats = await fs.stat(filename);
+  const buffer = await fs.readFile(filename);
🧰 Tools
🪛 Biome (1.9.4)

[error] 325-325: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 36cc8e9 and 8cb3cbd.

📒 Files selected for processing (1)
  • src/index.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/index.ts

[error] 194-194: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 325-325: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

🪛 GitHub Check: codecov/patch
src/index.ts

[warning] 210-211: src/index.ts#L210-L211
Added lines #L210 - L211 were not covered by tests


[warning] 218-219: src/index.ts#L218-L219
Added lines #L218 - L219 were not covered by tests


[warning] 263-270: src/index.ts#L263-L270
Added lines #L263 - L270 were not covered by tests


[warning] 282-283: src/index.ts#L282-L283
Added lines #L282 - L283 were not covered by tests

⏰ 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 (4)
src/index.ts (4)

1-103: Well-structured imports and type definitions!

Good practices observed:

  • Using 'node:' prefix for Node.js built-in modules
  • Comprehensive TypeScript interfaces with JSDoc documentation
  • Clear separation of concerns in type definitions

107-129: LGTM! Clean abstraction for file storage.

The FileManager class provides a good abstraction over different storage mechanisms.


254-254: Avoid using the deprecated 'Content-MD5' HTTP header

The Content-MD5 header is deprecated in HTTP/1.1 and is not recommended for use.


210-211: Improve test coverage for error handling paths.

Several critical code paths lack test coverage:

  • Path prefix validation (L210-211)
  • Directory traversal protection (L218-219)
  • Gzip response handling (L263-270)
  • Pre-compiled gzip handling (L282-283)

Would you like me to help generate test cases for these uncovered scenarios?

Also applies to: 218-219, 263-270, 282-283

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 210-211: src/index.ts#L210-L211
Added lines #L210 - L211 were not covered by tests

@fengmk2 fengmk2 merged commit b0524d9 into master Jan 12, 2025
18 checks passed
@fengmk2 fengmk2 deleted the egg-v4 branch January 12, 2025 13:58
fengmk2 pushed a commit that referenced this pull request Jan 12, 2025
[skip ci]

## [6.0.0](v5.1.4...v6.0.0) (2025-01-12)

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

- **New Features**
	- Added static cache middleware for Koa.
	- Introduced TypeScript support for the package.
	- Implemented comprehensive configuration for package management.

- **Infrastructure**
	- Updated GitHub Actions workflows for CI/CD.
	- Added ESLint configuration.
	- Updated project build and testing configurations.

- **Documentation**
	- Refreshed README with new badges and installation instructions.
	- Updated package description and licensing.

- **Maintenance**
	- Upgraded Node.js engine support to version 18.19.0+.
	- Migrated package to `@eggjs/koa-static-cache`.
	- Removed legacy Travis CI configuration.
	- Added new TypeScript configuration file.
- Removed unnecessary files and configurations, streamlining the project
structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

### Features

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

2 participants