egoist / tsup

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

Sourcemaps not generating correctly if map file already exists #1151

Open garikkh opened 3 days ago

garikkh commented 3 days ago

Problem

When using tsup to bundle typescript and generate sourcemaps, it will not generate accurate map files if the target map file already exists in the output directory. It will instead copy the sourcesContent from the existing map file, even if it is completely outdated and incorrect. The built javascript file is updated and correct, only the map file is wrong.

To avoid this currently, clean option must be set to delete the map file, then generate a fresh map.

Steps to reproduce:

  1. Run tsup index.ts --sourcemap
  2. Make some changes to index.ts
  3. Run tsup index.ts --sourcemap again
  4. Note that index.ts.map does not have the correct sourcesContent

There are other ways to show the issue, i.e. using --watch and not having map files updated, or even manually editing the index.js.map file to have incorrect sourcesContent, and running build again to see that it is not changed.

Example repo:

https://github.com/garikkh/tsup-sourcemaps-demo/tree/main

Upvote & Fund

Fund with Polar