0

I've been using async/await code inside a generator that I've been creating and have not faced any issue

async prompting() {
  await someFunction()
}

But when i try to use this same pattern on runInstall, yarnInstall or npmInstall it seems to fail.

async install() {
  this.log('in');
  await this.runInstall('npm', 'mocha', {verbose: true});
  this.log('yahooooooooo');
}

The code exits after it reaches the await command. I checked the code and it is returning a promise (yarnInstall and npmInstall internally uses runInstall) so no problem there.

I know i can work around this by using spawnCommandSync, but that is not the aim of this question.

I want to understand why it is not working or what am i doing wrong? My guess is that it has something to do with shell like shell is trying to access another shell (not exactly this, but something along the lines).

a1626
  • 2,953
  • 1
  • 19
  • 34
  • What is `runInstall` does it return a promise.? – Keith Feb 27 '18 at 13:15
  • @Keith [runInstall](http://yeoman.io/generator/actions_install.html#.runInstall) is a `yeoman` API. It executes package manager's (like `npm`) install commands on shell. Yes, it does return promise. – a1626 Feb 27 '18 at 13:19
  • "*The code exits after it reaches the await command.*" - what do you mean by "exits"? Does it immediately log `yahoo`? If not, does it throw an error maybe? – Bergi Feb 27 '18 at 13:35
  • @Bergi, no CLI returns the control back to the user after logging `in`. No error or any other message. – a1626 Feb 27 '18 at 13:50
  • OK, it might not log an error, but that doesn't necessarily mean that none happened :-) Did you try explicitly catching and logging? – Bergi Feb 27 '18 at 13:54
  • Where/how do you call `install`? And does the npm command actually run (quietly, obviously) or does it not do anything? – Bergi Feb 27 '18 at 13:56
  • @Bergi `runInstall` internally calls `spawnCommand` which has the job of calling `npm install`. The install command will run just like how you run it from CLI directly, printing all the logs and in my case after it is finished yeoman will return control of CLI back to the user. – a1626 Feb 27 '18 at 13:58

0 Answers0