diff --git a/lib/environment.js b/lib/environment.js index 9b7722c0..5011ebb6 100644 --- a/lib/environment.js +++ b/lib/environment.js @@ -164,7 +164,7 @@ class Environment extends Base { rootCommand.emit('yeoman:environment', command.env); const generator = command.env.instantiate(GeneratorClass, this.args, this.opts()); - command.env.queueGenerator(generator); + await command.env.queueGenerator(generator); return command.env.start().then(() => command.env); }); return command; @@ -922,29 +922,26 @@ class Environment extends Base { // Generator > 5 this.once('run', () => generator.emit('run')); this.once('end', () => generator.emit('end')); - generator.queueTasks(); - } else { - if (!generator.options.forwardErrorToEnvironment) { - generator.on('error', error => this.emit('error', error)); - } - generator.promise = generator.run(); + return generator.queueTasks(); + } + if (!generator.options.forwardErrorToEnvironment) { + generator.on('error', error => this.emit('error', error)); } + generator.promise = generator.run(); }; if (schedule) { this.runLoop.add( 'environment:run', - (done, stop) => { - try { - runGenerator(); - done(); - } catch (error) { - stop(error); - } + async () => { + await runGenerator(); } ); } else { - runGenerator(); + const maybePromise = runGenerator(); + if (maybePromise && maybePromise.then) { + return maybePromise.then(() => generator); + } } return generator; } @@ -1065,7 +1062,7 @@ class Environment extends Base { async runGenerator(generator) { try { generator = await generator; - generator = this.queueGenerator(generator); + generator = await this.queueGenerator(generator); } catch (error) { return Promise.reject(error); }