npm 安装和构建分叉的 github 存储库

编程入门 行业动态 更新时间:2024-10-24 12:30:46
本文介绍了npm 安装和构建分叉的 github 存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为我的 angular 应用程序使用一个名为 angular-translate 的模块.但是,我必须对源代码进行一些小的修改才能使一切按照我想要的方式工作,现在我想在 npm install 上保留这些更改.一个同事建议我fork源代码的repo并将我的fork repo作为依赖项,我已经尝试过这些方式,例如

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 github/myRepo/angular-translate npm install github/myRepo/angular-translate/archive/master.tar.gz

第一个给了我一个没有构建的目录.只是一个 package.json、.npmignore 和一些 Markdown 文件

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

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

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...

对于我对这个话题的无知,我深表歉意.我没有大量的 npm 经验.很想得到一些关于这个问题的反馈.当需要对包的源代码进行修改时,这似乎是一个足够普遍的问题?也许有更好的解决方案?

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?

推荐答案

尝试npm install /,其中是您的 GitHub 用户名(不带 @)和 是存储库的名称.那应该正确安装它.您很可能希望在安装命令中使用 --save 或 --save-dev 标志来保存 package.json.

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.

如果这不能正常工作,请检查您的 .npmignore 文件的内容.

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

如果安装命令需要很长时间不要惊慌;从 git 存储库安装比从 npm 注册表安装慢.

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

您的问题是,在您的情况下,dist/ 未提交到存储库(因为它在 .gitignore 中).这就是实际代码所在的地方.dist/ 是在包发布到 npm 注册表之前从 src/ 中的文件构建的,但 dist/ 永远不会提交到 repo.

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.

这很难看,但在这种情况下,您必须从 .gitignore 中删除 dist/ 然后运行:

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

(确保你先运行了npm install)

然后您应该可以从 github 安装.

You then should be able to install from github.

使用 prepare 脚本可能还有另一种方法可以做到这一点,但我不确定这是否可行;我从来没有尝试过. Cameron Tacklind 写了一个很好的答案,详细说明了如何做到这一点:stackoverflow/a/57829251/7127751

There might be another way to do this using a prepare script, but I'm not sure if that's possible; I've never tried it. Cameron Tacklind has written an excellent answer detailing how to do this: stackoverflow/a/57829251/7127751

更多推荐

npm 安装和构建分叉的 github 存储库

本文发布于:2023-07-04 17:23:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1027037.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:npm   github

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!