@@ -109,7 +109,8 @@ class PublishCommand extends Command {
109109
110110 chain = chain . then ( ( ) => this . resolveLocalDependencyLinks ( ) ) ;
111111 chain = chain . then ( ( ) => this . annotateGitHead ( ) ) ;
112- chain = chain . then ( ( ) => this . npmPublish ( ) ) ;
112+ chain = chain . then ( ( ) => this . packUpdated ( ) ) ;
113+ chain = chain . then ( ( ) => this . publishPacked ( ) ) ;
113114 chain = chain . then ( ( ) => this . resetChanges ( ) ) ;
114115
115116 if ( this . options . tempTag ) {
@@ -338,49 +339,70 @@ class PublishCommand extends Command {
338339 } ) ;
339340 }
340341
341- npmPublish ( ) {
342- const tracker = this . logger . newItem ( "npmPublish" ) ;
343- // if we skip temp tags we should tag with the proper value immediately
344- const distTag = this . options . tempTag ? "lerna-temp" : this . getDistTag ( ) ;
342+ packUpdated ( ) {
343+ const tracker = this . logger . newItem ( "npm pack" ) ;
344+
345+ tracker . addWork (
346+ this . options . requireScripts
347+ ? // track completion of prepublish.js on updates as well
348+ this . packagesToPublish . length + this . updates . length
349+ : this . packagesToPublish . length
350+ ) ;
345351
346352 let chain = Promise . resolve ( ) ;
347353
348354 chain = chain . then ( ( ) => createTempLicenses ( this . project . licensePath , this . packagesToBeLicensed ) ) ;
349-
350355 chain = chain . then ( ( ) => this . runPrepublishScripts ( this . project . manifest ) ) ;
351- chain = chain . then ( ( ) =>
352- pMap ( this . updates , ( { pkg } ) => {
353- if ( this . options . requireScripts ) {
356+
357+ if ( this . options . requireScripts ) {
358+ chain = chain . then ( ( ) =>
359+ pMap ( this . updates , ( { pkg } ) => {
354360 this . execScript ( pkg , "prepublish" ) ;
355- }
361+ tracker . completeWork ( 1 ) ;
362+ } )
363+ ) ;
364+ }
356365
357- return this . runPrepublishScripts ( pkg ) ;
358- } )
366+ chain = chain . then ( ( ) =>
367+ runParallelBatches ( this . batchedPackages , this . concurrency , pkg =>
368+ npmPublish . npmPack ( pkg ) . then ( ( ) => {
369+ tracker . completeWork ( 1 ) ;
370+ } )
371+ )
359372 ) ;
360373
374+ chain = chain . then ( ( ) => removeTempLicenses ( this . packagesToBeLicensed ) ) ;
375+
376+ // remove temporary license files if _any_ error occurs _anywhere_ in the promise chain
377+ chain = chain . catch ( error => this . removeTempLicensesOnError ( error ) ) ;
378+
379+ return pFinally ( chain , ( ) => tracker . finish ( ) ) ;
380+ }
381+
382+ publishPacked ( ) {
383+ // if we skip temp tags we should tag with the proper value immediately
384+ const distTag = this . options . tempTag ? "lerna-temp" : this . getDistTag ( ) ;
385+ const tracker = this . logger . newItem ( `${ this . npmConfig . npmClient } publish` ) ;
386+
361387 tracker . addWork ( this . packagesToPublish . length ) ;
362388
363- const mapPackage = pkg => {
364- tracker . verbose ( "publishing" , pkg . name ) ;
389+ let chain = Promise . resolve ( ) ;
365390
366- return npmPublish ( pkg , distTag , this . npmConfig ) . then ( ( ) => {
367- tracker . info ( "published" , pkg . name ) ;
368- tracker . completeWork ( 1 ) ;
391+ chain = chain . then ( ( ) =>
392+ runParallelBatches ( this . batchedPackages , this . concurrency , pkg =>
393+ npmPublish ( pkg , distTag , this . npmConfig ) . then ( ( ) => {
394+ tracker . info ( "published" , pkg . name ) ;
369395
370- if ( this . options . requireScripts ) {
371- this . execScript ( pkg , "postpublish" ) ;
372- }
396+ if ( this . options . requireScripts ) {
397+ this . execScript ( pkg , "postpublish" ) ;
398+ }
373399
374- return this . runPackageLifecycle ( pkg , "postpublish" ) ;
375- } ) ;
376- } ;
400+ tracker . completeWork ( 1 ) ;
401+ } )
402+ )
403+ ) ;
377404
378- chain = chain . then ( ( ) => runParallelBatches ( this . batchedPackages , this . concurrency , mapPackage ) ) ;
379405 chain = chain . then ( ( ) => this . runPackageLifecycle ( this . project . manifest , "postpublish" ) ) ;
380- chain = chain . then ( ( ) => removeTempLicenses ( this . packagesToBeLicensed ) ) ;
381-
382- // remove temporary license files if _any_ error occurs _anywhere_ in the promise chain
383- chain = chain . catch ( error => this . removeTempLicensesOnError ( error ) ) ;
384406
385407 return pFinally ( chain , ( ) => tracker . finish ( ) ) ;
386408 }
0 commit comments