如何更新npm模块,忽略git repo

Iva*_*nZh 25 git npm

我分叉了一个npm模块,现在它是一个git repo.

所以我的package.json:

"dependencies": {
    "some-module": "git+https://github.com/my-name/some-module.git",
}
Run Code Online (Sandbox Code Playgroud)

通过获取上游和合并来同步forked repo.但是当我尝试更新其他npm模块时,它会给出错误:

npm ERR! git Appears to be a git repo or submodule.
npm ERR! git     /Users/.../node_modules/some-module
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.

npm ERR! System Darwin 13.4.0
npm ERR! command "node" "/usr/local/bin/npm" "update"
npm ERR! cwd /Users/...
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! path /Users/.../node_modules/some-module
npm ERR! code EISGIT
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/.../npm-debug.log
npm ERR! not ok code 0
Run Code Online (Sandbox Code Playgroud)

更新时有没有办法忽略git repo?或者跳过此错误?

bol*_*lav 13

npm检查所有目录是否存在.git目录,EISGIT如果存在则抛出错误,因此无法忽略或跳过它.

但是代码会检查它是否是一个链接:

mod.parent && !mod.isLink && [checkGit, mod.realpath],
Run Code Online (Sandbox Code Playgroud)

所以我能够通过将模块符号化为node_modules来使其工作.

$ ln -s ../some-module node_modules
Run Code Online (Sandbox Code Playgroud)


Jos*_* Kj 10

在执行npm安装库时,我也遇到了这个问题,我能够通过从错误消息中提到的相应library_name中删除.git目录(隐藏在中node_modules/library_name)来解决该问题。

还要确保不要.git directory从项目的根目录中删除,因为如果从项目根目录中删除.git目录,则会丢失与git相关的信息,如分支信息等。

感谢bolav很好地解释了如何引发EISGIT错误。


Mah*_*ura 6

rm -rf node_modules/*/.git/
Run Code Online (Sandbox Code Playgroud)

尝试这个


Ven*_*ryx 5

是的,有一种方法可以跳过错误。

1) 打开文件 "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-install-checks\index.js"
2) 注释掉最底部的这段代码:

if (!er && s.isDirectory()) {
  var e = new Error(folder + ': Appears to be a git repo or submodule.')
  e.path = folder
  e.code = 'EISGIT'
  return cb(e)
}
Run Code Online (Sandbox Code Playgroud)

完毕。

背景

来自另一个长期因此错误而感到沮丧的开发人员;由于来自各种系统的限制,所有建议的解决方案都不适用于我的情况。

建议:NPM 使用符号链接,因此从 node_modules 创建模块的符号链接到您的库 repo 文件夹。
问题:然后 Watchman 不扫描其中的 JS 文件。

建议:做“npm publish”和“npm install”。每一个。单身的。时间。
问题:对于快速开发测试/周期来说很糟糕,并且向 npm 目录发送数百个从未使用过的版本。

建议:使用守望者链接 (WML)。(即文件更改时目录自动复制)
问题:对于我机器上包含的所有存储库,必须始终运行后台程序。另外,这意味着我无法直接打开 node_modules 文件夹中的文件进行快速更改;相反,我每次都必须去图书馆的源代码库。这通常很好,但有时在程序存储库中进行更改并使其反映在库存储库中是很好的,反之亦然。

我的解决方案

所以是的,通过上述更改,我可以使用库目录的硬链接克隆并避免上述问题。

我用它来创建目录级硬链接克隆:http : //schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html#hardlinkclones

这种方法的一个问题是,每当我在库中添加或删除文件时,我都必须重新运行硬链接克隆。但至少在现有文件中进行更改时,我不必做任何事情。(这是更痛苦的)