Two scenarios:
A. A monorepo such as a PNPM workspace with a backend and a client. The backend will never be published as a package, being internal. The client, that will be published, uses types from the backend.
B. A library that only uses some types from a large external package, not using any of its javascript code. It would be a waste to force the end-user to install all of the code. Besides “package size”, it’s easy to think of other reasons, e.g. “package is hard to install in certain runtimes (WASM, etc)”.
In each of these, we would like to bundle those types that we are using with our package.
api-extractor
seems a common tool, but only bundles the types one level deep. If the type we’re uses a type imported from elsewhere, this doesn’t do what we’re looking for.
dts-bundle-generator
requires the packages to be installed as dependencies
. Now it might be possible to 1. Install the packages with the types as dependencies 2. Use dts-bundle-generator
to bundle the types 3. Remove the packages from dependencies, but this seems very convoluted.
Given that both scenarios (especially A) don’t feel absurdly rare, there must be some industry-standard way to accomplish this. What is it?
jjh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.