egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
8.48k stars 209 forks source link

Correct way to bundle dependencies types in generated .d.ts #1071

Open sachaw opened 6 months ago

sachaw commented 6 months ago

Hi, My library: https://github.com/meshtastic/js bundles one of it's dependencies as it comes from another package registry, this part is working, however I need the dependencies types to also be bundled.

My library re-exports the dependency as follows:

export * as Admin from "@buf/meshtastic_protobufs.bufbuild_es/meshtastic/admin_pb.js";

The JS code is correctly bundled, but the generated .d.ts file still has an import from the original dependency that is not resolved when using the library:

import * as config_pb_js from '@buf/meshtastic_protobufs.bufbuild_es/meshtastic/config_pb.js';

Upvote & Fund

Fund with Polar

seriouslag commented 2 months ago

You should mark the needed types package as a peerDependency of the package you are importing. Re-exporting a type does not mean you pull the type into your package, re-exporting a type gives a nice API to reference said type.