{"id":21479337,"url":"https://github.com/bambooom/gh-pkg-demo","last_synced_at":"2025-03-17T08:42:21.462Z","repository":{"id":118775295,"uuid":"266926530","full_name":"bambooom/gh-pkg-demo","owner":"bambooom","description":"demo for how to use github package registry","archived":false,"fork":false,"pushed_at":"2020-05-27T02:12:13.000Z","size":85,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T18:15:52.737Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bambooom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-26T02:32:26.000Z","updated_at":"2023-02-06T07:35:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"fc65646a-606b-43f1-9ac9-dd8a2e2a2357","html_url":"https://github.com/bambooom/gh-pkg-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bambooom%2Fgh-pkg-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bambooom%2Fgh-pkg-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bambooom%2Fgh-pkg-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bambooom%2Fgh-pkg-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bambooom","download_url":"https://codeload.github.com/bambooom/gh-pkg-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244004214,"owners_count":20382344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-23T11:24:44.828Z","updated_at":"2025-03-17T08:42:21.436Z","avatar_url":"https://github.com/bambooom.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gh-pkg-demo\n\nExample package to use GitHub Package Registry.\n\n## How to use GitHub Package Registry\n\n### 1. Generate Personal Access Token\n\n- To download and install packages from GitHub Package Registry, you need a token with `read:packages` and `repo` scopes.\n- To upload and publish packages, you need a token with `write:packages` and `repo` scopes.\n- To delete a package with specified version, you need a token with `delete:packages` and `repo` scopes\n\nGenerate the token according to your need.\n\n### 2. Local config TOKEN\n\nAdd the generated token to the local file `~/.npmrc` like:\n\n```\n//npm.pkg.github.com/:_authToken=TOKEN\n```\n\nCreate the file `.npmrc` if it doesn't exist.\n\nIf you don't want to copy TOKEN in the local file, then one should log in by `npm login` command and input the info with prompt like:\n\n```\n$ npm login --registry=https://npm.pkg.github.com\n\u003e Username: USERNAME\n\u003e Password: TOKEN\n\u003e Email: PUBLIC-EMAIL-ADDRESS\n```\n\n### 3. Project Config to publish to GitHub\n\n[Edit the `package.json` file to specify the registry as GitHub](https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages#publishing-a-package-using-publishconfig-in-the-packagejson-file).\nAnd also the package name must be scoped with the onwer.\n\n```diff\n--- \"name\": \"gh-pkg-demo\",\n+++ \"name\": \"@bambooom/gh-pkg-demo\",\n+++ \"publishConfig\": {\n+++   \"registry\": \"https://npm.pkg.github.com/\"\n+++ },\n```\n\nAlternative way to config the project is [using local `.npmrc` file](https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages#publishing-a-package-using-a-local-npmrc-file).\nThat is adding a local `.npmrc` under project root, and adding this to the file:\n\n```\nregistry=https://npm.pkg.github.com/OWNER\n```\n\n### 4. Publish packages\nTo publish the package to GitHub, just use the command:\n\n```\n$ npm publish\n```\n\nYou can see the package on GitHub:\n\n![](./gh-pkg.png)\n\n### 5. Install packages\n\nTo install packages from GitHub package registry, need a local `.npmrc` file to set the registry.\n\n```\nregistry=https://npm.pkg.github.com/OWNER\n```\n\nBut if this is the only setting, all package requests will go through GitHub Packages.\n\n\u003e You also need to add the *.npmrc* file to your project so all requests to install packages will go through GitHub Packages. When you route all package requests through GitHub Packages, you can use both scoped and unscoped packages from *npmjs.com*.\n\nSo, the github package requests will do the check whether the package can be found on\ngithub. If not, it will go to *npmjs.com* to search for the packages.\n\nHowever, I found that the check request will be timeout randomly.\nI'd like to skip the check for other packages I want to download from *npmjs.com*.\n\nI try to change the setting in `.npmrc` like this to achive this goal:\n\n```\nregistry=https://registry.npmjs.org/\n@OWNER:registry=https://npm.pkg.github.com\n```\n\nWith this setting, default registry is *npmjs.com*. Only `@OWNER`'s packages, use the GitHub registry.\n\nThen use the command to install:\n\n```\nnpm install @bambooom/gh-pkg-demo\n```\n\nThen inside `package-lock.json`, the package is resolved by GitHub registry like:\n\n```\n\"@bambooom/gh-pkg-demo\": {\n  \"version\": \"1.0.0\",\n  \"resolved\": \"https://npm.pkg.github.com/download/@bambooomgh-pkg-demo/1.0.00ec13dcce4a2f9510111a8b88957c3436a0e04633d0208aa71dfa5f7804b67ff\",\n  \"integrity\": \"....\"\n},\n```\n\n## Refs\n- [GitHub Packages Tokens](https://help.github.com/en/packages/publishing-and-managing-packages/about-github-packages#about-tokens)\n- [Creating a personal access token for the command line](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line)\n- [Configuring npm for use with GitHub Packages](https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbambooom%2Fgh-pkg-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbambooom%2Fgh-pkg-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbambooom%2Fgh-pkg-demo/lists"}