简体   繁体   中英

Good way to switch between 2 versions of the same dependency in package.json?

Turns out you can't have comments in JSON files, and it's a bit awkward to have people refer to some documentation telling them what line to copy/paste in and where in order to achieve this.

I think I can make a python script to copy/paste in one of two package.json files depending on what flags they pass in, but that feels overcomplicated.

I think I can include both dependencies (under different names) but that would create a requirement for both to be available, which is not good either.

Looking for ideas/thoughts on a good way to accomplish this. I have a release and dev version of the same dependency and I often need to swap between the two. Would like to improve the workflow beyond just having a notepad on the side with the two lines pasted in it...

yarn and npm already do this job, why not use them?

Releases

Tag the dev versions when you release them

yarn publish --tag dev dep
npm publish --tag dev dep

Then reference the tag at install time yarn install dep@dev .

Local

For local dependencies, npm and yarn provide the "link" command.

In your dependency dir run yarn link
In you project dir run yarn link dep

You could document the commands as scripts so easy to run or view.

"scripts" : {
  "dep:local": "yarn link dep",
  "dep:dev": "yarn install dep@dev",
  "dep:latest": "yarn install dep@latest"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM