npm安装并构建分叉的github回购 [英] npm install and build of forked github repo

查看:137
本文介绍了npm安装并构建分叉的github回购的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是一个全新的问题,但我一直在寻找一段时间,而且我无法找到解决方案。



m使用我的角度应用程序称为角度翻译模块。但是,我不得不对源代码进行一些小的修改,以便按照我所希望的方式运行所有内容,现在我想在 npm install 上保留这些更改>。一位同事建议我分叉源代码的回购,并指出我的分叉回购作为依赖,我试过这些方式,例如

  npm install https://github.com/myRepo/angular-translate 
npm install https://github.com/myRepo/angular-translate/archive/master.tar.gz

第一个给我这样一个没有构建的目录。只是一个package.json,.npmignore和一些降价文件

  -angular-translate 
.npmignore
.nvmrc
CHANGELOG.md
package.json
etc

第二个 npm install 给了我完整的repo,但是当我使用命令时,我没有得到一个构建版本npm install angular-translate 。我已经看到了一些关于运行预发布脚本的讨论,但我不确定在安装所有模块时如何执行此操作。我也尝试将fork作为我自己的模块发布到npm注册表中,但是我再也没有构建,并且我不确定这是正确的做法...



我对这个话题的无知表示歉意。我对npm没有太多的经验。很想在这个问题上得到一些反馈。当需要对包的源代码进行修改时,似乎它可能是一个常见的问题?也许有更好的解决方案?感谢您的帮助。

解决方案

请尝试 npm install< ghusername> /< repoName> ,其中< ghUsername> 是您的GitHub用户名(不包含 @ code>< repoName> 是存储库的名称。这应该正确安装它。你很可能希望在install命令中使用 - save - save-dev 标志来保存依赖于你的 package.json



如果不能正常工作,请检查 .npmignore 文件。



如果安装命令需要很长时间,请不要惊慌;从git仓库安装比从npm注册表安装要慢。






编辑:


你的问题在于你的情况, dist / 没有被提交到repo中(因为它位于 .gitignore )。这就是实际的代码所在的地方。 dist / 是在包被发布到npm注册表之前从 src / 中的文件构建的,但是 dist / 永远不会被提交回购。



这很丑陋,但在这种情况下,您必须移除 dist / .gitignore 然后运行:

  npm运行编译
git add。
git commit
git push

(确保您已经运行<$ c
$ b


$ b

然后你应该可以从github安装。



可能还有另一种方法可以使用 postinstall 脚本来完成此操作,但我不确定这是否可行;我从来没有尝试过。


This is not a totally new question, but I've been looking around for a good while now and I'm having trouble finding a solution.

I'm using a module for my angular app called angular-translate. However, I've had to make a few small modifications to the source code to get everything working the way I'd like, and now I want to persist those changes on npm install. A colleague suggested that I fork the repo of the source code and point to my forked repo as a dependency, which I've tried in these ways, e.g.

npm install https://github.com/myRepo/angular-translate
npm install https://github.com/myRepo/angular-translate/archive/master.tar.gz

The first gives me a directory like this with no build. Just a package.json, .npmignore, and some markdown files

-angular-translate
   .npmignore 
   .nvmrc
    CHANGELOG.md 
    package.json
    etc

The second npm install gives me the full repo, but again I don't get a build like when I use the command npm install angular-translate. I've seen some dicussion of running the prepublish script, but I'm not sure how to do this when installing all the modules. I've also tried publishing the fork as my own module to the npm registry, but again I get no build, and I'm not sure that's the right thing to do...

I apologise for my ignorance on the topic. I don't have a huge amount of experience with npm. Would love to get some feedback on this issue. It seems like it could be a common enough issue when modifications need to be made to a package's source code? Maybe there's a better solution? Thanks in advance for your help.

解决方案

Try npm install <ghusername>/<repoName>, where <ghUsername> is your GitHub username (without the @) and <repoName> is the name of the repository. That should correctly install it. You will most likely want to use the --save or --save-dev flag with the install command to save dependency in your package.json.

If that isn't working correctly, check the contents of your .npmignore file.

Don't panic if the install command takes a long time; installing from a git repository is slower than installing from the npm registry.


Edit:

Your problem is that in your case, dist/ is not committed to the repo (since it is in the .gitignore). That is where the actual code lives. dist/ is built from the files in src/ before the package is published to the npm registry, but dist/ is never committed to the repo.

It's ugly, but in this case you will have to remove dist/ from the .gitignore and then run:

npm run build
git add .
git commit
git push

(Ensure that you have run npm install first)

You then should be able to install from github.

There might be another way to do this using a postinstall script, but I'm not sure if that's possible; I've never tried it.

这篇关于npm安装并构建分叉的github回购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆