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

fix: try resolve by file no matter dir exists or not #30

Merged
merged 3 commits into from
Dec 25, 2024
Merged

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Dec 25, 2024

Summary by CodeRabbit

  • New Features
    • Introduced module exports in app.js and router.js for future enhancements.
  • Bug Fixes
    • Improved module resolution logic for absolute and relative file paths.
    • Enhanced error handling for module resolution.
  • Tests
    • Added test cases for importResolve() to verify functionality with package.json and file path resolutions.
  • Chores
    • Updated dependencies in package.json.
    • Removed outdated CI workflows for Node.js 14 and 16.

Copy link

vercel bot commented Dec 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
egg-utils ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 25, 2024 2:49pm

Copy link

coderabbitai bot commented Dec 25, 2024

Warning

Rate limit exceeded

@fengmk2 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 54 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 25ef6b5 and 5859509.

📒 Files selected for processing (1)
  • package.json (1 hunks)

Walkthrough

The pull request introduces modifications to the module resolution process in src/import.ts, enhancing the importResolve function's logic for handling different file paths and module types. The changes improve the function's ability to resolve modules across ESM and CommonJS environments, with more explicit handling of absolute and relative paths, JSON files, and module resolution strategies. Additionally, the PR includes minor updates to test fixtures in the Egg framework, adding placeholder exports to app.js and router.js, and updates to the package.json dependencies.

Changes

File Change Summary
src/import.ts - Updated importResolve function logic for path resolution
- Enhanced handling of absolute/relative paths
- Improved module resolution for different file types and environments
test/fixtures/framework-egg-default/app.js - Added empty object module export
test/fixtures/framework-egg-default/app/router.js - Added empty function module export with app parameter
test/import.test.ts - Added two new test cases for importResolve() function
- Testing package.json and file path resolution scenarios
package.json - Updated dependency from egg-bin to @eggjs/bin
- Updated dependency version from mm 3 to 4
.github/workflows/nodejs-14.yml - Removed Node.js 14 CI workflow
.github/workflows/nodejs-16.yml - Removed Node.js 16 CI workflow
test/framework.test.ts - Updated import statement for mm module to named imports

Poem

🐰 Resolving paths with rabbit might,
Modules dance in ESM's light!
Absolute, relative, JSON's grace,
CodeRabbit's import finds its place.
Hop, hop, resolution's delight! 🌟


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.

@fengmk2 fengmk2 marked this pull request as ready for review December 25, 2024 14:24
Copy link

pkg-pr-new bot commented Dec 25, 2024

Open in Stackblitz

npm i https://pkg.pr.new/eggjs/utils/@eggjs/utils@30

commit: 5859509

Copy link

codecov bot commented Dec 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.34%. Comparing base (daa5edf) to head (5859509).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #30      +/-   ##
==========================================
+ Coverage   87.27%   88.34%   +1.06%     
==========================================
  Files           6        6              
  Lines         605      609       +4     
  Branches       95      100       +5     
==========================================
+ Hits          528      538      +10     
+ Misses         77       71       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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/import.ts (2)

165-169: Ensure consistent fallback logic when resolving files.
You call tryToResolveByDirname first, then tryToResolveFromFile. Consider clarifying what happens if the file name also happens to be a directory or if multiple matches exist. Documenting this behavior would help future maintainers.


173-181: Consider potential ESM JSON imports.
Currently, JSON is exclusively resolved via require if not absolute or if the environment is CommonJS. As of Node 20, ESM supports JSON imports without experimental flags. If you want broader future-proofing, consider allowing ESM’s native JSON import.

test/import.test.ts (1)

38-40: Excellent check for default .js resolution.
This test ensures that a directory path (/path/app) correctly resolves to /path/app.js. You could consider adding variants for .ts or .mjs to expand coverage.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 35d9a0c and d7213ab.

📒 Files selected for processing (4)
  • src/import.ts (1 hunks)
  • test/fixtures/framework-egg-default/app.js (1 hunks)
  • test/fixtures/framework-egg-default/app/router.js (1 hunks)
  • test/import.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • test/fixtures/framework-egg-default/app.js
  • test/fixtures/framework-egg-default/app/router.js
🔇 Additional comments (3)
src/import.ts (2)

154-157: Check Node.js version compatibility for fs.statSync with throwIfNoEntry.
This option was introduced in newer Node.js versions—verify it won’t cause compatibility issues on older runtimes. Otherwise, the stat object will be undefined on missing files, which you already handle with optional chaining.


182-182: Watch out for Windows paths with file:// scheme.
If the resolved path is a Windows drive-based URL, it will start with file:///C:/.... The current string check still works but might be fragile if node changes the scheme format in future releases.

test/import.test.ts (1)

32-36: Good job adding coverage for JSON resolution.
These lines confirm correct path resolution to egg/package.json. Including negative or edge cases (e.g., non-existent JSON) can further bolster test robustness.

Copy link

socket-security bot commented Dec 25, 2024

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

Package New capabilities Transitives Size Publisher
npm/[email protected] None +4 276 kB fengmk2

🚮 Removed packages: npm/[email protected]

View full report↗︎

@fengmk2 fengmk2 merged commit 4605e3a into master Dec 25, 2024
25 checks passed
@fengmk2 fengmk2 deleted the egg-v4 branch December 25, 2024 14:54
fengmk2 pushed a commit that referenced this pull request Dec 25, 2024
[skip ci]

## [4.1.4](v4.1.3...v4.1.4) (2024-12-25)

### Bug Fixes

* try resolve by file no matter dir exists or not ([#30](#30)) ([4605e3a](4605e3a))
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