【问题标题】:Script to handle package.json dependency merge conflicts处理 package.json 依赖合并冲突的脚本
【发布时间】:2023-04-07 04:39:01
【问题描述】:

我想知道是否有人有可以执行以下操作的脚本:

  • 检测并修复 package.json 文件中依赖项中的合并冲突
  • 始终采用最新版本的相关依赖项

例如:

<<<<<<< someBranch
lodash: "1.2.3",
=======
lodash: "1.4.5",
>>>>>>> master

我只想从合并冲突中取出 lodash: "1.4.5", 行。

谢谢!

【问题讨论】:

  • “总是采用最新版本” - git 怎么知道? Git 不(也不应该)关心代码的语义
  • 对,这将是脚本分析合并冲突中的不同行并决定保留哪个版本。

标签: git npm


【解决方案1】:

我写了一个 npm 模块,fix-package-conflicts 来处理这个问题https://github.com/tnrich/fix-package-conflicts

以下是示例用法:

npx fix-package-conflicts pathToYourRepo branchName --useYarn
--incomingBranch=main

又名

npx fix-package-conflicts ~/Sites/react-snowpack zoinkl --useYarn
--incomingBranch=main
npx fix-package-conflicts -h                                     
fix-package-conflicts [folderPath] [branch]

Merge in a branch and fix any merge conflicts.

USAGE: fix-package-conflicts ~/Sites/react-snowpack zoinkl --useYarn
--incomingBranch=main

Positionals:
  folderPath  folderPath to fix conflicts at eg ~/Sites/yourRepoName
                                               [default: "~/Sites/yourRepoName"]
  branch      branch to fix conflicts on eg someBranchWithConflicts
                                            [default: "someBranchWithConflicts"]

Options:
      --version         Show version number                            [boolean]
  -h, --help            Show help                                      [boolean]
  -i, --incomingBranch  Set the incoming branch to something other than master
                                                    [string] [default: "master"]
  -y, --useYarn         Run with yarn                                  [boolean]

这是示例运行的输出:

npx fix-package-conflicts ~/Sites/react-snowpack zoinkl --useYarn
CHECKING OUT /Users/tnrich/Sites/react-snowpack
MERGING master into zoinkl
CONFLICT DETECTED IN FILE: /Users/tnrich/Sites/react-snowpack/package.json
FILE ALREADY FIXED:  /Users/tnrich/Sites/react-snowpack/build/package.json
EXECUTING YARN TO FIX LOCK FILE ...may take a minute...
FINISHED

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-11
    • 2016-08-21
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多