linnovate/mean-cli

Don't assume shell.exec() is synchronous

vthunder opened this issue · 2 comments

While investigating #94 I noticed that in some places there is an assumption that shell.exec() is synchronous. In fact, it is not when a callback is provided:

https://github.com/arturadib/shelljs#execcommand--options--callback

In this case, for example, init() will return immediately since shell.exec() is the last statement in the function. It's not clear whether init() is expected to fully complete its work before returning:

https://github.com/linnovate/mean-cli/blob/master/lib/cli.js#L896

I've no evidence this is a problem right now, but if the caller does expect init to be finished upon returning, then script could conceivably exit before the callback has a chance to run. Either init() should explicitly return a promise, take a callback, or ensure it completes its work before returning.

In this case, assuming we want the latter, simply adding {async:false} should do the trick.

Great piece of information here, 👍 !

#94 is closed. thanks for the info here.