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

"onSuccess" script runs before dts compile done. #700

Open Misaka-0x447f opened 2 years ago

Misaka-0x447f commented 2 years ago

image

Upvote & Fund

Fund with Polar

egoist commented 2 years ago

yeah this was initially added to let you run the generated js file, so we didn't wait for the dts build to succeed to call this function.

can you explain why you need this? maybe we can call this function again when the dts build is ready:

onSuccess: ({ isDtsReady }) => {
  // isDtsReady: boolean
}
Misaka-0x447f commented 2 years ago

yeah this was initially added to let you run the generated js file, so we didn't wait for the dts build to succeed to call this function.

can you explain why you need this? maybe we can call this function again when the dts build is ready:

onSuccess: ({ isDtsReady }) => {
  // isDtsReady: boolean
}

I need let the developer knows compile success and is now waiting for change, but not done without a process exit. Maybe add a hardcoded prompt when everything’s done in watch mode is good enough.

alii commented 1 year ago

can you explain why you need this? maybe we can call this function again when the dts build is ready:

@egoist reasons for needing this functionality in #856

RichiCoder1 commented 1 year ago

^ basically the same reason. Need to rename the types (https://twitter.com/robpalmer2/status/1634702219025981440?s=20). Currently doing tsup && script-that-renames.js, but it'd be really nice to consolidate that. (And/or have it be something tsup does)

alii commented 1 year ago

I see three possible solutions here, I'd love to help/work on a PR if an option is decided

victor9000 commented 1 year ago

I'm running into this problem as well while using onSuccess to trigger other tasks. I need it to be called once after everything has completed. I'm currently working around this by deleting the dist dir before a build and using the onSuccess below to verify that both steps have completed. It seems like a bit of a hack though.

--onSuccess 'while [ ! -f  ./dist/index.d.ts ]; do sleep 1; done && bash my-command.sh'
coopbri commented 1 year ago

What I ended up doing was running the build without DTS generation, then running a DTS-only build in onSuccess. This solution is also a bit of a hack and loses some concurrency, but it works. From there, you can tap into the lifecycle however you want. Implemented here: https://github.com/animareflection/ui/blob/bd10752060d082e51c2d489974d247f6b3d36944/tsup.config.ts#L46-L53

brc-dd commented 1 year ago

One can also do something like this: (not sure though if it works in all cases)

// tsup.config.ts

import { defineConfig } from 'tsup'

export default defineConfig({
  ...
})

process.on('beforeExit', (code) => {
  if (code === 0) {
    // do something here...
  }
})
NickBolles commented 11 months ago

We're using onsuccess to call yalc publish for a dev command. We see the JS code get updated in the consuming app, but not the typings until the next build. calling onSuccess again when dts is complete, or having another handler for dts completion would be helpful for this usecase too.

its-lee commented 3 months ago

I'm using this to determine when it's safe for downstream code to locally npm install a package as part of my workflow. As things stand, it only pulls in the non .d.ts code which doesn't really work for Typescript consumers.

nerdyman commented 2 weeks ago

I ran into this issue using an ESBuild plugin that generates custom .js and d.ts files at the end of the build. It seems that when clean is enabled it doesn't clear out the d.ts files until the dts stage runs so I had a really weird issue where the .js files were being written but the generated .d.ts files never appeared because the DTS stage was deleting them after the onSuccess fired.

Would be great to have an option to wait for the DTS stage to finish too.