-
Notifications
You must be signed in to change notification settings - Fork 31
feat: support ESM export for extend #108
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
base: master
Are you sure you want to change the base?
Conversation
we detect ts file content,and generate import * as xx from "file" when module just has export.
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.
Pull Request Overview
This PR adds support for ESM exports in the extend generator by detecting when a file contains only named exports (no default export) and generating appropriate import statements.
- Detects files with only named exports using a new
hasExportWithoutDefaulthelper function - Updates import statement generation to use namespace imports (
import * as) when appropriate - Modifies test fixture to use named exports instead of default export
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/generators/extend.ts | Adds export detection logic and updates import generation to handle named exports |
| test/fixtures/app/app/extend/helper.ts | Converts from default export to named exports for testing |
| test/generators/extend.test.ts | Updates test assertions to match new import patterns |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
WalkthroughIntroduces per-file import construction in ExtendGenerator by detecting default vs. named exports via a new helper. Updates test fixture helper to use named exports. Adjusts generator tests to assert on generated import statements (star vs. default) rather than raw paths. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant EG as ExtendGenerator
participant FS as File System
participant U as utils.getImportStr
participant Out as Generated Declarations
EG->>FS: Read target file
EG->>EG: hasExportWithoutDefault(filePath)
alt No default export detected
EG->>U: getImportStr(path, alias, type, useImportStar=true)
else Default export present
EG->>U: getImportStr(path, alias, type, useImportStar=false)
end
U-->>EG: Import statement string
EG->>Out: Write import + context
note over Out: Output varies between<br/>import * as X ... vs. import X ...
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used🧬 Code graph analysis (1)test/fixtures/app/app/extend/helper.ts (1)
🔇 Additional comments (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
egg-ts-helper doesn't support code like this:
because egg-ts-helper generator d.ts file with content
import xx from "./file"and xx mead defaultExport.In this case, What we need is
import * as xx from "./file".this PR detect code, and generate
import * as xx from "./file"when code just hasexport(not export defualt)Summary by CodeRabbit
New Features
Tests