Commit 63c2c73d authored by James Tharpe's avatar James Tharpe Committed by Achilleas Pipinellis

Fix instructions regarding `npm publish` registry

parent ba1c2b3e
...@@ -84,6 +84,28 @@ NOTE: **Note:** ...@@ -84,6 +84,28 @@ NOTE: **Note:**
If you encounter an error message with [Yarn](https://yarnpkg.com/en/), see the If you encounter an error message with [Yarn](https://yarnpkg.com/en/), see the
[troubleshooting section](#troubleshooting). [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 ## Uploading packages
Before you will be able to upload a package, you need to specify the registry 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): ...@@ -145,3 +167,29 @@ with your with your OAuth or personal access token):
```text ```text
//gitlab.com/api/v4/projects/:_authToken=<your_oauth_token> //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/
```
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment