oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.5k stars 2.79k forks source link

Bun Dependency Order for running scripts via --filter does not work #13239

Open m11hauk opened 3 months ago

m11hauk commented 3 months ago

What version of Bun is running?

1.1.21

What platform is your computer?

Linux 5.15.133.1-microsoft-standard-WSL2 x86_64 unknown

What steps can reproduce the bug?

My specific scenario is a simple one package builds a 'dist' whereas the other package depends on that being already build. But the below example should demonstrate sufficiently.

To reproduce:

  1. clone this example workspace repo https://github.com/m11hauk/bun-issue-13239
  2. run bun clean & bun i just to be safe
  3. run bun --filter '*' build

What is the expected behavior?

As said in the doc:

Bun will respect package dependency order when running scripts. Say you have a package foo that depends on another package bar in your workspace, and both packages have a build script. When you run bun --filter '*' build, you will notice that foo will only start running once bar is done.

What do you see instead?

This does not appear to work. Both scripts are executed at the same time, and the 'build' of the package-b finished earlier than it's dependency, tha package-a.

Additional information

No response

Edit:

Added a custom repo to demonstrate the issue.

Hamza12700 commented 3 months ago

In bun v1.1.22 works just fine. Update to version: 1.1.22

m11hauk commented 3 months ago

In bun v1.1.22 works just fine. Update to version: 1.1.22

Checked it in on 1.1.22 and no change for me. Also went through the commits and changelog notes in between those versions and haven't seen anything related.

Just to be sure I'm on the same page, are we talking about the same thing? Which is that the order in which those individual scripts are executed/started matters.

I made a little doodle to ilustrate: bun-workspaces-doodle

Fundementals we should be able to agree on:

My issue is with the order they are executed in.

So if we take what's in the issue doc, what should happen:

the package manager will start build script A since it is lowest in the dependency tree. After that one finishes, the build script of package B should start, since it should be waiting on the result of build script A.

What happens instead:

both scripts start simultaneously, without the dependency order in mind.

So are we talking about the same thing? Either:

  1. problem is solely on my platform and it works as it should for other people
  2. the issue is still there and I may have described it insufficiently
  3. I misunderstood the documentation description
  4. the documentation is wrong/out-of-date

Maybe a better example would be to have both of them sleep for 5seconds, in which case they finish simultaneously, which also suggests the dependency order is not being considered at all,.

chimericdream commented 3 months ago

Do the scripts have pre- and/or post- hooks? If so, it's possible this is the same issue I reported in April (#10357). In my case, it looks like Bun is losing track of which hooks have finished and whether a given script is safe to run.

m11hauk commented 3 months ago

@chimericdream no they do not, I don't think the issue is in pre/post hooks. However I think that the issue you reported is dealing with the same problem, which means that the order at which the scripts are run in a situation where:

The scripts are run simultaneously instead of being run in order of the inter package dependencies as mentioned in the doc. I think that might solve your underlying issue.

I created a simple repo for demonstration https://github.com/m11hauk/bun-issue-13239

Hamza12700 commented 3 months ago

@m11hauk I wasn't on the same page as you. I tested it again using bun version 1.1.25 canary build and yes scripts a and b starts simultaneously, without any dependency order.