-
Notifications
You must be signed in to change notification settings - Fork 657
Description
This is a feature request.
Proposed change
Currently api-extractor requires that we use the typescript compiler to generate our declarations first. Then, api-extractor reads those declarations and does its magic.
My proposal is instead to run tsc with emitDeclarationOnly as a preliminary step. The files emitted would be written to an in-memory filesystem plugged by api-extractor. Those files would then be read from that in-memory filesystem to follow the extraction process.
I have no opinion on how this behaviour is to be triggered. It can be through the configuration file, the command line or by noticing that the entry file is a .ts file (not a .d.ts). Obviously the current behaviour would stay the default.
Motivation
In the wild, a lot of projects don't use the typescript compiler directly. Some use webpack loaders, rollup plugins, babel or ts-node, but specific tools are irrelevant to the discussion.
In this situation there can be either of two cases:
- There is no generation of declaration files (the Applications use case), or
- Declaration files are generated with
tscout-of-band on a published directory (the Libraries use case)
Applications
Applications don't usually generate declarations files. However they may still want to use api-extractor as it provides the facilities to automatically generate an internal documentation.
This is how applications that use third-party loaders or transpilers such as the one listed above would do it currently:
- Call
tsc(with for exampleemitDeclarationOnly) so that it generates declaration files on atempdirectory - Call
api-extractor runwith the entry intemp - Delete the
tempdirectory (and all the other unused artifacts of api-extractor such asdist/tsdoc-metadata.json)
This is quite involved. With the proposed change, this is how they would do it:
- Call
api-extractor runwith the entry as their main.tsfile - Delete unused artifacts of api-extractor
Much simpler.
Libraries
TypeScript libraries already generate declaration files. But they may not want to if the two following conditions are met:
- TypeScript is not directly used to generate the distributed bundles
- The project would benefit from dts rollup
Without api-extractor, tsc is called anyway (probably with emitDeclarationOnly) and the relevant .d.ts file is exposed in typings. However, with api-extractor and dts rollup, the process would look like this:
- Call
tsc(with for exampleemitDeclarationOnly) so that it generates declaration files on atempdirectory - Call
api-extractor runwith the entry intemp(publishFolderis set to be the published directory andtypingsinpackage.jsonpoints to the generated.d.tsfile) - Delete the
tempdirectory
This is the same burden as with the first use case. With the proposed change, this is how they would do it:
- Call
api-extractor runwith the entry as their main.tsfile (publishFolderis set to be the published directory andtypingsinpackage.jsonpoints to the generated.d.tsfile)
That's it! Just one step, like before.
Making a Pull Request
If you approve this proposal I'd like to try a PR.
The files emitted would be written to an in-memory filesystem plugged by api-extractor
This is what makes sense to me but I suppose that if typescript exposes the proper data structure and if we are able to resolve references through it an actual in-memory filesystem would be overkill.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status