yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.44k stars 1.11k forks source link

[Bug] Yarn2 does not build workspaces in order specified in the manifest on Windows #1351

Closed emmalynch closed 4 years ago

emmalynch commented 4 years ago

Describe the bug

On Windows, workspaces are not built in the order they're specified. It appears to use alphabetical order. This creates problems when workspaces depend on others with names that are alphabetically after their own.

To Reproduce

I haven't added a Sherlock repro, as it wouldn't run against Windows and the issue doesn't happen on Linux.

package.json: https://github.com/emmalynch/cookie-cutter/blob/feature/yarn2/package.json

"workspaces": [
    "packages/core",
    "packages/azure",
    "packages/gcp",
    "packages/grpc",
    "packages/instana",
    "packages/kafka",
    "packages/kubernetes",
    "packages/lightstep",
    "packages/mssql",
    "packages/prometheus",
    "packages/proto",
    "packages/redis",
    "packages/s3",
    "packages/statsd",
    "packages/timer",
    "packages/validatejs",
    "docs/website",
    "examples/*"
  ],

azure has a dependency on core

travis build: https://travis-ci.org/github/walmartlabs/cookie-cutter/builds/686522850 Running yarn build && yarn test on Windows gives the following error:

YN0000: src/__test__/dedupe.integration.test.ts(15,8): error TS2307: Cannot find module '@walmartlabs/cookie-cutter-core'.

Environment if relevant (please complete the following information):

OS: Windows (Windows Server, version 1809)

$ node --version v10.20.1

$ npm --version 6.14.4

$ nvs --version 1.5.4

$ yarn --version 2.0.0-rc.33

Additional context

This issue is occurring on a travis build. The same project builds successfully on both MacOS and Linux.

arcanis commented 4 years ago

Hey! That's not how Yarn works, actually. The exact order isn't set, except that it's a consistent one (by that I mean that it should be consistent across systems, but that alphabetical sort is perfectly fine).

If you're looking to execute a script in your workspaces in topological order (ie by taking their inter-relationships into account), then I think you want to use the --topological flag in yarn workspaces foreach. Does that make sense?

arcanis commented 4 years ago

I've just noticed that you mention "build scripts", which may be interpreted as "postinstall scripts". In that case, make sure you properly list the dependencies between your workspaces (ie that the workspace containing the tests depends on the core package), as this is how Yarn will be able to sort the workspaces for coherent builds.

emmalynch commented 4 years ago

Aah, that makes sense. I think I just presumed the default behaviour was the same as using the --topological flag, since that's how it appeared to work when I was building locally. That did the trick though!

I'm still unsure why a build would succeed on one system but not another though, with or without that flag if the order should be consistent across systems. I'll have another read of the docs for my own info anyway. Thanks for the help!