-
Notifications
You must be signed in to change notification settings - Fork 709
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
Support for package exports
map
#1937
Comments
Possibly a duplicate of #1934, which I somehow missed despite looking at all open issues, searching, etc.: and it was right in front of my face! 🤦🏼♂️ Feel free to close/merge with that one as makes sense! (It doesn't overlap 100%, but it may make sense to track in one spot.) |
How about support entryPoints in package.json first, I can live without exports support (not easy) as long as the generated doc contain the def. {
"typedoc": {
"entryPoints": ["./src/index.ts","./src/server.ts"],
"readmeFile": "./README.md"
}
} |
So... I've spent probably a dozen hours poking at this over the past few months... and it's ridiculously complicated. I ran into microsoft/TypeScript#50466 today.
PR welcome |
I'd be willing to take a peek at implmeneting this! Though it appears there's a pending release ( If this takes the |
What is the status of this issue? Is this coming out in |
Not planned for 0.24. I'm not entirely convinced there's a good way of doing this that'll work for more than 50% of packages, at least without requiring a custom resolution mode to tell TD what to use. The problem is mainly projects which ship esm and cjs, and use the exports map to associate different build outputs which each. |
Perhaps then its worth pursuing this pr suggestion. I will work on it if there is no current work ongoing |
The boring answer might just be to always assume |
https://isaacs.github.io/resolve-import/functions/index.resolveAllExports.html will resolve all the valid exports for a given
I'd recommend either just hard-coding the Any module that's exporting multiple versions of a single module is going to have something that resolves with Another approach would be to document both of the exports for a given export module name, and have one at |
Just throwing another idea on the pile: support a specific conditional export. e.g.: {
"name": "my-pkg",
"version": "1.0.0",
"exports": {
".": {
"types": "./dist/index.d.ts",
"typedoc": "./src/index.ts",
"default": "./dist/index.js"
},
"./something": {
"types": "./dist/something.d.ts",
"typedoc": "./src/something.ts",
"default": "./dist/something.js"
}
}
} Grab the entry points that way. |
@boneskull i love this. |
Maybe it would be worthwhile to propose a |
I'm working on a library that has multiple modules per the export * as types from './types'
export * as filter from './filters' and typedoc outputs this: |
The TypeDoc supports multiple entry points, so you could achieve the same output (with Namespaces changed to Modules) by passing both of those files to TypeDoc. |
I have just released a comprehensive solution for this issue: @typhonjs-typedoc/typedoc-pkg. I have created a zero configuration CLI front end for TypeDoc that analyzes
I'd really like to get some stress tests done with a variety of packages, so please give it a go. I'm using I spent the last couple of months working on all of this full time, so it's ready to go. I'd like to collect feedback and I'll be working on more documentation and a wiki in the coming weeks then bump things to The following is docs hosted on Github for @typhonjs-build-test/esm-d-ts: https://typhonjs-node-build-test.github.io/esm-d-ts/ And here are the docs and example of using an export condition ( https://typhonjs-svelte.github.io/trie-search/ In particular you can see the export conditions and the NPM script for generating from TS source. |
If a package uses a "typedoc" conditional export, then TypeDoc will use that. If not provided, TypeDoc will use the "import" and "node" import conditions Resolves #1937
@Gerrit0 thanks for solving this! I know it was not trivial. 🙏🏼 |
Search Terms
exports
Problem
Today, if you use
exports
with TS 4.7 to create a public API that is different from the layout you author in, TypeDoc preserves the authoring API rather than the consuming API.Consider a structure like this:
The
tsconfig.json
specifies anoutDir
ofdist
, resulting in this output:Finally,
package.json
has this:This means that Node consumers (and any tools following its resolution algorithm) can now import not only from the
index.js
but fromother-module
as well:The docs generated by TypeDoc, however, render the modules without reference to the
exports
map inpackage.json
, so you end up with a list of modules like this:public
public/other-module
For a real-world example of this, see True Myth and its docs.
Suggested Solution
The resolved module map should follow the resolution algorithm from
exports
inpackage.json
the way TS itself does, so that the resolved module name is based on the mapping defined there.Note: I know 4.7 came out literally this week, and that this is likely non-trivial! Just figured I'd write it up to get it here so if folks search they will see that it's open.
The text was updated successfully, but these errors were encountered: