Skip to content

Commit

Permalink
Add immediately parameter to composeWith
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Jul 5, 2021
1 parent b8747da commit 8fd5c86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <caption>Using a peerDependency generator</caption>
Expand All @@ -1175,7 +1177,7 @@ class Generator extends Base {
* @example <caption>Passing a Generator class</caption>
* 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') {
Expand Down Expand Up @@ -1263,7 +1265,7 @@ this.composeWith({
return instantiatedGenerator;
}

if (this._running) {
if (this._running || immediately) {
this.env.queueGenerator(instantiatedGenerator);
} else {
this._composedWith.push(instantiatedGenerator);
Expand Down
17 changes: 13 additions & 4 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8fd5c86

Please sign in to comment.