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] run transitive dependencies with --workspace flag? #3413

Closed
1 task done
adiun opened this issue Jun 14, 2021 · 4 comments
Closed
1 task done

[BUG] run transitive dependencies with --workspace flag? #3413

adiun opened this issue Jun 14, 2021 · 4 comments
Labels
cmd:run-script related to `npm run-script` config:workspace related to `--workspace` Enhancement new feature or improvement

Comments

@adiun
Copy link

adiun commented Jun 14, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I have a monorepo that contains:

- packageA (depends on sharedC)
- packageB
- sharedC (depends on sharedD)
- sharedD

If I run npm run build --workspace [packageA], this only builds packageA and not sharedC or sharedD

Expected Behavior

I migrated from lerna to npm workspaces - in lerna there was a flag --include-filtered-dependencies which would look at the transitive dependencies of packageA and would run those first. So an npm run build --workspace packageA would run the build first on sharedD and then sharedC before running the build on packageA. I expected to find something like this in npm workspaces.

Right now I have to define the workspaces in the right order in the root package.json but that doesn't solve the problem of npm run since I have many packages and only want to run some command (like a build) on a subtree. In CI it seems I have to specify each of the dependent packages and build them in the right order.

Steps To Reproduce

  1. In a monorepo environment with a package packageA that has dependencies on a shared package shared and build npm scripts specified for both packageA and shared
  2. With npm 7.17 installed
  3. Run npm run build --workspace packageA
  4. Expect to see shared package build first. Actual: packageA builds - shared never builds.

Environment

  • OS: Ubuntu 20.04
  • Node: 14.16.0
  • npm: 7.17.0
@adiun adiun added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Jun 14, 2021
@zackerydev
Copy link

This would be a huge advantage of NPM workspaces - right now we are keeping lerna around for running transitive builds one at a time.

@jacobroufa
Copy link

I'm looking into a similar issue with some software I'm working on, where I'm scoping to a folder filled with workspaces, e.g. modules/* and dependents are not built prior to the modules that require them. In my research I've come across a few things.

Lerna builds a dependency tree by which to order their operations: see their PackageGraph class.

NPM's install and ci commands use a similar method, with their dependent class Arborist: see the install command.

It seems like one would just have to implement this Arborist in place of the simplified operation taking place to set workspaces.

@lukekarrys lukekarrys added Enhancement new feature or improvement config:workspace related to `--workspace` and removed Release 7.x work is associated with a specific npm 7 release Bug thing that needs fixing labels Mar 3, 2022
@ruyadorno ruyadorno added cmd:run-script related to `npm run-script` and removed Needs Triage needs review for next steps labels Mar 3, 2022
@ruyadorno
Copy link
Collaborator

ruyadorno commented Mar 3, 2022

Hi @adiun 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.

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmd:run-script related to `npm run-script` config:workspace related to `--workspace` Enhancement new feature or improvement
Projects
None yet
Development

No branches or pull requests

5 participants