diff --git a/lib/index.js b/lib/index.js index 42b5f71e..a65e89e7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1163,7 +1163,9 @@ class Generator extends Base { /** * Compose this generator with another one. * @param {String|Object|Array} generator The path to the generator module or an object (see examples) + * @param {Array} [args] Arguments passed to the Generator * @param {Object} [options] The options passed to the Generator + * @param {boolean} [immediately] Boolean whether to queue the Generator immediately * @return {Generator} The composed generator * * @example Using a peerDependency generator @@ -1175,7 +1177,7 @@ class Generator extends Base { * @example Passing a Generator class * this.composeWith({ Generator: MyGenerator, path: '../generator-bootstrap/app/main.js' }, { sass: true }); */ - composeWith(generator, args, options) { + composeWith(generator, args, options, immediately = false) { if (typeof args === 'boolean') { args = []; } else if (!Array.isArray(args) && typeof args === 'object') { @@ -1263,7 +1265,7 @@ this.composeWith({ return instantiatedGenerator; } - if (this._running) { + if (this._running || immediately) { this.env.queueGenerator(instantiatedGenerator); } else { this._composedWith.push(instantiatedGenerator); diff --git a/test/base.js b/test/base.js index 4f8b8d75..0aade76c 100644 --- a/test/base.js +++ b/test/base.js @@ -886,10 +886,19 @@ describe('Base', () => { this.env.registerStub(this.GenCompose, 'composed:gen'); }); - it('returns the composed generator when pass true', function () { - assert( - this.dummy.composeWith('composed:gen', true) instanceof this.GenCompose - ); + it('returns the composed generator', function () { + assert(this.dummy.composeWith('composed:gen') instanceof this.GenCompose); + }); + + it('should add to _composedWith', function () { + const generator = this.dummy.composeWith('composed:gen'); + assert(generator instanceof this.GenCompose); + assert(generator === this.dummy._composedWith[0]); + }); + + it('should not add to _composedWith when immediately is true', function () { + this.dummy.composeWith('composed:gen', undefined, undefined, true); + assert.strictEqual(this.dummy._composedWith.length, 0); }); it('runs the composed generators', function (done) {