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

问题描述 投票:0回答:1

我有

package.json
yarn.lock
文件。 yarn.lock 已锁定版本,我想同步并锁定(没有
^
)yarn.lock 中的所有版本,放回 package.json。

有什么简单的方法可以做到吗?

最后,我不想在我的package.json中包含

"^"
,因为它会带来太多麻烦,并且我想在运行新的yarn安装时专门升级包,而不是在不知不觉中。

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

node.js npm package.json yarnpkg
1个回答
22
投票

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

同步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   
© www.soinside.com 2019 - 2024. All rights reserved.