npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.36k stars 3.09k forks source link

[BUG] not installing peer dependencies for workspaces if they are not nested inside the root package #2650

Open talsi opened 3 years ago

talsi commented 3 years ago

Current Behavior:

having 'library-project' with peer-dependencies adjacent to 'main-project' and 'main-project' with workspaces: ['../library-project'] (outside of 'main-project' folder) 'npm install' in 'main-project' is not installing the peer-dependencies

example:

library-project/
  package.json      // peerDependencies: {"dep-a": "1.0.0"}
main-project/
  package.json      // "workspaces": [ "../library-project" ]

Expected Behavior:

expecting node_modules in 'main-project' after 'npm i' to include 'dep-a':

node_modules
  library-project (linked)
  dep-a

actual result: missing 'dep-a' in node_modules

this works fine if 'library-project' would be inside 'main-project'

Steps To Reproduce:

  1. main-project and library-project are two adjacent projects

  2. main-project package.json:

    {
    "name": "main-project",
    "version": "1.0.0",
    "workspaces": [
    "../library-project"
    ],
    "dependencies": {
    "library-project": "1.0.0"
    }
    }
  3. library-project package.json:

    {
    "name": "library-project",
    "version": "1.0.0",
    "peerDependencies": {
    "@angular/core": "11.1.2"
    }
    }
  4. run 'npm install' in 'main-project'

  5. expected "@angular/core" to be installed as it's a peer dependency of 'library-project'

Environment:

darcyclarke commented 3 years ago

@talsi sorry about the confusion, we should probably be throwing in these cases since our intent is not to allow workspace definitions outside of the root. Our docs should be more clear about this &/or we may allow for this in the future - although that would be a net-new feature/support.

talsi commented 3 years ago

@darcyclarke

i think having built-in support for this will be much appreciated. it's a very productive feature and it's unfortunate that it can't be used for legacy projects (it's not easy, to say the least, moving existing projects around into other projects).

fyi, as a workaround, if anyone else is interested, you could -

  1. symlink 'library-project' into the root folder ('main-project') manually / using a tool like symlink-dir.
  2. set "workspaces": ["library-project"] (you can even use globs)

now it works as expected for me.