egoist / tsup

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

Watch Mode and D.TS generation #970

Open Christopher2K opened 1 year ago

Christopher2K commented 1 year ago

Description

Hi!

I'm using tsup in watch mode for a shared library in a monorepo. I can't get the d.ts generation working in watch mode.

My config

  "tsup": {
    "entry": [
      "src/index.ts",
      "src/models/index.ts",
      "src/validators/index.ts"
    ],
    "format": [
      "esm",
      "cjs"
    ],
    "dts": true,
    "splitting": false,
    "sourcemap": true,
    "clean": false
  }

Output after saving a file

dev-apps-1   | @weakassdev/shared:dev: CLI Change detected: change src/example.ts
dev-apps-1   | @weakassdev/shared:dev: ESM Build start
dev-apps-1   | @weakassdev/shared:dev: CJS Build start
dev-apps-1   | @weakassdev/shared:dev: ESM dist/index.js                122.00 B
dev-apps-1   | @weakassdev/shared:dev: ESM dist/models/index.js         1.11 KB
dev-apps-1   | @weakassdev/shared:dev: ESM dist/validators/index.js     681.00 B
dev-apps-1   | @weakassdev/shared:dev: ESM dist/index.js.map            183.00 B
dev-apps-1   | @weakassdev/shared:dev: ESM dist/validators/index.js.map 1.19 KB
dev-apps-1   | @weakassdev/shared:dev: ESM dist/models/index.js.map     1.80 KB
dev-apps-1   | @weakassdev/shared:dev: ESM ⚡️ Build success in 42ms
dev-apps-1   | @weakassdev/shared:dev: CJS dist/index.cjs                2.15 KB
dev-apps-1   | @weakassdev/shared:dev: CJS dist/validators/index.cjs     3.20 KB
dev-apps-1   | @weakassdev/shared:dev: CJS dist/models/index.cjs         4.11 KB
dev-apps-1   | @weakassdev/shared:dev: CJS dist/validators/index.cjs.map 1.36 KB
dev-apps-1   | @weakassdev/shared:dev: CJS dist/index.cjs.map            283.00 B
dev-apps-1   | @weakassdev/shared:dev: CJS dist/models/index.cjs.map     2.07 KB
dev-apps-1   | @weakassdev/shared:dev: CJS ⚡️ Build success in 45ms

^ Note that this output doesn't mention dts file and when

Workaround

I'm currently using tsup --onSuccess script option to run tsc to get the d.ts files. I'd prefer a built-in solution since this requires me to align tsup and tsc config everytime I'm adding a module

Info

    "tsup": "~7.2.0",
    "typescript": "~5.1.6"

Thanks!

Upvote & Fund

Fund with Polar

Californian commented 1 year ago

@Christopher2K how exactly are you using the --onSuccess flag to generate them? --onSuccess 'tsc -d' doesn't generate anything for me.

Edit: to fix the above and keep things consistent, I'm using the following for my npm run build:watch command: tsup --watch --onSuccess 'tsup --dts-only'. It's probably still better to use tsc for both though, so I'm still curious to hear if anyone has gotten that to work.

Christopher2K commented 1 year ago

That's actually a good idea. The only reason I used tsc is because I feel like d.ts generation is slower with tsup.

Californian commented 1 year ago

@Christopher2K what tsc command did you use in your onSuccess flag? I think you're right that it is slower (and not guaranteed consistent with the compiler) to use tsup so I'd like to switch if you have something that works!

mgcrea commented 8 months ago

Can confirm that I'm hitting this as well when using experimentalDts, the dts is generated only the first time.

davilima6 commented 8 months ago

I confirm the issue with both dts and experimentalDts using:

How can I run experimentalDts using the onSuccess option?

Or any pointers on how to contribute to a fix?