Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch Mode and D.TS generation #970

Open
Christopher2K opened this issue Aug 10, 2023 · 5 comments
Open

Watch Mode and D.TS generation #970

Christopher2K opened this issue Aug 10, 2023 · 5 comments

Comments

@Christopher2K
Copy link

Christopher2K commented Aug 10, 2023

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

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@Californian
Copy link

Californian commented Aug 16, 2023

@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
Copy link
Author

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
Copy link

@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
Copy link

mgcrea commented Feb 22, 2024

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

@davilima6
Copy link

davilima6 commented Mar 21, 2024

I confirm the issue with both dts and experimentalDts using:

  • tsup v8.0.2
  • @microsoft/api-extractor 7.43.0
  • typescript 5.3.3

How can I run experimentalDts using the onSuccess option?

Or any pointers on how to contribute to a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants