【问题标题】:npm install forked git with submodulenpm 安装带有子模块的分叉 git
【发布时间】:2022-04-13 19:56:18
【问题描述】:

我正在尝试让 npm 通过 npm install 安装 node-gitteh 作为依赖项,该依赖项从 package.json 读取。不幸的是,这个 npm 包在节点 0.6.x 中被破坏了,但没有问题,因为有一个分叉的 repo 可以解决这些问题 (https://github.com/hughsk/node-gitteh.git)。

现在的问题是这个分叉的 repo 有一个子模块,所以如果我尝试从package.json 的 github 下载 tar:

, "dependencies" : {
    "gitteh" : "https://github.com/hughsk/node-gitteh/tarball/master"
}

我收到一个等同于“未找到子模块文件夹”的错误。如果我手动克隆相同的 repo 并执行递归子模块更新和 npm installnode-gitteh 文件夹,它工作正常,但我不知道如何让 npm 做到这一点。

【问题讨论】:

    标签: javascript node.js npm


    【解决方案1】:

    我遇到了同样的问题,到目前为止,我只是依靠将我的模块克隆到 node_modules 并手动进行子模块更新。让 npm 自动处理这个会很好。

    在 package.json 中有一个 scripts 字段(参见npm docs) 可以这样做

    "scripts":{"preinstall": "git submodule update -i -r"}
    

    有关此示例,请参阅 https://github.com/isaacs/octave-test

    【讨论】:

    • npm 不会复制.gitmodules,因此只能在本地工作:(
    • 在我的例子中,npm 碰巧给了我一个 .gitmodules,但是如果没有 .git 文件告诉我要安装哪个版本,这仍然不够。 :(
    • 我的保留.gitmodules 文件,仅此而已。其他 git 元数据都没有出现,子模块目录根本不显示。
    【解决方案2】:

    根据the docs,您需要以特殊格式提供 git url。 此外,它需要指向 git repo(与 git clone 使用的地址相同),而不是 github 提供的 tarball。

    在您的情况下(git over https),它将是:

    , "dependencies" : {
      "gitteh" : "git+https://github.com/hughsk/node-gitteh"
    }
    

    使用这个,npm 将默认到 master 分支。

    【讨论】:

      猜你喜欢
      • 2017-08-13
      • 2014-02-17
      • 2023-03-14
      • 1970-01-01
      • 2013-03-31
      • 2017-12-18
      • 1970-01-01
      • 2014-11-12
      • 1970-01-01
      相关资源
      最近更新 更多