-
Notifications
You must be signed in to change notification settings - Fork 1
feat: support cjs and esm both by tshy #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
Conversation
BREAKING CHANGE: drop Node.js < 18.19.0 support part of eggjs/egg#3644 eggjs/egg#5257
|
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 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. 📒 Files selected for processing (2)
WalkthroughThis pull request represents a comprehensive refactoring and modernization of the Changes
Sequence DiagramsequenceDiagram
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
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Updated and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 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 |
commit: |
There was a problem hiding this 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.dbsrc/index.ts (2)
194-194: Simplify conditional logic using optional chainingTo 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 clarityAssigning 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
📒 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.jsonfile 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 suiteThe 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" doneLength of output: 1207
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 ☂️ |
There was a problem hiding this 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
loadFilefunction 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
📒 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 headerThe
Content-MD5header 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
[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))
BREAKING CHANGE: drop Node.js < 18.19.0 support
part of eggjs/egg#3644
eggjs/egg#5257
Summary by CodeRabbit
New Features
Infrastructure
Documentation
Maintenance
@eggjs/koa-static-cache.