PageRenderTime 28ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/user/project/packages/npm_registry.md

https://gitlab.com/alexcern/gitlab-ee
Markdown | 120 lines | 83 code | 37 blank | 0 comment | 0 complexity | d6cd0600269ad40accb940a3a19735a4 MD5 | raw file
  1. # GitLab NPM Registry **[PREMIUM]**
  2. > [Introduced](https://gitlab.com/gitlab-org/gitlab-ee/issues/5934)
  3. in [GitLab Premium](https://about.gitlab.com/pricing/) 11.7.
  4. With the GitLab NPM Registry, every
  5. project can have its own space to store NPM packages.
  6. ![GitLab NPM Registry](img/npm_package_view.png)
  7. NOTE: **Note:**
  8. Only [scoped](https://docs.npmjs.com/misc/scope) packages are supported.
  9. NOTE: **Note:**
  10. As `@group/subgroup/project` is not a valid NPM package name, publishing a package
  11. within a subgroup is not supported yet.
  12. ## Enabling the NPM Registry
  13. NOTE: **Note:**
  14. This option is available only if your GitLab administrator has
  15. [enabled support for the NPM registry](https://docs.gitlab.com/ee/administration/packages.html).**[PREMIUM ONLY]**
  16. After the NPM registry is enabled, it will be available for all new projects
  17. by default. To enable it for existing projects, or if you want to disable it:
  18. 1. Navigate to your project's **Settings > General > Permissions**.
  19. 1. Find the Packages feature and enable or disable it.
  20. 1. Click on **Save changes** for the changes to take effect.
  21. You should then be able to see the **Packages** section on the left sidebar.
  22. Before proceeding to authenticating with the GitLab NPM Registry, you should
  23. get familiar with the package naming convention.
  24. ## Package naming convention
  25. **Only packages that have the same path as the project** are supported. For
  26. example:
  27. | Project | Package | Supported |
  28. | ---------------------- | ----------------------- | --------- |
  29. | `foo/bar` | `@foo/bar` | Yes |
  30. | `gitlab-org/gitlab-ce` | `@gitlab-org/gitlab-ce` | Yes |
  31. | `gitlab-org/gitlab-ce` | `@foo/bar` | No |
  32. Now, you can configure your project to authenticate with the GitLab NPM
  33. Registry.
  34. ## Authenticating to the GitLab NPM Registry
  35. If a project is private or you want to upload an NPM package to GitLab,
  36. credentials will need to be provided for authentication. Support is available
  37. only for [OAuth tokens](../../../api/oauth2.md#resource-owner-password-credentials-flow).
  38. CAUTION: **2FA not supported:**
  39. Authentication for personal access tokens is not yet supported
  40. ([#9140](https://gitlab.com/gitlab-org/gitlab-ee/issues/9140)). If you have 2FA
  41. enabled, you won't be able to authenticate to the GitLab NPM Registry.
  42. ### Authenticating with an OAuth token
  43. To authenticate with an [OAuth token](../../../api/oauth2.md#resource-owner-password-credentials-flow),
  44. add a corresponding section to your `.npmrc` file:
  45. ```ini
  46. ; Set URL for your scoped packages.
  47. ; For example package with name `@foo/bar` will use this URL for download
  48. @foo:registry=https://gitlab.com/api/v4/packages/npm/
  49. ; Add the OAuth token for the scoped packages URL. This will allow you to download
  50. ; `@foo/` packages from private projects.
  51. //gitlab.com/api/v4/packages/npm/:_authToken=<your_oauth_token>
  52. ; Add OAuth token for uploading to the registry. Replace <your_project_id>
  53. ; with the project you want your package to be uploaded to.
  54. //gitlab.com/api/v4/projects/<your_project_id>/packages/npm/:_authToken=<your_oauth_token>
  55. ```
  56. Replace `<your_project_id>` with your project ID which can be found on the home page
  57. of your project and `<your_oauth_token>` with your OAuth token.
  58. If you have a self-hosted GitLab installation, replace `gitlab.com` with your
  59. domain name.
  60. You should now be able to download and upload NPM packages to your project.
  61. ## Uploading packages
  62. Before you will be able to upload a package, you need to specify the registry
  63. for NPM. To do this, add the following section to the bottom of `package.json`:
  64. ```json
  65. "publishConfig": {
  66. "@foo:registry":"https://gitlab.com/api/v4/projects/<your_project_id>/packages/npm/"
  67. }
  68. ```
  69. Replace `<your_project_id>` with your project ID, which can be found on the home
  70. page of your project, and replace `@foo` with your own scope.
  71. If you have a self-hosted GitLab installation, replace `gitlab.com` with your
  72. domain name.
  73. Once you have enabled it and set up [authentication](#authenticating-to-the-gitlab-npm-registry),
  74. you can upload an NPM package to your project:
  75. ```sh
  76. npm publish
  77. ```
  78. You can then navigate to your project's **Packages** page and see the uploaded
  79. packages or even delete them.
  80. ## Uploading a package with the same version twice
  81. If you upload a package with a same name and version twice, GitLab will show
  82. both packages in the UI, but the GitLab NPM Registry will expose the most recent
  83. one as it supports only one package per version for `npm install`.