Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Using yarn, I have added few additional libraries ( 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 the devDependencies block.

What I currently 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 the devDependencies block without uninstalling and reinstalling the same.

like image 465
diEcho Avatar asked Oct 29 '22 23:10

diEcho


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.

like image 135
eedrah Avatar answered Nov 13 '22 05:11

eedrah