Repository navigation
fix: add "types" field to subpath exports map generation - #307
YangJonghun wants to merge 7 commits into
Conversation
✅ Deploy Preview for tsdown ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| } | ||
| if (es) value[dualFormat ? 'import' : 'default'] = es | ||
| if (cjs) value[dualFormat ? 'require' : 'default'] = cjs | ||
| if (cjsTypes || esmTypes) value.types = cjsTypes || esmTypes |
There was a problem hiding this comment.
types should precede import or require.
| if (chunk.facadeModuleId && !subExport.src) { | ||
| subExport.src = `./${slash(path.relative(pkgRoot, chunk.facadeModuleId))}` | ||
| } | ||
| } else if (!isIndex && (format === 'cjs' || format === 'es')) { |
|
I think we'd better to have an option for this |
- correct "types" field order
|
@sxzz |
| }, | ||
| "./package.json": "./package.json", | ||
| }, | ||
| ".": "./foo.js", |
There was a problem hiding this comment.
I just added dts with single entry test, and types field should be added here.
There was a problem hiding this comment.
Wouldn't it make sense for the "types" setting to affect the root-level types too?
There was a problem hiding this comment.
In fact, setting exports.types itself doesn't make much difference, since TypeScript will look for .d.ts files based on the .js entry. However, explicitly specifying it may improve resolution speed. Regardless, since we have this option, we should set it for the main entry as well to maintain consistency.
There was a problem hiding this comment.
Thanks for your explanation.
If there's anything else I need to change, please feel free to let me know.
There was a problem hiding this comment.
I mean types field should be added here.
commit: |
|
I'm waiting this feature, it is really helpful, thank you for this work @YangJonghun and @sxzz |
13a67c0 to
8171b96
Compare
04e9d3d to
3b05923
Compare
fc57efe to
4818111
Compare
ecc60c6 to
597d921
Compare
10421f2 to
85c0e55
Compare
|
Will it be easy to add custom conditions to this later (not necessarily in this PR)? That's what I (currently) use to get live types. I've been managing it manually, but it'd be cool if tsdown could do it for me. |
|
Closing this as stale, and |
Description
When developers generate a bundle with multiple entry points, tsdown currently does not automatically generate the "types" field for subpath exports.
For example, if a developer provides the following entries:
tsdown should generate the following exports map:
"exports": { ".": { "import": { "types": "./index.d.ts", "default": "./index.js" }, "require": { "types": "./index.d.cts", "default": "./index.cjs" } }, "./foo": { "import": { "types": "./foo.d.ts", "default": "./foo.js" }, "require": { "types": "./foo.d.cts", "default": "./foo.cjs" } }, "./package.json": "./package.json", }, "main": "./index.cjs", "module": "./index.js", "types": "./index.d.cts",Linked Issues
closes #253
Additional context