Skip to content

Commit 9dd97c4

Browse files
fahslajFrozenPandaz
authored andcommitted
fix(release): respect root .npmrc registry settings for publishing
(cherry picked from commit 12afa20)
1 parent 66e254c commit 9dd97c4

File tree

12 files changed

+1164
-104
lines changed

12 files changed

+1164
-104
lines changed

docs/generated/manifests/menus.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,14 @@
23002300
"children": [],
23012301
"disableCollapsible": false
23022302
},
2303+
{
2304+
"name": "Configure Custom Registries",
2305+
"path": "/recipes/nx-release/configure-custom-registries",
2306+
"id": "configure-custom-registries",
2307+
"isExternal": false,
2308+
"children": [],
2309+
"disableCollapsible": false
2310+
},
23032311
{
23042312
"name": "Publish in CI/CD",
23052313
"path": "/recipes/nx-release/publish-in-ci-cd",
@@ -4140,6 +4148,14 @@
41404148
"children": [],
41414149
"disableCollapsible": false
41424150
},
4151+
{
4152+
"name": "Configure Custom Registries",
4153+
"path": "/recipes/nx-release/configure-custom-registries",
4154+
"id": "configure-custom-registries",
4155+
"isExternal": false,
4156+
"children": [],
4157+
"disableCollapsible": false
4158+
},
41434159
{
41444160
"name": "Publish in CI/CD",
41454161
"path": "/recipes/nx-release/publish-in-ci-cd",
@@ -4207,6 +4223,14 @@
42074223
"children": [],
42084224
"disableCollapsible": false
42094225
},
4226+
{
4227+
"name": "Configure Custom Registries",
4228+
"path": "/recipes/nx-release/configure-custom-registries",
4229+
"id": "configure-custom-registries",
4230+
"isExternal": false,
4231+
"children": [],
4232+
"disableCollapsible": false
4233+
},
42104234
{
42114235
"name": "Publish in CI/CD",
42124236
"path": "/recipes/nx-release/publish-in-ci-cd",

docs/generated/manifests/nx.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,6 +3145,17 @@
31453145
"path": "/recipes/nx-release/automatically-version-with-conventional-commits",
31463146
"tags": ["nx-release"]
31473147
},
3148+
{
3149+
"id": "configure-custom-registries",
3150+
"name": "Configure Custom Registries",
3151+
"description": "",
3152+
"mediaImage": "",
3153+
"file": "shared/recipes/nx-release/configure-custom-registries",
3154+
"itemList": [],
3155+
"isExternal": false,
3156+
"path": "/recipes/nx-release/configure-custom-registries",
3157+
"tags": ["nx-release"]
3158+
},
31483159
{
31493160
"id": "publish-in-ci-cd",
31503161
"name": "Publish in CI/CD",
@@ -5668,6 +5679,17 @@
56685679
"path": "/recipes/nx-release/automatically-version-with-conventional-commits",
56695680
"tags": ["nx-release"]
56705681
},
5682+
{
5683+
"id": "configure-custom-registries",
5684+
"name": "Configure Custom Registries",
5685+
"description": "",
5686+
"mediaImage": "",
5687+
"file": "shared/recipes/nx-release/configure-custom-registries",
5688+
"itemList": [],
5689+
"isExternal": false,
5690+
"path": "/recipes/nx-release/configure-custom-registries",
5691+
"tags": ["nx-release"]
5692+
},
56715693
{
56725694
"id": "publish-in-ci-cd",
56735695
"name": "Publish in CI/CD",
@@ -5761,6 +5783,17 @@
57615783
"path": "/recipes/nx-release/automatically-version-with-conventional-commits",
57625784
"tags": ["nx-release"]
57635785
},
5786+
"/recipes/nx-release/configure-custom-registries": {
5787+
"id": "configure-custom-registries",
5788+
"name": "Configure Custom Registries",
5789+
"description": "",
5790+
"mediaImage": "",
5791+
"file": "shared/recipes/nx-release/configure-custom-registries",
5792+
"itemList": [],
5793+
"isExternal": false,
5794+
"path": "/recipes/nx-release/configure-custom-registries",
5795+
"tags": ["nx-release"]
5796+
},
57645797
"/recipes/nx-release/publish-in-ci-cd": {
57655798
"id": "publish-in-ci-cd",
57665799
"name": "Publish in CI/CD",

docs/generated/manifests/tags.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,13 @@
532532
"name": "Automatically Version with Conventional Commits",
533533
"path": "/recipes/nx-release/automatically-version-with-conventional-commits"
534534
},
535+
{
536+
"description": "",
537+
"file": "shared/recipes/nx-release/configure-custom-registries",
538+
"id": "configure-custom-registries",
539+
"name": "Configure Custom Registries",
540+
"path": "/recipes/nx-release/configure-custom-registries"
541+
},
535542
{
536543
"description": "",
537544
"file": "shared/recipes/nx-release/publish-in-ci-cd",

docs/map.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,12 @@
11321132
"tags": ["nx-release"],
11331133
"file": "shared/recipes/nx-release/automatically-version-with-conventional-commits"
11341134
},
1135+
{
1136+
"name": "Configure Custom Registries",
1137+
"id": "configure-custom-registries",
1138+
"tags": ["nx-release"],
1139+
"file": "shared/recipes/nx-release/configure-custom-registries"
1140+
},
11351141
{
11361142
"name": "Publish in CI/CD",
11371143
"id": "publish-in-ci-cd",
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Configure Custom Registries
2+
3+
To publish JavaScript packages, Nx Release uses the `npm` CLI under the hood, which defaults to publishing to the `npm` registry (`https://registry.npmjs.org/`). If you need to publish to a different registry, you can configure the registry in the `.npmrc` file in the root of your workspace or at the project level in the project configuration.
4+
5+
## Set the Registry in the Root .npmrc File
6+
7+
The easiest way to configure a custom registry is to set it in the `npm` configuration via the root `.npmrc` file. This file is located in the root of your workspace, and Nx Release will use it for publishing all projects. To set the registry, add the 'registry' property to your root `.npmrc` file:
8+
9+
```bash .npmrc
10+
registry=https://my-custom-registry.com/
11+
```
12+
13+
### Authenticate to the Registry in CI
14+
15+
To authenticate with a custom registry in CI, you can add authentication tokens to the `.npmrc` file:
16+
17+
```bash .npmrc
18+
registry=https://my-custom-registry.com/
19+
//my-custom-registry.com/:_authToken=<TOKEN>
20+
```
21+
22+
See the [npm documentation](https://docs.npmjs.com/cli/v10/configuring-npm/npmrc#auth-related-configuration) for more information.
23+
24+
## Configure Multiple Registries
25+
26+
The recommended way to determine which registry packages are published to is by using [npm scopes](https://docs.npmjs.com/cli/v10/using-npm/scope). All packages with a name that starts with your scope will be published to the registry specified in the `.npmrc` file for that scope. Consider the following example:
27+
28+
```bash .npmrc
29+
@my-scope:registry=https://my-custom-registry.com/
30+
//my-custom-registry.com/:_authToken=<TOKEN>
31+
32+
@other-scope:registry=https://my-other-registry.com/
33+
//my-other-registry.com/:_authToken=<OTHER_TOKEN>
34+
35+
registry=https://my-default-registry.com/
36+
//my-default-registry.com/:_authToken=<DEFAULT_TOKEN>
37+
```
38+
39+
With the above `.npmrc`, the following packages would be published to the specified registries:
40+
41+
- `@my-scope/pkg-1` -> `https://my-custom-registry.com/`
42+
- `@other-scope/pkg-2` -> `https://my-other-registry.com/`
43+
- `pkg-3` -> `https://my-default-registry.com/`
44+
45+
## Specify an Alternate Registry for a Single Package
46+
47+
In some cases, you may want to configure the registry on a per-package basis instead of by scope. This can be done by setting options in the project's configuration.
48+
49+
{% callout type="info" title="Authentication" %}
50+
All registries set for specific packages must still have authentication tokens set in the root `.npmrc` file for publishing in CI. See [Authenticate to the Registry in CI](#authenticate-to-the-registry-in-ci) for an example.
51+
{% /callout %}
52+
53+
### Set the Registry in the Project Configuration
54+
55+
The project configuration for Nx Release is in two parts - one for the version step and one for the publish step.
56+
57+
#### Update the Version Step
58+
59+
The version step of Nx Release is responsible for determining the new version of the package. If you have set the `version.generatorOptions.currentVersionResolver` to 'registry', then Nx Release will check the remote registry for the current version of the package.
60+
61+
**Note:** If you do not use the 'registry' current version resolver, then this step is not needed.
62+
63+
To set custom registry options for the current version lookup, add the registry and/or tag to the `currentVersionResolverMetadata` in the project configuration:
64+
65+
```json project.json
66+
{
67+
"name": "pkg-5",
68+
"sourceRoot": "...",
69+
"targets": {
70+
...
71+
},
72+
"release": {
73+
"version": {
74+
"generatorOptions": {
75+
"currentVersionResolverMetadata": {
76+
"registry": "https://my-unique-registry.com/",
77+
"tag": "next"
78+
}
79+
}
80+
}
81+
}
82+
}
83+
```
84+
85+
#### Update the Publish Step
86+
87+
The publish step of Nx Release is responsible for publishing the package to the registry. To set custom registry options for publishing, you can add the `registry` and/or `tag` options for the `nx-release-publish` target in the project configuration:
88+
89+
```json project.json
90+
{
91+
"name": "pkg-5",
92+
"sourceRoot": "...",
93+
"targets": {
94+
...,
95+
"nx-release-publish": {
96+
"options": {
97+
"registry": "https://my-unique-registry.com/",
98+
"tag": "next"
99+
}
100+
}
101+
}
102+
}
103+
```
104+
105+
### Set the Registry in the Package Manifest
106+
107+
{% callout type="caution" title="Caution" %}
108+
It is not recommended to set the registry for a package in the 'publishConfig' property of its 'package.json' file. 'npm publish' will always prefer the registry from the 'publishConfig' over the '--registry' argument. Because of this, the '--registry' CLI and programmatic API options of Nx Release will no longer be able to override the registry for purposes such as publishing locally for end to end testing.
109+
{% /callout %}

docs/shared/reference/sitemap.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
- [Get Started with Nx Release](/recipes/nx-release/get-started-with-nx-release)
181181
- [Release Projects Independently](/recipes/nx-release/release-projects-independently)
182182
- [Automatically Version with Conventional Commits](/recipes/nx-release/automatically-version-with-conventional-commits)
183+
- [Configure Custom Registries](/recipes/nx-release/configure-custom-registries)
183184
- [Publish in CI/CD](/recipes/nx-release/publish-in-ci-cd)
184185
- [Automate GitHub Releases](/recipes/nx-release/automate-github-releases)
185186
- [Publish Rust Crates](/recipes/nx-release/publish-rust-crates)

0 commit comments

Comments
 (0)