command which relocate a library from dependencies to devDependencies block in package.json?

Viewed 2746

using yarn, I have added few additional library ( let say jquery)

yarn add jquery

this will be added by default to dependencies block in package.json

but I want to change its location from dependencies to devDependencies block.

what currently I do is

  • remove library

yarn remove jquery

  • then add again with -D

yarn add jquery -D

So I am looking for any command in yarn or npm which directly changes the library location from dependencies to devDependencies block without uninstalling and reinstall the same.

1 Answers

The problem with using npm or yarn commands is that there is a chance that the version that is re-added is a different version than the one that is currently used. If this is what you want - both a move and an upgrade - then go ahead and use the accepted answer in this question.

If not, simply manually edit your package.json to move the line from the devDependencies object to the dependencies object (creating it if necessary). You can go the other direction too.

The lock file doesn't hold any information about if things are prod or dev dependencies, so that doesn't need to be updated.

Because you asked specifically for a command:

Choose your favorite combination out of the command line text editors: sed, awk, grep, perl or even python. Or you could use a JSON editor like jq.

You are right though - there should be a native command for this and perhaps we need to make a pull request to npm/yarn.

Related