-
Notifications
You must be signed in to change notification settings - Fork 13
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 import typescript files first at dev env #26
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe pull request introduces enhancements to module resolution and TypeScript support in the Changes
Sequence DiagramsequenceDiagram
participant Caller
participant importResolve
participant getRequire
participant isSupportTypeScript
participant FileSystem
Caller->>importResolve: Call with filepath
importResolve->>getRequire: Get custom require
getRequire-->>importResolve: Return require
importResolve->>isSupportTypeScript: Check TypeScript support
isSupportTypeScript-->>importResolve: Return support status
importResolve->>FileSystem: Check file existence
FileSystem-->>importResolve: Return file info
importResolve-->>Caller: Return resolved module path
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 (
|
commit: |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #26 +/- ##
==========================================
+ Coverage 86.81% 87.65% +0.83%
==========================================
Files 6 6
Lines 440 478 +38
Branches 54 63 +9
==========================================
+ Hits 382 419 +37
- Misses 58 59 +1 ☔ View full report in Codecov by Sentry. |
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 (4)
src/import.ts (2)
31-39
: Consider extending TypeScript support detection.
Currently, this only checks for '.ts' in require.extensions but ignores '.mts', '.cts', or '.tsx'. If your project expects to handle these additional TS extensions, you should incorporate them.
44-63
: Handle potential package.json parse errors.
When reading package.json, a malformed file may cause JSON.parse() to throw an error, which could disrupt your import logic. Consider adding a try/catch to log or handle parse failures gracefully.const pkgFile = path.join(filepath, 'package.json'); if (fs.existsSync(pkgFile)) { - const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf-8')); + let pkg; + try { + pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf-8')); + } catch (err) { + debug('[importResolve] failed to parse package.json in %o, error: %o', pkgFile, err); + return getRequire().resolve(filepath, { paths }); + } const mainIndexFile = pkg.tshy?.exports?.['.']; ...test/fixtures/tshy/src/index.ts (1)
1-3
: Empty classes could benefit from documentation or implementation details.
If Application and Agent need more functionality or clarity, consider adding basic methods or docstrings explaining their purpose.test/import.test.ts (1)
111-125
: Comprehensive test for TS fixture import.
This test checks the entire export set from the TypeScript fixture, including classes, constants, and default exports, providing excellent validation for TS import behavior. Consider adding a negative/invalid-case test if you want to confirm error handling.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/import.ts
(2 hunks)src/plugin.ts
(1 hunks)test/fixtures/tshy/package.json
(1 hunks)test/fixtures/tshy/src/index.ts
(1 hunks)test/import.test.ts
(2 hunks)
✅ Files skipped from review due to trivial changes (2)
- test/fixtures/tshy/package.json
- src/plugin.ts
🔇 Additional comments (5)
src/import.ts (3)
4-5
: Additions of 'node:path' and 'node:fs' imports look good.
These imports are necessary for path resolution and file system checks. No issues found.
20-29
: Efficient fallback for customRequire.
Using createRequire(process.cwd()) is a practical fallback when require is undefined in an ESM environment. This approach is concise and handles multiple runtime contexts gracefully.
41-43
: TS import resolution on absolute paths is clear.
The condition ensuring isSupportTypeScript() for absolute paths is straightforward and helps avoid attempts to import TS files when TS is not available.
test/fixtures/tshy/src/index.ts (1)
5-9
: Exported default object and constant look good.
The default export pattern here is straightforward, and exporting the constant one allows clear usage in test code. No issues found.
test/import.test.ts (1)
15-17
: Good test coverage for TypeScript resolution.
Verifying that importResolve correctly interprets the TypeScript entry point (tshy/src/index.ts) ensures your new TS import logic works as intended.
[skip ci] ## [4.1.0](v4.0.3...v4.1.0) (2024-12-23) ### Features * support import typescript files first at dev env ([#26](#26)) ([349c0c3](349c0c3))
Summary by CodeRabbit
New Features
Application
,Agent
) and an asynchronous function (startCluster
) in the project.package.json
for improved module resolution and export management.Bug Fixes
Tests