Since the tinyglobby
change was introduced we have been seeing our output files change between builds.
In a monorepo project we have multiple entrypoints and since 8.3.0 of tsup we have been seeing the resulting output files change between subsequent builds, primarily due to chunk names changing.
I have set up a minimal reproduction of the issue here:
https://github.com/phcyso/tsup_glob_bug_repro
Running yarn bundle
over and over will cause at least two files to change each time.
e.g.
Running yarn bundle
against the main branch of my reproduction causes one of the index files to diff as:
--- import{b as i}from"../chunk-BJMENOML.mjs";import{a as o}from"../chunk-6VRBJZPP.mjs";import{a as r,b as t,d as m}from"../chunk-V3Q6A3RL.mjs";async function n(){t("world 4"),o("world 4"),o(`what - ${i}`)}r(n,"main");m(import.meta.url,n);export{n as main};
+++
import{a as o}from"../chunk-6VRBJZPP.mjs";import{b as i}from"../chunk-BJMENOML.mjs";import{a as r,b as t,d as m}from"../chunk-V3Q6A3RL.mjs";async function n(){t("world 4"),o("world 4"),o(`what - ${i}`)}r(n,"main");m(import.meta.url,n);export{n as main};
And then running it a second time gives
import{b as i}from"../chunk-BJMENOML.mjs";import{a as o}from"../chunk-6VRBJZPP.mjs";import{a as r,b as t,d as m}from"../chunk-V3Q6A3RL.mjs";async function n(){t("world 4"),o("world 4"),o(`what - ${i}`)}r(n,"main");m(import.meta.url,n);export{n as main};
so back to the original.
This will then flip flop back and forth between these two outputs.
We did some digging and this appears to be the culprit:
https://github.com/egoist/tsup/blob/main/src/index.ts#L111
After hacking this line in node_modules directly to sort the result of the glob
call:
options.entry = (await _tinyglobby.glob.call(void 0, entry)).sort();
the issue appears fixed.
I have not raised a PR for this as I am not fully across what the implications of sorting the glob output would be.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too