Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Changing directory into a workspace and using yarn add nock adds nock to the dependencies for the package.json, rather than updating the version in devDependencies. Different versions of nock are then present within the same package.json in the dependencies and devDependencies.
I've created a repo so you can easily replicate, with a PR showing the erroneous result, here.
What is the expected behavior?
Yarn should update the devDependencies version of nock, like it would have done were we not in a workspace.
Please mention your node.js, yarn and operating system version.
Node: v8.9.1
Yarn: v1.3.2
OS: macOS 10.12.6
@greysteil I believe that's the correct behavior, since you should use yarn upgrade nock if you want to update the existing dependency. Have you given that a go?
So cd packages/package1 && yarn add nock is supposed to have a different effect on my package.json if I'm using workspaces than if I'm not? That seems really unintuitive and surely not deliberate.
yarn upgrade nock doesn't update the contents of my package.json, so doesn't do an update. (Check out the PR I linked for details of the buggy result of yarn add nock - in particular, check out the duplicate appearance of nock. Surely that's not the desired behaviour?)
Sorry for the delay! So I was able to verify this bug on my end. yarn workspace package1 [add/upgrade] nock only seems to work on upgrading dependencies, and not devDependencies.
yarn workspace package1 add dependency --dev adds to devDependencies
I can confirm that upgrading devDependencies with yarn workspace does not work on yarn 1.9.2.
yarn workspace package1 upgrade dependency --latest
--dev is not working for me, it just adds to dependencies
In my case, if I tried to install packages available at npm registry, it successfully adds to devDependencies.
But when I tried with local packages, it goes to dependencies regardless of -D or --dev.
@greysteil @kaylie-alexa below commands adds to devDependencies for me -
yarn workspace <workspace> add <dependency> -D/--dev
Node: v12.16.3
Yarn: v1.22.4
OS: macOS 10.14.6
So it looks like adding a local package that has the bug mentioned here https://github.com/yarnpkg/yarn/issues/4878 will add it to the dependencies instead of devDependencies... yarn workspace <workspace> add <local package dependency>@version -D/--dev
Node: 12.18.5
Yarn: 1.22.5
OS: macOS 10.15.6
Most helpful comment
Sorry for the delay! So I was able to verify this bug on my end.
yarn workspace package1 [add/upgrade] nockonly seems to work on upgrading dependencies, and not devDependencies.