egoist / egoist/tsup

tsup dts doesn't follow source structure

Open
#1,010 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

While using dts in tsup, there seems to be that all built declaration files are bundled into one file.
What I am expecting that the generated dts structure follows the source structures.

For example, if my source structure looks like this,

![image](https://github.com/egoist/tsup/assets/38908080/64716324-f3f0-4eed-a32c-b620ee87cd3d)

And the `src/index.ts` file exports all of them like this

```tsx
export {
Badge,
Button,
} from './components
```

My expectation of dts is creating separted `d.ts` files like this.

![image](https://github.com/egoist/tsup/assets/38908080/68cfb24a-4328-4b52-842d-4c84e857e8d4)

However, by applying the dts of tsup, it creates only a single of `.d.ts` file not following above source structure. What I knew that [vite-plugin-dts](https://github.com/qmhc/vite-plugin-dts) is following the source structure like above example.

Is there any way to follow source structure of `dts` in `tsup`?
Or Is this single `d.ts` creation behavior intended for specific reason?

My tsup config that creates a single `d.ts` is as follows.

```ts
import { defineConfig } from 'tsup';
import { TsconfigPathsPlugin } from '@esbuild-plugins/tsconfig-paths';
import { vanillaExtractPlugin } from '@vanilla-extract/esbuild-plugin';

// @ts-expect-error
export default defineConfig((options) => ({
entry: ['src/index.ts'],
outDir: 'dist',
format: ['esm', 'cjs'],
dts: true,
external: ['react', 'react-dom'],
clean: true,
splitting: false,
bundle: true,
minify: !options.watch,
sourcemap: options.watch,
plugins: [
TsconfigPathsPlugin({
tsconfig: './tsconfig.json',
}),
],
esbuildPlugins: [vanillaExtractPlugin()],
}));

```

Contributor guide

Open the contributing guide

Research direction

Reproduce the declaration output from the shown tsup config, beginning at the src/index.ts entry point and its re-exports. Determine whether dts with bundle: true is intended to emit one file or should preserve source structure; done should be a documented, tested behavior matching the chosen output.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.