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

Non-deterministic typescript definitions #481

Open vpontis opened 2 years ago

vpontis commented 2 years ago

Sometimes when tsup recompiles it generates a valid, but different version of the .d.ts file.

You can see an example diff here: https://gist.github.com/vpontis/bc4ae5c8f8ef6ba87026952dd21e5c6c

These two .d.ts files are semantically equivalent but git thinks they are different because the content in the file is getting reorganized.

Is this a known issue somewhere in the tsup pipeline? Is there any way I can avoid this?

Upvote & Fund

Fund with Polar

sachinraja commented 2 years ago

The issue would probably be over at https://github.com/Swatinem/rollup-plugin-dts, which tsup uses to produce those .d.ts files. Is there a reason why you're committing the generated files though?

vpontis commented 2 years ago

The issue would probably be over at https://github.com/Swatinem/rollup-plugin-dts, which tsup uses to produce those .d.ts files. Is there a reason why you're committing the generated files though?

Yea, committing generated files is good when you're publishing packages.

sachinraja commented 2 years ago

I don't think it makes much sense to do that. Most people don't commit the dist files. If you're publishing a package, then you can just gitignore dist and run the build before you publish.

OmgImAlexis commented 2 years ago

@vpontis you shouldn't be committing the generated files. If you're publishing the files then a build script should be used. If you're expecting people to use the repo to install from then make sure to have a prepare script which calls your build script.

vpontis commented 2 years ago

We have reasons to commit generated files... When we check out different branches, it's nice to not have to recompile everything.

I feel like the solution to TS being non-deterministic isn't to just ignore it...

egoist commented 2 years ago

I can take a deeper look if you provide a minimal repro 🙏🏼

OmgImAlexis commented 2 years ago

When we check out different branches, it's nice to not have to recompile everything.

That's gonna lead to all sorts of issues. Recompiling one of the largest repos I have takes less than 2s on my old windows machine.. so unless we're missing something I'd highly suggest just fixing this.