@@ -5,13 +5,19 @@ const semver = require('semver')
5
5
6
6
const otplease = require ( './utils/otplease.js' )
7
7
const readLocalPkgName = require ( './utils/read-local-package.js' )
8
+ const getWorkspaces = require ( './workspaces/get-workspaces.js' )
8
9
const BaseCommand = require ( './base-command.js' )
9
10
10
11
class DistTag extends BaseCommand {
11
12
static get description ( ) {
12
13
return 'Modify package distribution tags'
13
14
}
14
15
16
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
17
+ static get params ( ) {
18
+ return [ 'workspace' , 'workspaces' ]
19
+ }
20
+
15
21
/* istanbul ignore next - see test/lib/load-all-commands.js */
16
22
static get name ( ) {
17
23
return 'dist-tag'
@@ -43,15 +49,14 @@ class DistTag extends BaseCommand {
43
49
44
50
async distTag ( [ cmdName , pkg , tag ] ) {
45
51
const opts = this . npm . flatOptions
46
- const has = ( items ) => new Set ( items ) . has ( cmdName )
47
52
48
- if ( has ( [ 'add' , 'a' , 'set' , 's' ] ) )
53
+ if ( [ 'add' , 'a' , 'set' , 's' ] . includes ( cmdName ) )
49
54
return this . add ( pkg , tag , opts )
50
55
51
- if ( has ( [ 'rm' , 'r' , 'del' , 'd' , 'remove' ] ) )
56
+ if ( [ 'rm' , 'r' , 'del' , 'd' , 'remove' ] . includes ( cmdName ) )
52
57
return this . remove ( pkg , tag , opts )
53
58
54
- if ( has ( [ 'ls' , 'l' , 'sl' , 'list' ] ) )
59
+ if ( [ 'ls' , 'l' , 'sl' , 'list' ] . includes ( cmdName ) )
55
60
return this . list ( pkg , opts )
56
61
57
62
if ( ! pkg ) {
@@ -62,6 +67,33 @@ class DistTag extends BaseCommand {
62
67
throw this . usage
63
68
}
64
69
70
+ execWorkspaces ( args , filters , cb ) {
71
+ this . distTagWorkspaces ( args , filters ) . then ( ( ) => cb ( ) ) . catch ( cb )
72
+ }
73
+
74
+ async distTagWorkspaces ( [ cmdName , pkg , tag ] , filters ) {
75
+ // cmdName is some form of list
76
+ // pkg is one of:
77
+ // - unset
78
+ // - .
79
+ // - .@version
80
+ if ( [ 'ls' , 'l' , 'sl' , 'list' ] . includes ( cmdName ) && ( ! pkg || pkg === '.' || / ^ \. @ / . test ( pkg ) ) )
81
+ return this . listWorkspaces ( filters )
82
+
83
+ // pkg is unset
84
+ // cmdName is one of:
85
+ // - unset
86
+ // - .
87
+ // - .@version
88
+ if ( ! pkg && ( ! cmdName || cmdName === '.' || / ^ \. @ / . test ( cmdName ) ) )
89
+ return this . listWorkspaces ( filters )
90
+
91
+ // anything else is just a regular dist-tag command
92
+ // so we fallback to the non-workspaces implementation
93
+ log . warn ( 'Ignoring workspaces for specified package' )
94
+ return this . distTag ( [ cmdName , pkg , tag ] )
95
+ }
96
+
65
97
async add ( spec , tag , opts ) {
66
98
spec = npa ( spec || '' )
67
99
const version = spec . rawSpec
@@ -145,6 +177,22 @@ class DistTag extends BaseCommand {
145
177
}
146
178
}
147
179
180
+ async listWorkspaces ( filters ) {
181
+ const workspaces =
182
+ await getWorkspaces ( filters , { path : this . npm . localPrefix } )
183
+
184
+ for ( const [ name ] of workspaces ) {
185
+ try {
186
+ this . npm . output ( `${ name } :` )
187
+ await this . list ( npa ( name ) , this . npm . flatOptions )
188
+ } catch ( err ) {
189
+ // set the exitCode directly, but ignore the error
190
+ // since it will have already been logged by this.list()
191
+ process . exitCode = 1
192
+ }
193
+ }
194
+ }
195
+
148
196
async fetchTags ( spec , opts ) {
149
197
const data = await regFetch . json (
150
198
`/-/package/${ spec . escapedName } /dist-tags` ,
0 commit comments