Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] workspace scripts should be run in topological order by default #4139

Closed
2 tasks done
justinfagnani opened this issue Dec 8, 2021 · 6 comments
Closed
2 tasks done
Labels
config:workspace related to `--workspace` Enhancement new feature or improvement Priority 2 secondary priority issue Release 8.x work is associated with a specific npm 8 release

Comments

@justinfagnani
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

when running a script across workspaces like npm run build --workspaces you'll most likely end up with errors if your workspaces depend on each other as npm doesn't execute the script in topological order. Other monorepo tools like Lerna do this automatically.

The only workaround is to not use "workspaces": ["packages/*"] in package.json, but manually enter and maintain the list of packages by hand.

Expected Behavior

Scripts should run in topological order.

Steps To Reproduce

  1. In any environment...
  2. With a config that has multiple workspaces and wildcard workspaces setting like "workspaces": ["packages/*"], and one package that depends on another, and say both use TypeScript...
  3. Run npm run build --workspaces
  4. See error from the compiler

Environment

  • npm: 8.2.0
  • Node: 16.9.1
  • OS: macOS 12.0.1
  • platform: macOS
  • npm config:
legacy-peer-deps = true 
@justinfagnani justinfagnani added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Dec 8, 2021
@lukekarrys lukekarrys added Priority 1 high priority issue and removed Needs Triage needs review for next steps labels Feb 27, 2022
@lukekarrys
Copy link
Contributor

Just leaving a comment to link this to #3413 which is a related issue I think.

@lukekarrys lukekarrys added config:workspace related to `--workspace` Enhancement new feature or improvement Priority 2 secondary priority issue and removed Bug thing that needs fixing Priority 1 high priority issue labels Mar 3, 2022
@ruyadorno
Copy link
Collaborator

Hi @justinfagnani thanks for taking the time to bring this up to our attention.

Given that this would be an entire new feature for npm workspaces to support I would recommend you to propose this as either a issue or discussion over at our RFC repo where it can pick up the attention from the community and the rest of the npm cli team.

@justinfagnani
Copy link
Author

Sorry, I don't really have time to do that. This is how other monorepo tools work though, so if you want to just copy, say Lerna, that would probably be great for your users.

@ruyadorno
Copy link
Collaborator

Sounds good, no worries at all @justinfagnani 😊 eventually someone in the team (maybe even myself) will take the time to open an RFC for discussion and we'll move on from there.

I appreciate your help and keep an eye for updates! Thanks 😄

@zackerydev
Copy link

I went ahead and opened an RFC issue here
npm/rfcs#548

We are hoping for this feature to land in npm as well

@faroceann
Copy link

A workaround here is to order your packages in the workspaces property of the top level package.json in the desired order of script execution.

Example

...
"workspaces": [ 
	"/packages/a-package-depended-on",
	"/packages/b-package-depended-on",
	"/packages/package-dependent-on-a-b"
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config:workspace related to `--workspace` Enhancement new feature or improvement Priority 2 secondary priority issue Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

5 participants