diff --git a/src/environment-base.ts b/src/environment-base.ts index f92f9d22..4466afdc 100644 --- a/src/environment-base.ts +++ b/src/environment-base.ts @@ -422,10 +422,12 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron ): Promise; async composeWith(generator: string | GetGeneratorConstructor, ...args: any[]): Promise { const options = getComposeOptions(...args) as ComposeOptions; - const { schedule = true, ...instantiateOptions } = options; + const { schedule: passedSchedule = true, ...instantiateOptions } = options; const generatorInstance = await this.create(generator, instantiateOptions); - return this.queueGenerator(generatorInstance, { schedule }); + // Convert to function to keep type compatibility with old @yeoman/types where schedule is boolean only + const schedule: (gen: G) => boolean = typeof passedSchedule === 'function' ? passedSchedule : () => passedSchedule; + return this.queueGenerator(generatorInstance, { schedule: schedule(generatorInstance) }); } /** diff --git a/test/environment.js b/test/environment.js index a1bafc14..e7778214 100644 --- a/test/environment.js +++ b/test/environment.js @@ -272,6 +272,18 @@ for (const generatorVersion of allVersions) { } }); }); + describe('passing function schedule parameter', () => { + it('returning false should not schedule generator', async function () { + this.env.queueTask = sinon.spy(); + await this.env.composeWith('stub', { generatorArgs: [], schedule: () => false }); + if (isGreaterThan6(generatorVersion)) { + assert(this.env.queueTask.calledOnce); + assert(this.env.queueTask.getCall(0).firstArg !== 'environment:run'); + } else { + assert(this.env.queueTask.notCalled); + } + }); + }); it('should emit a compose event', function (done) { this.env.once('compose', (namespace, generator) => {