Skip to content

Commit 82df2ce

Browse files
scottgonzalezjzaefferer
authored andcommitted
NPM: Verify credentials upfront
Fixes gh-27 Closes jquerygh-36
1 parent 23aaee7 commit 82df2ce

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/npm.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
module.exports = function( Release ) {
22
Release.define({
3+
_getNpmUser: function() {
4+
var user = Release.exec( "npm whoami", { silent: true } );
5+
6+
if ( user.code !== 0 ) {
7+
Release.abort( "Error getting npm user." );
8+
}
9+
10+
if ( /^Not authed/.test( user.output ) ) {
11+
Release.abort( "You are not registered with npm." );
12+
}
13+
14+
return user.output.trim();
15+
},
16+
17+
_getNpmOwners: function() {
18+
var owners = Release.exec( "npm owner ls " + Release.project, { silent: true } );
19+
20+
if ( owners.code !== 0 ) {
21+
Release.abort( "Error getting npm owners." );
22+
}
23+
24+
return owners.output.trim().split( "\n" ).map(function( owner ) {
25+
return owner.split( " " )[ 0 ];
26+
});
27+
},
28+
29+
_checkNpmCredentials: function() {
30+
if ( !Release.npmPublish ) {
31+
return;
32+
}
33+
34+
var user = Release._getNpmUser(),
35+
owners = Release._getNpmOwners();
36+
37+
if ( owners.indexOf( user ) === -1 ) {
38+
Release.abort( user + " is not an owner of " + Release.project + " on npm." );
39+
}
40+
},
41+
342
_publishNpm: function() {
443
if ( !Release.npmPublish ) {
544
return;

release.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ commonTasks = [
2828
Release._section( "setting up repo" ),
2929
Release._cloneRepo,
3030
Release._checkRepoState,
31+
Release._checkNpmCredentials,
3132

3233
Release._section( "calculating versions" ),
3334
Release._getVersions,

0 commit comments

Comments
 (0)