summaryrefslogtreecommitdiff
path: root/doc/user/packages/npm_registry
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-19 18:06:18 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-19 18:06:18 +0000
commit81f7adf08b4557c38ac2ef1c730e72e07db2f1a3 (patch)
tree37239c312903ca5e6ca079b64c35a6e0e01b18c4 /doc/user/packages/npm_registry
parent383daa1200fb0b8859e2b6ec0eb55f4615538749 (diff)
downloadgitlab-ce-81f7adf08b4557c38ac2ef1c730e72e07db2f1a3.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/user/packages/npm_registry')
-rw-r--r--doc/user/packages/npm_registry/index.md48
1 files changed, 48 insertions, 0 deletions
diff --git a/doc/user/packages/npm_registry/index.md b/doc/user/packages/npm_registry/index.md
index 6d11ab603ef..5f5d86ab17e 100644
--- a/doc/user/packages/npm_registry/index.md
+++ b/doc/user/packages/npm_registry/index.md
@@ -84,6 +84,28 @@ NOTE: **Note:**
If you encounter an error message with [Yarn](https://yarnpkg.com/en/), see the
[troubleshooting section](#troubleshooting).
+### Using variables to avoid hard-coding auth token values
+
+To avoid hard-coding the `authToken` value, you may use a variables in its place.
+In your `.npmrc` file, you would add:
+
+```ini
+@foo:registry=https://gitlab.com/api/v4/packages/npm/
+//gitlab.com/api/v4/packages/npm/:_authToken=${NPM_TOKEN}
+//gitlab.com/api/v4/projects/<your_project_id>/packages/npm/:_authToken=${NPM_TOKEN}
+```
+
+Then, you could run `npm publish` either locally or via GitLab CI/CD:
+
+- **Locally:** Export `NPM_TOKEN` before publishing:
+
+ ```sh
+ NPM_TOKEN=<your_token> npm publish
+ ```
+
+- **GitLab CI/CD:** Set an `NPM_TOKEN` [variable](../../../ci/variables/README.md)
+ under your project's **Settings > CI/CD > Variables**.
+
## Uploading packages
Before you will be able to upload a package, you need to specify the registry
@@ -145,3 +167,29 @@ with your with your OAuth or personal access token):
```text
//gitlab.com/api/v4/projects/:_authToken=<your_oauth_token>
```
+
+### `npm publish` targets default NPM registry (`registry.npmjs.org`)
+
+Ensure that your package scope is set consistently in your `package.json` and `.npmrc` files.
+
+For example, if your project name in GitLab is `foo/my-package`, then your `package.json` file
+should look like:
+
+```json
+{
+ "name": "@foo/my-package",
+ "version": "1.0.0",
+ "description": "Example package for GitLab NPM registry",
+ "publishConfig": {
+ "@foo:registry":"https://gitlab.com/api/v4/projects/<your_project_id>/packages/npm/"
+ }
+}
+```
+
+And the `.npmrc` file should look like:
+
+```ini
+//gitlab.com/api/v4/projects/<your_project_id>/packages/npm/:_authToken=<your_oauth_token>
+//gitlab.com/api/v4/packages/npm/:_authToken=<your_oauth_token>
+@foo:registry=https://gitlab.com/api/v4/packages/npm/
+```