Skip to content

Commit f089d9d

Browse files
authored
fix(README): correct docs on authentication (#413)
1 parent d47164d commit f089d9d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
| Step | Description |
1010
|--------------------|-------------|
11-
| `verifyConditions` | Verify the presence of the `NPM_TOKEN` environment variable, create or update the `.npmrc` file with the token and verify the token is valid. |
11+
| `verifyConditions` | Verify the presence of the `NPM_TOKEN` environment variable, or an `.npmrc` file, and verify the authentication method is valid. |
1212
| `prepare` | Update the `package.json` version and [create](https://docs.npmjs.com/cli/pack) the npm package tarball. |
1313
| `addChannel` | [Add a release to a dist-tag](https://docs.npmjs.com/cli/dist-tag). |
1414
| `publish` | [Publish the npm package](https://docs.npmjs.com/cli/publish) to the registry. |
@@ -41,7 +41,9 @@ The npm authentication configuration is **required** and can be set via [environ
4141

4242
Both the [token](https://docs.npmjs.com/getting-started/working_with_tokens) and the legacy (`username`, `password` and `email`) authentication are supported. It is recommended to use the [token](https://docs.npmjs.com/getting-started/working_with_tokens) authentication. The legacy authentication is supported as the alternative npm registries [Artifactory](https://www.jfrog.com/open-source/#os-arti) and [npm-registry-couchapp](https://github.com/npm/npm-registry-couchapp) only supports that form of authentication.
4343

44-
**Note**: Only the `auth-only` [level of npm two-factor authentication](https://docs.npmjs.com/getting-started/using-two-factor-authentication#levels-of-authentication) is supported, **semantic-release** will not work with the default `auth-and-writes` level.
44+
**Notes**:
45+
- Only the `auth-only` [level of npm two-factor authentication](https://docs.npmjs.com/getting-started/using-two-factor-authentication#levels-of-authentication) is supported, **semantic-release** will not work with the default `auth-and-writes` level.
46+
- The presence of an `.npmrc` file will override any specified environment variables.
4547

4648
### Environment variables
4749

test/set-npmrc-auth.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,30 @@ test.serial('Throw error if "NPM_EMAIL" is missing', async (t) => {
212212
t.is(error.message, 'No npm token specified.');
213213
t.is(error.code, 'ENONPMTOKEN');
214214
});
215+
216+
test.serial('Prefer .npmrc over environment variables', async (t) => {
217+
process.env.HOME = tempy.directory();
218+
const cwd = tempy.directory();
219+
process.chdir(cwd);
220+
const npmrc = tempy.file({name: '.npmrc'});
221+
// Specify an NPM token environment variable
222+
const env = {NPM_TOKEN: 'env_npm_token'};
223+
224+
await appendFile(path.resolve(cwd, '.npmrc'), '//registry.npmjs.org/:_authToken=npmrc_npm_token');
225+
226+
await require('../lib/set-npmrc-auth')(npmrc, 'http://registry.npmjs.org', {cwd, env, logger: t.context.logger});
227+
228+
t.is(
229+
(await readFile(npmrc)).toString(),
230+
// Assert did not write the token from environment variable
231+
`//registry.npmjs.org/:_authToken=npmrc_npm_token`
232+
);
233+
234+
// Assert reads from config
235+
t.deepEqual(t.context.log.args[1], ['Reading npm config from %s', path.resolve(cwd, '.npmrc')]);
236+
237+
// Assert does not write NPM_TOKEN
238+
for (const log of t.context.log.args) {
239+
t.false(log.includes('Wrote NPM_TOKEN'));
240+
}
241+
});

0 commit comments

Comments
 (0)