1
1
"use strict" ;
2
2
3
+ const pMap = require ( "p-map" ) ;
4
+
3
5
const ChildProcessUtilities = require ( "@lerna/child-process" ) ;
4
6
const Command = require ( "@lerna/command" ) ;
5
- const batchPackages = require ( "@lerna/batch-packages" ) ;
6
- const runParallelBatches = require ( "@lerna/run-parallel-batches" ) ;
7
+ const runTopologically = require ( "@lerna/run-topologically" ) ;
7
8
const ValidationError = require ( "@lerna/validation-error" ) ;
8
9
const { getFilteredPackages } = require ( "@lerna/filter-options" ) ;
9
10
@@ -47,10 +48,6 @@ class ExecCommand extends Command {
47
48
this . count = this . filteredPackages . length ;
48
49
this . packagePlural = this . count === 1 ? "package" : "packages" ;
49
50
this . joinedCommand = [ this . command ] . concat ( this . args ) . join ( " " ) ;
50
-
51
- this . batchedPackages = this . toposort
52
- ? batchPackages ( this . filteredPackages , this . options . rejectCycles )
53
- : [ this . filteredPackages ] ;
54
51
} ) ;
55
52
}
56
53
@@ -67,8 +64,10 @@ class ExecCommand extends Command {
67
64
68
65
if ( this . options . parallel ) {
69
66
chain = chain . then ( ( ) => this . runCommandInPackagesParallel ( ) ) ;
67
+ } else if ( this . toposort ) {
68
+ chain = chain . then ( ( ) => this . runCommandInPackagesTopological ( ) ) ;
70
69
} else {
71
- chain = chain . then ( ( ) => this . runCommandInPackagesBatched ( ) ) ;
70
+ chain = chain . then ( ( ) => this . runCommandInPackagesLexical ( ) ) ;
72
71
}
73
72
74
73
if ( this . bail ) {
@@ -120,18 +119,29 @@ class ExecCommand extends Command {
120
119
} ;
121
120
}
122
121
123
- runCommandInPackagesBatched ( ) {
122
+ runCommandInPackagesTopological ( ) {
124
123
const runner = this . options . stream
125
124
? pkg => this . runCommandInPackageStreaming ( pkg )
126
125
: pkg => this . runCommandInPackageCapturing ( pkg ) ;
127
126
128
- return runParallelBatches ( this . batchedPackages , this . concurrency , runner ) . then ( batchedResults =>
129
- batchedResults . reduce ( ( arr , batch ) => arr . concat ( batch ) , [ ] )
130
- ) ;
127
+ return runTopologically ( {
128
+ packages : this . filteredPackages ,
129
+ concurrency : this . concurrency ,
130
+ rejectCycles : this . options . rejectCycles ,
131
+ runner,
132
+ } ) ;
131
133
}
132
134
133
135
runCommandInPackagesParallel ( ) {
134
- return Promise . all ( this . filteredPackages . map ( pkg => this . runCommandInPackageStreaming ( pkg ) ) ) ;
136
+ return pMap ( this . filteredPackages , pkg => this . runCommandInPackageStreaming ( pkg ) ) ;
137
+ }
138
+
139
+ runCommandInPackagesLexical ( ) {
140
+ const runner = this . options . stream
141
+ ? pkg => this . runCommandInPackageStreaming ( pkg )
142
+ : pkg => this . runCommandInPackageCapturing ( pkg ) ;
143
+
144
+ return pMap ( this . filteredPackages , runner , { concurrency : this . concurrency } ) ;
135
145
}
136
146
137
147
runCommandInPackageStreaming ( pkg ) {
0 commit comments