-
Notifications
You must be signed in to change notification settings - Fork 134
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
RFC: Detecting whether a dependency implements TSDoc #7
Comments
If a given file (e.g. in a local ./typings folder) wants to opt-out of TSDoc or indicate a different flavor, perhaps it could do this using a // directive in the source code (similar to how tslint annotations work). The package.json field would merely set the default for the package folder. |
I'd like to explore possibilities for resilient handling of type definitions from node_modules by default but I see the benefits to explicit flavor declarations. Maybe there could be a minimal, default flavor that minimizes possible parsing confusion. Is there any reason (other than for tsdoc config) that the package.json would already be read? I'm wondering if it would be possible to simplify things by sticking to |
I'd expect tsdoc have only versions and extensions, not "flavours". If it does, will parsers and code editors need to support multiple flavours? And what if I want to write docs supporting multiple flavours? Tsdoc is said to become a standard for doc comments, so parsers and extensions must not have basic incompatibilities, and extensions must find ways to ensure no ambiguities. |
I guess Never the less, giving the tools some kind of metadata about your docs might be beneficial, although talking about |
API Extractor already relies on the package.json file to map files to their associated package. For example, suppose we follow a type alias that points to this file: /home/pgonzal/my-project/node_modules/library1/_node_modules/library2/lib/Widget.d.ts: The algorithm will walk upwards from this path until it finds the nearest package.json file here: /home/pgonzal/my-project/node_modules/library1/_node_modules/library2/package.json ...and then it will understand that the Widget type is part of library2. However, it will not attempt to parse the doc comments to look for
This is a pretty good point actually. If two different tools introduce custom TSDoc tags, then should be possible for both tools to be used on the same source files. How about something like this? "tsdoc": {
"version": "1.1", // <-- we don't need this right away, but might need to introduce it later
"extensions": [ "aedoc", "typedoc" ] // <-- sets of custom tags that are in use in these files
}
One of the goals of TSDoc is that two different tools can add custom tags while sharing a common grammar. However, it's still possible that two different tools might introduce a nonstandard tag called |
An alternative to the The configuration should indicate whether lax or strict mode is being used. In addition to this, additional fields can be used by the consumers (doc generator etc.), such as "excludePrivate", "excludeProtected", logo file etc. |
@dend I would allow both variants. Some people surely prefer that kind of configuration being in the main package.json, others might want it to be in a dedicated file. Also, I can imagine for some project having 2+ tsconfig-files: one for public documentation (some doc generator shall ignore internal/private members) and one for internal documentation with other settings within it. |
@tenry92 what is the benefit of having two ways to configure the same thing? That seems like something that would add unnecessary confusion, and just extra paths to test and debug. Given that we are starting from scratch, this is an opportunity to define one standard way of doing things, instead of trying to solve problems that don't necessarily yet exist. |
@dend Like I said, what if someone needs one configuration for public documentation and one or internal documentation within the same project? |
@tenry92 you could probably do something like:
|
API Extractor 7 eliminates the old analysis engine, which now requires every project to have the This led us to a different idea: What if, as part of the build, API Extractor wrote an output file dist/tsdoc-metadata.json that contains something like this: {
"tsdocVersion": "1.1",
"toolPackages": [
{
"packageName": "@microsoft/tsdoc",
"packageVersion": "0.12.4"
},
{
"packageName": "@microsoft/api-extractor",
"packageVersion": "7.0.0"
}
]
} This file would NOT be added to Git. But it would be published as part of the NPM package. When API Extractor crawls into the package folder for a dependency, it will find the package.json file and then look for dist/tsdoc-metadata.json relative to that folder. If it finds this file, then it can assume the library has TSDoc tags compatible with API Extractor. There are two advantages of this approach:
The loader for this file could be part of the @microsoft/tsdoc library. |
Also, I agree that the concept of "flavors" is a little vague. In this new proposal, we would simply list various tools that were invoked. Presumably these tools define some sort of extensions to the core TSDoc syntax. Knowing which tools were used should generally give enough information about how to parse the files. If additional metadata is needed beyond that (e.g. how the tool was configured), we could allow custom properties for each {
"tsdocVersion": "1.1",
"toolPackages": [
{
"packageName": "@microsoft/tsdoc",
"packageVersion": "0.12.4"
},
{
"packageName": "@microsoft/api-extractor",
"packageVersion": "7.0.0",
"customData": {
"dtsTrimming": "enabled"
}
}
]
} |
Updated to clarify that |
@iclanton pointed out that the my-package/dist/tsdoc-metadata.json includes somewhat arbitrary assumptions about the folder structure. Instead, he suggested the following lookup rules:
|
@pgonzal I like this proposition. I'm currently experimenting with api-extractor on a project that uses |
The resolver of the TSDoc metadata file now follows the following proposal: microsoft/tsdoc#7 (comment) The default location of the generated TSDoc metadata file is inferred as to match the resolver. This behaviour can be overriden in api-extractor.json. Generation of the TSDoc medatadata file can even be disabled.
We recently published an ESLint rule that validates TSDoc syntax. For example it can underline errors as you are authoring code in your editor. The ESLint plugin has similar requirements as the
In PR #1628 @ecraig12345 proposed a way to define custom tags in API Extractor's proprietary config file. However, that wouldn't be easily readable by the ESLint rule. In hindsight, it seems that New Proposal
Thoughts? |
@octogonz About the extend feature, it would be nice to have a support for packages. |
I also want to make it an array so you can use |
After discussing this some more, @iclanton and I realized that
Both scenarios seem legitimate, although It's also worth noting that TypeScript's Thus I'm now thinking that we should rename |
We could also shorten the name from |
😊 Vote for the filename here: https://twitter.com/octogonz_/status/1195793782534393856 |
We went with A config loader was published as |
The resolver of the TSDoc metadata file now follows the following proposal: microsoft/tsdoc#7 (comment) The default location of the generated TSDoc metadata file is inferred as to match the resolver. This behaviour can be overriden in api-extractor.json. Generation of the TSDoc medatadata file can even be disabled.
Consider this example from API Extractor:
This illustrates a couple kinds of cross references:
Widget.render
docs are copied fromIWidget.render
using the{@inheritdoc}
tag. This avoids having to write duplicate documentation.@beta
. For a public release, only the@public
definitions will be included in the generated *.d.ts rollup file; the other definitions are trimmed out. In the above example, the analyzer must report an error because ifIPrepareOptions
gets trimmed, thenWidget.prepare
won't be able to consumer that interface.Now, suppose that IWidget and IPrepareOptions are imported from a separate NPM package called widget-lib. This is no problem -- API Extractor can simply parse the TSDoc comments from this file:
./node_modules/widget-lib/lib/index.d.ts
This seems fine on the surface, but the node_modules folder is full of *.d.ts files that have no awareness of API Extractor. Their doc comments might randomly contain a string such as
@beta
, or they might simply have malformed comments that would normally be reported as a TSDoc error.We need a way to determine whether a given NPM package actually implements TSDoc or not.
Our proposal is to add a custom field
tsdoc
to the package.json file format like this:(Note that the CommonJS spec specifically allows for custom fields.)
Initially, the
tsdoc
block would support a single fieldtsdocFlavor
that helps tooling to recognize custom extensions to the core TSDoc tags. In the future it might include other fields such as a version number. See this file for a real world prototype of this convention.Does this seem like a good design?
The text was updated successfully, but these errors were encountered: