Support rewriting specifiers in dynamic imports for `transform` entry mode
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 432
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
Describe the feature
Hi!
I was trying the transform entry type and noticed that import specifier rewriting works for static imports, but not for dynamic imports.
Example setup:
src/hello-world.ts
export default () => {
return "hello-world";
};
src/index.ts
const { default: helloWorld } = await import("./hello-world.ts");
console.log(helloWorld());
build.config.ts
import { defineBuildConfig } from "obuild/config";
export default defineBuildConfig({
entries: [
{
type: "transform",
input: "./src",
outDir: "./dist",
dts: false
}
]
});
The generated output in dist/index.mjs dynamic import remains:
await import("./hello-world.ts");
instead of:
await import("./hello-world.mjs");
Even though dist/hello-world.mjs file was generated.
I was wondering if dynamic imports are intentionally excluded, if they are I may be completely wrong here.
Would you be open to adding support for rewriting dynamic import specifiers as well? For example, adding a TransformEntry option like:
rewriteDynamicImportExtensions: true
(or another name that better fits) could enable transforming .ts extensions from dynamic imports
Solution
I tried implementing this change in a fork, it worked for me but I'm not an expert in build tools so I'm not sure if this'd be the right approach as it only rewrites string literals
Thanks!
Additional information
- Would you be willing to help implement this feature?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/builders/transform.ts around the linked lines and compare how static import specifiers are rewritten with the dynamic-import case. Use the provided src/index.ts, src/hello-world.ts, and build.config.ts example to check the generated dist/index.mjs. Done means the dynamic import points to the generated .mjs file while preserving existing transform behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100