将 yarn.lock 同步回 package.json 并锁定

sync yarn.lock back into package.json and lock

我有 package.jsonyarn.lock 文件。 yarn.lock 已锁定版本,我想同步并锁定(不带 ^)yarn.lock 中的所有版本,返回 package.json。 有什么简单的方法吗?

最后我不想在我的 package.json 中有“^”,因为它会导致太多麻烦,我想在 [=26] 时专门升级包而不是不知不觉=] 一个新的 yarn 安装。

是否有任何工具或方法可以将 package.json 中的版本快速替换为 yarn.lock 中现有的版本?

最后我自己做了一些东西:

sync-yarnlock-into-packagejson

它是一个微型实用程序,可以将现有 package.json 与 yarn.lock 同步。

同步锁

yarn.lock 版本同步到现有的 package.json 文件中,删除动态数字,例如 ^,保持静态版本不变。

安装

yarn global add syncyarnlock

NPM

npm install -g syncyarnlock

用法

  Usage: syncyarnlock [options]

  Sync `yarn.lock` package versions, into package.json
  Options:

    -V, --version                output the version number
    -d, --dir <path>             directory path where the yarn.lock file is located (default to current directory)
    -p, --dirPackageJson <path>  directory of project with target package.json, if not set, -d will be used
    -s, --save                   By default don't override the package.json file, make a new one instead package.json.yarn
    -k, --keepUpArrow            By default the ^ or any other dynamic numbers are removed and replaced with static ones.
    -g, --keepGit                By default direct git repositories are also replaced by the version written in yarn.
    -l, --keepLink               By default direct link: repositories are also replaced by the version written in yarn.
    -a, --keepVariable <variable>By default everything is converted to yarn version, write a part of the type you wish not to convert, seperate by comma if more than one, to not replace git and link you would use +,link:
    -h, --help                   output usage information
  Transforms yarn.lock files to JSON

  Examples:
  //perform inside a directory with yarn.lock and package.json, will output package.json.yarn in the same directory.
  syncyarnlock