Tools comparisson (dts-bundle-generator, api-extractor, rollup-plugin-dts, npm-dts) #68
Replies: 39 comments 6 replies
-
Hi @pgonzal, thank you for your interest in the project! After slight looking up I see the next differences:
Correct me if I were wrong somewhere about |
Beta Was this translation helpful? Give feedback.
-
Thanks for writing up this comparison! It's very interesting.
Right, API Extractor processes .d.ts files instead of .ts files. This supports the usage of preprocessors (e.g. a .js -> .d.ts generator), and also simplifies the processing that we do, since .d.ts files are in a simplified normalized form.
What do you mean by "follow dependencies"? For locally referenced files
This requirement can be disabled in the config file.
Wow, thanks for pointing this out! We overlooked it for a long time. :-)
API Extractor installs with a specific (very recent) TypeScript package that it uses for its own analysis, but this is typically different from the version that your project builds with. For example when processing a 2.6.1 project, it can use the 2.6.1 runtime library typings while still invoking the 3.1 engine.
Yeah the configuration is a weak area, since in our own usage at Microsoft, all the projects are in a huge monorepo with a standardized configuration, so nobody customizes the configuration directly. The external community has complained about this, and it's a high priority to improve the configuration and make it more flexible.
That's true. The analyzer engine partially models path-based entry points, but they are very difficult to support in general. (How should a documentation web site represent them? When generating a .d.ts rollup, where do you emit common local declarations that are shared by two different entry points?) |
Beta Was this translation helpful? Give feedback.
-
AFAIK some
Oh, great! It is quite possible that I just didn't get it work in a proper way 🙁
👌 Will know, thanks!
In my case, I've tried to run in a project with 3.2.1 TypeScript, and it tried to use
Another, but the similar opinion about configuration - https://github.com/Swatinem/rollup-plugin-dts#why.
What do you mean "documentation web site"? It is about the documentation site, which your tool generates? If so, I don't know the answer 🙁 In my case I just pointing to separate (not main) file in docs (see JS file example).
I haven't think about it yet deeply, but it is possible, that it is not a big problem in a common case. In a project where I'm working on we generate 3 different d.ts bundles (and there is a lot of code in a common between them), and it seems that everything is ok for now with that. |
Beta Was this translation helpful? Give feedback.
-
It sounds like a good new issue 🙂 #69 |
Beta Was this translation helpful? Give feedback.
-
@pgonzal also we can compare generated output. I think a test cases would be fine for that (for example run |
Beta Was this translation helpful? Give feedback.
-
Hi, and let me also chime in as the maintainer of rollup-plugin-dts As I have also mentioned in my README, I have tried So I have nothing to actually compare the output quality and differences, like @timocov asked me to here: Swatinem/rollup-plugin-dts#5 But apart from the configuration issue that was already mentioned, my biggest beef is that it requires me to create intermediate output in the form of pre-rollup Also concerning 4., I recently found out that |
Beta Was this translation helpful? Give feedback.
-
/**
* For more info, please email [email protected]
*/
export class Base {
}
export class Child extends Base {
} ...it would strip
This is useful feedback. Thanks!
It would be possible to pass these as in-memory data structures rather than writing them to disk. Someone else proposed this in microsoft/rushstack#1010. (It's not a very high priority for me personally, since from an opposite perspective I find it frustrating to work with a "black box" where you can't easily inspect the intermediary stages of the build. Also, I haven't seen significant perf benefits from skipping disk writes; if anything it would make incremental builds less feasible. But this feature is useful, so we should implement it.) |
Beta Was this translation helpful? Give feedback.
-
puh, that is definitely something that has to be fixed upstream then.
Those are definitely valid points. Luckily, when you create small focused libraries, perf is not a problem. Regarding configuration, I personally would like things to be as zero-config as possible. Also related to that, the intermediate artifacts themselves are not the problem. Its rather that you have to manage those yourself. To my own shame, I also didn’t yet understand how to correctly work with TS project references. At work we have a codebase of ~2700 ts files (a lot of those come from external dependencies) and quickly growing. Typechecking times (and IDE performance) are already a pain that I would like to solve somehow. |
Beta Was this translation helpful? Give feedback.
-
I just found dts-generator by SitePen. cc @dylans Could you explain how your package differs from the others mentioned in this thread? 😄 |
Beta Was this translation helpful? Give feedback.
-
BTW, I also did a really quick research around this topic and I found https://github.com/TypeStrong/dts-bundle, but the latest commit was 2 years ago so this seems pretty dead to me. |
Beta Was this translation helpful? Give feedback.
-
There is also https://github.com/nomaed/dts-builder. |
Beta Was this translation helpful? Give feedback.
-
Hello there! Let me also hop in with npm-dts module I have put together to make it easy with some use cases. Basically I was a user of dts-generator and encountered a problem at some point (SitePen/dts-generator#121). After trying to solve it for a while I decided to write a simple tool myself which would have less mandatory command-line arguments and would work for my use case. I tried to make this tool as simple as possible to make it easy to maintain. Added logging with configurable log levels to make it easier to understand what is happening. And well, tried to keep it's source, CLI and docs as tidy as it was viable. My use case was to pre-bundle several npm libraries (excluding sub-dependencies of course) and generate index.d.ts file for each of those library bundles so that I would still have full TS support when consuming them even though initial src was not uploaded during publishing. Quick summary based on discussion points above:
It also has a webpack plugin and can be executed from another JS script as a dependency. If it works for you, feel free to use it. If not - use other generators :) Aaaand feel free to leave feedback, especially if something does not work as expected. |
Beta Was this translation helpful? Give feedback.
-
import dts from "rollup-plugin-dts";
import rts2 from "rollup-plugin-typescript2";
export default [
{ // TypeScript
input: "src/index.ts",
output: [
{file: "lib/index.js", format: "cjs"},
{file: "lib/index.mjs", format: "esm"},
],
plugins: [
rts2({
cacheRoot: "out/.rts2_cache",
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
declarationDir: "out/.dts",
},
},
}),
],
},
{ // TypeScript Type Definitions
input: "out/.dts/index.d.ts",
plugins: [dts()],
output: {file: "lib/index.d.ts", format: "esm"},
},
]; PS: No docs yet, only comments in .d.ts, but it basically relies on the package.json structure to bundle a NodeJS library: entry point, .d.ts bundle and executable bin scripts. Of course it use itself to build itself. |
Beta Was this translation helpful? Give feedback.
-
@gavar can you please tell what features/abilities you didn't find in other tools (like api-extractor or dts-bundle-generator), but they are in |
Beta Was this translation helpful? Give feedback.
-
I also recently found a lot more issues with my tool, which are due to the way typescript works:
I still hope that this usecase will be implemented in typescript properly, which would make all of these tools obsolete. |
Beta Was this translation helpful? Give feedback.
-
User for api-extractor here.
My recomendation:
|
Beta Was this translation helpful? Give feedback.
-
I would really like to use dts-bundle-generator but I used a monorepo, which means the bundler I choose should support composite project. It seems that dts-bunder-generator doesn't. I wonder which library above does. |
Beta Was this translation helpful? Give feedback.
-
Good thread. However, I am searching for the proper tool for a situation where I need to bundle all types from external dependencies as well, with proper name-conflict resolution. Since these are areas where all the mentioned tools seem to be outright avoiding or not guaranteeing proper functionality, can I ask for any recommendations / suggestions? |
Beta Was this translation helpful? Give feedback.
-
@loreanvictor when and where it would be needed? Can you please elaborate why do you need this (with examples if possible)? |
Beta Was this translation helpful? Give feedback.
-
@timocov I need it for this project. Basically, I'm wrapping some TypeScript functions automatically into API endpoints, and then transferring the type definitions of these functions to the client-side for auto-generating an SDK for said API. The type definitions will sit alongside some auto-generated This works pretty smoothly except for situations where the API functions rely on types from dependencies, as in this situation the client would also need to have the dependencies installed (or at least, the corresponding types installed). Current work-around is avoiding such types in the API functions, which is not ideal as it bars re-using recurring types. The alternative would be to also include all types that the API functions are dependent on in the bundle automatically. P.s. on revisiting my comment I see that it can be read as "collecting all types exported from all dependencies in a blanket manner and add them to the bundle", but thats not what I meant. I basically need to create type-bundles with zero external dependencies. |
Beta Was this translation helpful? Give feedback.
-
So I think rollup-plugin-dts should be up for the task. Although I absolutely do not recommend it, I know that a few people use it to bundle up all external dependencies as well, and it will happily take care of name conflicts and everything. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@Swatinem may I ask why? |
Beta Was this translation helpful? Give feedback.
-
@adventure-yunfei yeah it seems that similar to dts-bundle-generator, you can only specify a few select external libraries and it will bundle types exported from them (i.e. I could not find the |
Beta Was this translation helpful? Give feedback.
-
Its just that some |
Beta Was this translation helpful? Give feedback.
-
makes sense. tbh, if there was a way to just install types of a package, the cleanest solution for my case would also be simply installing all types as explicit dependencies of the client SDK instead of bundling them all together. question though: since this pitfall affects mostly |
Beta Was this translation helpful? Give feedback.
-
when using |
Beta Was this translation helpful? Give feedback.
-
Hello! Let me introduce a new member of the family: rollup-plugin-flat-dts. Probably the dumbest one :), but good reliable worker. Instead of trying to be "smart" while merging
This algorithm applies severe limitations to the code base:
Surprisingly, I had to adjust only one project's structure out of a few dozens I maintain. The rest of the projects already suit the requirements. So, these limitations did not cause any troubles. Multiple Entry PointsOne important feature causing me to develop this tool is a multiple entry points support. Some tools like API extractor do not support it intentionally.
In contrast, rollup-plugin-flat-dts allows to specify which type definitions belong to which module. And then either merge them to one file, or put different module type definitions to different files. No extra files generated. Thus, it is possible to establish a one-to-one connection between package entry point and its type definition. This allows IDEs to recognize the imported modules and enable correct autocompletion for them. Also, this prevents incorrect imports. The latter often happens when generating a type definition per source file with ConclusionIn exchange for some limitations, the plugin emits predictable output and grants control over contents of generated type definitions files. I hope this makes it a good tool for library authors like myself. |
Beta Was this translation helpful? Give feedback.
-
@Swatinem thank you very much for rollup-plugin-dts! First I was trying api-extractor, but it does not support
Another downside of api-extractor for me was the requirement to put |
Beta Was this translation helpful? Give feedback.
-
How would I go about bundling |
Beta Was this translation helpful? Give feedback.
-
@timocov FYI we've been working on a tool API Extractor that seems to have similar goals to dts-bundle-generator. It might be interesting to compare the features and goals of the two projects, and see if anything can be shared between them.
Beta Was this translation helpful? Give feedback.
All reactions