egoist / tsup

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

Generated declaration file has incorrect imports #943

Open lachlancollins opened 1 year ago

lachlancollins commented 1 year ago

Hi there, thanks for creating such an incredible package! I've been trying to setup tsup in the TanStack Query alpha branch, and seem to have an issue generating .d.ts files - I've just been falling back to tsc (not ideal, especially with the 7.1.0 improvement for ESM/CJS).

In particular, I'm having issues configuring @tanstack/eslint-plugin-query.

tsup.config.js

export default defineConfig({
  entry: ['src/index.ts'],
  format: ['cjs', 'esm'],
  target: ['es2020', 'node16'],
  outDir: 'build/lib',
  external: [/eslint/],
  dts: true, // Add this to generate the code below
  sourcemap: true,
  clean: true,
})

After running pnpm run build:tsup with dts enabled in config:

build/lib/index.d.ts

export { configs } from './configs/index.ts';
export { rules } from './rules/index.ts';

For some reason, it is outputting relative links to .ts files which don't exist in the build directory. I wonder if this is something to do with the entry field? Any help would be much appreciated!

Upvote & Fund

Fund with Polar

lachlancollins commented 1 year ago

Hi, I have an update on this: when I remove external: [/eslint/],, the correct types get generated. I think this is because the only types emitted require imports from @typescript-eslint/utils.

I thought the expected behaviour would be that it preserves imports from @typescript-eslint/utils in declaration files rather than removing them altogether, which is what it does with regular .js/.cjs/.mjs files. I'll be able to fix this by moving it from a devDep to a dep, but it still seems like unexpected behaviour. Please let me know if there is some other way to fix this!