egoist / egoist/tsup

Include/Generate declaration files for bundled external libraries

Open
#1,368 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
11.3k
Forks
274
PR merge metrics
No merged PRs in 30d

Description

We're trying to use tsup to bundle typebox (which is an ESM only library) into a CommonJS library. This works well for the code itself, however we also need to include or generate the type declaration files of typebox to allow its types propagate to consumers.

Is there a way of doing that? It seems that just enabled dts doesn't do the trick.

This is the configuration file I'm using:

import { defineConfig } from 'tsup'

export default defineConfig({
  entry: ['src/index.ts'],
  format: ['cjs', 'esm'],
  dts: {
    tsconfig: './tsconfig.lib.json',
  },
  sourcemap: true,
  clean: true,
  splitting: false,
  treeshake: true,
  minify: false,
  target: 'es2022',
  noExternal: ['typebox'],
  esbuildOptions(options) {
    options.conditions = ['module']
  },
})

Using tsup version 8.5.0.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the declaration build with src/index.ts, tsup 8.5.0, and tsconfig.lib.json using the configuration shown. Inspect how the dts option handles the bundled typebox dependency for both CommonJS and ESM outputs. Done means consumers receive usable declaration files whose typebox types propagate correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, tooling
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.