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
tsc out-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 example emitDeclarationOnly) so that it generates declaration files on a temp directory
- Call
api-extractor run with the entry in temp
- Delete the
temp directory (and all the other unused artifacts of api-extractor such as dist/tsdoc-metadata.json)
This is quite involved. With the proposed change, this is how they would do it:
- Call
api-extractor run with the entry as their main .ts file
- 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 example emitDeclarationOnly) so that it generates declaration files on a temp directory
- Call
api-extractor run with the entry in temp (publishFolder is set to be the published directory and typings in package.json points to the generated .d.ts file)
- Delete the
temp directory
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 run with the entry as their main .ts file (publishFolder is set to be the published directory and typings in package.json points to the generated .d.ts file)
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.
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
tscwithemitDeclarationOnlyas 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
.tsfile (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:
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:
tsc(with for exampleemitDeclarationOnly) so that it generates declaration files on atempdirectoryapi-extractor runwith the entry intemptempdirectory (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:
api-extractor runwith the entry as their main.tsfileMuch simpler.
Libraries
TypeScript libraries already generate declaration files. But they may not want to if the two following conditions are met:
Without api-extractor,
tscis called anyway (probably withemitDeclarationOnly) and the relevant.d.tsfile is exposed intypings. However, with api-extractor and dts rollup, the process would look like this:tsc(with for exampleemitDeclarationOnly) so that it generates declaration files on atempdirectoryapi-extractor runwith the entry intemp(publishFolderis set to be the published directory andtypingsinpackage.jsonpoints to the generated.d.tsfile)tempdirectoryThis is the same burden as with the first use case. With the proposed change, this is how they would do it:
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.
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.