Skip to content

Commit

Permalink
Ignore unsupported npm access for e.g. Nexus environments (fixes #700)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Sep 14, 2020
1 parent be98df3 commit 9411fb0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/npm.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ If there is a `package.json` but it should be ignored and nothing should be publ
To prevent issues later in the process, release-it first checks whether the npm registry is up, the user is
authenticated with npm and is a collaborator for the current package.

Some instances of npm registries, such as Nexus, do not support `npm ping` and/or `npm whoami`. If the error is a `E400`
or `E404`, release-it will give a warning but continue.
Some instances of npm registries, such as Nexus, do not support `npm ping`, `npm whoami` and/or `npm access`. If the
error is a `E400` or `E404`, release-it will give a warning but continue.

To skip these checks, use `npm.skipChecks`.

Expand Down
8 changes: 6 additions & 2 deletions lib/plugin/npm/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class npm extends Plugin {
() => true,
err => {
if (/code E40[04]|404.*(ping not found|No content for path)/.test(err)) {
this.log.warn('Ignoring unsupported `npm ping` command response.');
this.log.warn('Ignoring response from unsupported `npm ping` command.');
return true;
}
return false;
Expand All @@ -122,7 +122,7 @@ class npm extends Plugin {
err => {
this.debug(err);
if (/code E40[04]/.test(err)) {
this.log.warn('Ignoring unsupported `npm whoami` command response.');
this.log.warn('Ignoring response from unsupported `npm whoami` command.');
return true;
}
return false;
Expand Down Expand Up @@ -150,6 +150,10 @@ class npm extends Plugin {
},
err => {
this.debug(err);
if (/code E400/.test(err)) {
this.log.warn('Ignoring response from unsupported `npm access` command.');
return true;
}
return /code E404/.test(err);
}
);
Expand Down
9 changes: 6 additions & 3 deletions test/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,29 @@ test('should throw if npm is down', async t => {
exec.restore();
});

test('should not throw if npm returns 404 for unsupported ping/whoami', async t => {
test('should not throw if npm returns 400/404 for unsupported ping/whoami/access', async t => {
const npmClient = factory(npm);
const exec = sinon.stub(npmClient.shell, 'exec').resolves();
const pingError = "npm ERR! code E404\nnpm ERR! 404 Package '--ping' not found : ping";
const whoamiError = "npm ERR! code E404\nnpm ERR! 404 Package '--whoami' not found : whoami";
const accessError = 'npm ERR! code E400\nnpm ERR! 400 Bad Request - GET https://npm.example.org/-/collaborators';
exec.withArgs('npm ping').rejects(new Error(pingError));
exec.withArgs('npm whoami').rejects(new Error(whoamiError));
exec.withArgs('npm access').rejects(new Error(accessError));
await runTasks(npmClient);
t.is(exec.lastCall.args[0].trim(), 'npm publish . --tag latest');
exec.restore();
});

test('should not throw if npm returns 400 for unsupported ping/whoami', async t => {
test('should not throw if npm returns 400 for unsupported ping/whoami/access', async t => {
const npmClient = factory(npm);
const exec = sinon.stub(npmClient.shell, 'exec').resolves();
const pingError = 'npm ERR! code E400\nnpm ERR! 400 Bad Request - GET https://npm.example.org/-/ping?write=true';
const whoamiError = 'npm ERR! code E400\nnpm ERR! 400 Bad Request - GET https://npm.example.org/-/whoami';
const accessError = 'npm ERR! code E400\nnpm ERR! 400 Bad Request - GET https://npm.example.org/-/collaborators';
exec.withArgs('npm ping').rejects(new Error(pingError));
exec.withArgs('npm whoami').rejects(new Error(whoamiError));
exec.withArgs('npm access ls-collaborators release-it').resolves(JSON.stringify({ john: ['write'] }));
exec.withArgs('npm access').rejects(new Error(accessError));
await runTasks(npmClient);
t.is(exec.lastCall.args[0].trim(), 'npm publish . --tag latest');
exec.restore();
Expand Down

0 comments on commit 9411fb0

Please sign in to comment.