Skip to content

Commit c6ef15d

Browse files
committed
Fix compatibility with some external registries
Fixes #420
1 parent 02b4ed9 commit c6ef15d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

source/npm/util.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,19 @@ export const collaborators = async package_ => {
110110
return stdout;
111111
} catch (error) {
112112
throwIfNpmTimeout(error);
113+
113114
// Ignore non-existing package error
114115
if (error.stderr.includes('code E404')) {
115116
return false;
116117
}
117118

119+
// External registries often don't support this endpoint, so ignore errors.
120+
// The whoami check is sufficient for verifying authentication.
121+
// See: https://github.com/sindresorhus/np/issues/420
122+
if (isExternalRegistry(package_)) {
123+
return false;
124+
}
125+
118126
throw error;
119127
}
120128
};

test/npm/util/collaborators.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,25 @@ test('non-existent', createFixture, [{
6262
);
6363
});
6464

65-
test('error', createFixture, [{
65+
test('error on default registry', createFixture, [{
6666
command: accessCommand('@private/pkg'),
6767
stderr: 'npm ERR! code E403\nnpm ERR! 403 403 Forbidden',
6868
}], async ({t, testedModule: {collaborators}}) => {
6969
const {stderr} = await t.throwsAsync(collaborators({name: '@private/pkg'}));
7070
t.is(stderr, 'npm ERR! code E403\nnpm ERR! 403 403 Forbidden');
7171
});
7272

73+
test('error on external registry - returns false', createFixture, [{
74+
command: `${accessCommand('@private/pkg')} --registry http://my-internal-registry.local`,
75+
stderr: 'npm ERR! code E403\nnpm ERR! 403 403 Forbidden',
76+
}], async ({t, testedModule: {collaborators}}) => {
77+
// Errors should return false instead of throwing, since external registries
78+
// often don't support the collaborators endpoint.
79+
// See: https://github.com/sindresorhus/np/issues/420
80+
t.is(await collaborators({
81+
name: '@private/pkg',
82+
publishConfig: {
83+
registry: 'http://my-internal-registry.local',
84+
},
85+
}), false);
86+
});

0 commit comments

Comments
 (0)