简体   繁体   English

从 GitHub 存储库安装包

[英]Installing a package from a GitHub repository

My problem is that when I try to install a package of mine with the version set to a certain git branch my build is breaking because the repository doesn't house the dist folder which my npm package does.我的问题是,当我尝试安装我的软件包并将版本设置为某个 git 分支时,我的构建中断了,因为存储库没有包含我的 npm 软件包所做的dist文件夹。

Here is how I want to install the package.这是我想要安装软件包的方式。 @me/myPkg": "github:me/myPkg#myBranch

So should my repository include the dist folder or what's the best practice in this case?那么我的存储库是否应该包含 dist 文件夹,或者在这种情况下最佳实践是什么? I don't want to publish my dist package onto github because then I would have weird merge conflicts because the dist folder is containg all of my type declaration and minified javascript files, but maybe this the preferred way?我不想将我的 dist 包发布到 github 上,因为那样我会遇到奇怪的合并冲突,因为 dist 文件夹包含我所有的类型声明和缩小的 javascript 文件,但这也许是首选方式?

Another thought I had was to have a postinstall script in my package.json which built the source files but then I would have to have the devDependencies installed as well and npm install doesn't install them for dependencies.我的另一个想法是在我的 package.json 中有一个 postinstall 脚本,它构建了源文件,但是我必须同时安装 devDependencies 并且 npm install 不会为依赖项安装它们。

How are you publishing your package?你如何发布你的包? For instance, I have a GitHub Actions setup on my repositories that, when commits are made to master , will automatically perform several steps例如,我在我的存储库上有一个GitHub Actions设置,当提交到master ,将自动执行几个步骤

  • Run an npm install Setup Git Credential variables (for later process)运行npm install Setup Git Credential variables(用于以后的过程)

  • Run npm test (and fail whole process if tests fail)运行npm test (如果测试失败则整个过程失败)

  • Run npm run release (I use standard-version for auto version incrementing and Changelog creation, and do this prior to build so the version can be reflected in the built code)运行npm run release (我使用standard-version进行自动版本递增和更改日志创建,并在构建之前执行此操作,以便版本可以反映在构建的代码中)

  • Run npm run build运行npm run build

  • Run npm run publish to push to npm运行npm run publish推送到 npm

  • Commit my version update as a tag to Git将我的版本更新作为标记提交给 Git

My GitHub Action does all of this in a temp container it spins up for the build process.我的 GitHub Action 在它为构建过程启动的临时容器中完成所有这些。 Once it is done, the whole container is tossed.完成后,整个容器都被扔掉了。 I use an .npmignore file to tell publish what I don't want in the final package (note files, build tools, etc).我使用.npmignore文件来告诉在最终包中publish我不想要的内容(注释文件、构建工具等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM