File tree 2 files changed +16
-2
lines changed
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -422,10 +422,12 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
422
422
) : Promise < G > ;
423
423
async composeWith < G extends BaseGenerator = BaseGenerator > ( generator : string | GetGeneratorConstructor < G > , ...args : any [ ] ) : Promise < G > {
424
424
const options = getComposeOptions ( ...args ) as ComposeOptions < G > ;
425
- const { schedule = true , ...instantiateOptions } = options ;
425
+ const { schedule : passedSchedule = true , ...instantiateOptions } = options ;
426
426
427
427
const generatorInstance = await this . create ( generator , instantiateOptions ) ;
428
- return this . queueGenerator ( generatorInstance , { schedule } ) ;
428
+ // Convert to function to keep type compatibility with old @yeoman /types where schedule is boolean only
429
+ const schedule : ( gen : G ) => boolean = typeof passedSchedule === 'function' ? passedSchedule : ( ) => passedSchedule ;
430
+ return this . queueGenerator ( generatorInstance , { schedule : schedule ( generatorInstance ) } ) ;
429
431
}
430
432
431
433
/**
Original file line number Diff line number Diff line change @@ -272,6 +272,18 @@ for (const generatorVersion of allVersions) {
272
272
}
273
273
} ) ;
274
274
} ) ;
275
+ describe ( 'passing function schedule parameter' , ( ) => {
276
+ it ( 'returning false should not schedule generator' , async function ( ) {
277
+ this . env . queueTask = sinon . spy ( ) ;
278
+ await this . env . composeWith ( 'stub' , { generatorArgs : [ ] , schedule : ( ) => false } ) ;
279
+ if ( isGreaterThan6 ( generatorVersion ) ) {
280
+ assert ( this . env . queueTask . calledOnce ) ;
281
+ assert ( this . env . queueTask . getCall ( 0 ) . firstArg !== 'environment:run' ) ;
282
+ } else {
283
+ assert ( this . env . queueTask . notCalled ) ;
284
+ }
285
+ } ) ;
286
+ } ) ;
275
287
276
288
it ( 'should emit a compose event' , function ( done ) {
277
289
this . env . once ( 'compose' , ( namespace , generator ) => {
You can’t perform that action at this time.
0 commit comments