egoist / egoist/tsup

Output changing between builds since v8.3.0

Open
#1,246 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start at src/index.ts around line 111 and inspect how the tinyglobby glob result becomes the entry list. Use the linked minimal reproduction and run yarn bundle repeatedly to compare generated files; done means successive builds no longer flip chunk import ordering or otherwise change output.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.