Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM install/dependency from a GitHub Release Binary

I know how to make an NPM dependency from a GitHub release :

"dependencies": {
  "package-name": "user/repo#v1.0.0"
}

That's nice, but I want to install a specific binary from this release.

I tried

"dependencies": {
  "package-name": "https://github.com/user/repo/releases/download/v1.0.0/bin.tgz"
}

But I gives me the following error :

❯ npm install
npm ERR! fetch failed https://github.com/user/repo/releases/download/v1.0.0/bin.tgz
npm WARN retry will retry, error on last attempt: Error: fetch failed with status code 404

Binary release assets exist outside of GitHub and are using AWS S3.

The URL github.com/user/repo/releases/download/v1.0.0/bin.tgz is redirecting with a 302 status and a HTTP location header set to https://github-cloud.s3.amazonaws.com/releases/XXX/XXX...

If I try directly with the S3 URL I got a ENAMETOOLONG error (see NPM issue) :

> npm install https://github-cloud.s3.amazonaws.com/releases/XXX/XXX...
npm ERR! tarball.destroy is not a function
npm WARN retry will retry, error on last attempt: Error: ENAMETOOLONG: name too long, open '/var/folders/pn/......

Questions :

  • Why is NPM not following the redirect?
  • Why a 404?
  • Is there a way to link an NPM dependency to a GitHub release's binary tarball? How?

My context and needs :

  • I have a private GitHub repository
  • My package needs to be built before "deploying" (transpilation, etc.)
  • I want to "publish" a tarball of this build in my GitHub release and directly reference it to my NPM dependencies
  • I use a CI service to build, make the tarball and upload it next to the GitHub release
  • I would like to use GitHub release binary as a NPM repository

Related

  • SO question: How to install an npm package from GitHub directly?
  • NPM issue: https://github.com/npm/npm/issues/3055
like image 549
Yves M. Avatar asked Jul 07 '16 09:07

Yves M.


People also ask

How do I install dependencies on GitHub?

To npm install a public project that is hosted on Github, and not the NPM registry, add the Github repo to package. json dependencies using the username/repo#branch-name format. Run npm install and npm will download the project and save it into your /node_modules/ folder.

How do I install npm dependencies?

NPM installs devDependencies within the package. json file. The 'npm install' command should add all the dependencies and devDependencies automatically during installation. If you need to add specific devDependencies to your project, you can use this command- 'npm install --save-dev'.


1 Answers

I don't think npm provides a way to do this as per their documentation, they support using github's tarballs but not a specific binary attached to a release. https://docs.npmjs.com/cli/install The only way I see it would work is downloading the file and using the "tarball file" way described in the "npm install" docs.

I'm in the same boat and I think I'll end up using npm private repositories.

like image 105
Leandro Almeida Avatar answered Oct 17 '22 04:10

Leandro Almeida