@@ -11,6 +11,7 @@ const npmFetch = require('npm-registry-fetch')
11
11
const flatten = require ( './utils/config/flatten.js' )
12
12
const otplease = require ( './utils/otplease.js' )
13
13
const { getContents, logTar } = require ( './utils/tar.js' )
14
+ const getWorkspaces = require ( './workspaces/get-workspaces.js' )
14
15
15
16
// this is the only case in the CLI where we use the old full slow
16
17
// 'read-package-json' module, because we want to pull in all the
@@ -44,6 +45,10 @@ class Publish extends BaseCommand {
44
45
this . publish ( args ) . then ( ( ) => cb ( ) ) . catch ( cb )
45
46
}
46
47
48
+ execWorkspaces ( args , filters , cb ) {
49
+ this . publishWorkspaces ( args , filters ) . then ( ( ) => cb ( ) ) . catch ( cb )
50
+ }
51
+
47
52
async publish ( args ) {
48
53
if ( args . length === 0 )
49
54
args = [ '.' ]
@@ -56,6 +61,7 @@ class Publish extends BaseCommand {
56
61
const dryRun = this . npm . config . get ( 'dry-run' )
57
62
const json = this . npm . config . get ( 'json' )
58
63
const defaultTag = this . npm . config . get ( 'tag' )
64
+ const silent = log . level === 'silent'
59
65
60
66
if ( semver . validRange ( defaultTag ) )
61
67
throw new Error ( 'Tag name must not be a valid SemVer range: ' + defaultTag . trim ( ) )
@@ -77,7 +83,7 @@ class Publish extends BaseCommand {
77
83
path : spec . fetchSpec ,
78
84
stdio : 'inherit' ,
79
85
pkg : manifest ,
80
- banner : log . level !== ' silent' ,
86
+ banner : ! silent ,
81
87
} )
82
88
}
83
89
@@ -114,27 +120,51 @@ class Publish extends BaseCommand {
114
120
path : spec . fetchSpec ,
115
121
stdio : 'inherit' ,
116
122
pkg : manifest ,
117
- banner : log . level !== ' silent' ,
123
+ banner : ! silent ,
118
124
} )
119
125
120
126
await runScript ( {
121
127
event : 'postpublish' ,
122
128
path : spec . fetchSpec ,
123
129
stdio : 'inherit' ,
124
130
pkg : manifest ,
125
- banner : log . level !== ' silent' ,
131
+ banner : ! silent ,
126
132
} )
127
133
}
128
134
129
- const silent = log . level === 'silent'
130
- if ( ! silent && json )
131
- this . npm . output ( JSON . stringify ( pkgContents , null , 2 ) )
132
- else if ( ! silent )
133
- this . npm . output ( `+ ${ pkgContents . id } ` )
135
+ if ( ! this . workspaces ) {
136
+ if ( ! silent && json )
137
+ this . npm . output ( JSON . stringify ( pkgContents , null , 2 ) )
138
+ else if ( ! silent )
139
+ this . npm . output ( `+ ${ pkgContents . id } ` )
140
+ }
134
141
135
142
return pkgContents
136
143
}
137
144
145
+ async publishWorkspaces ( args , filters ) {
146
+ // Suppresses JSON output in publish() so we can handle it here
147
+ this . workspaces = true
148
+
149
+ const results = { }
150
+ const json = this . npm . config . get ( 'json' )
151
+ const silent = log . level === 'silent'
152
+ const workspaces =
153
+ await getWorkspaces ( filters , { path : this . npm . localPrefix } )
154
+ for ( const [ name , workspace ] of workspaces . entries ( ) ) {
155
+ const pkgContents = await this . publish ( [ workspace ] )
156
+ // This needs to be in-line w/ the rest of the output that non-JSON
157
+ // publish generates
158
+ if ( ! silent && ! json )
159
+ this . npm . output ( `+ ${ pkgContents . id } ` )
160
+ else
161
+ results [ name ] = pkgContents
162
+ }
163
+
164
+ if ( ! silent && json )
165
+ this . npm . output ( JSON . stringify ( results , null , 2 ) )
166
+ }
167
+
138
168
// if it's a directory, read it from the file system
139
169
// otherwise, get the full metadata from whatever it is
140
170
getManifest ( spec , opts ) {
0 commit comments