raphinesse commented on a change in pull request #763: refactor: replace
superspawn & child_process with execa
URL: https://github.com/apache/cordova-ios/pull/763#discussion_r364486538
##########
File path: bin/templates/scripts/cordova/lib/run.js
##########
@@ -199,21 +200,30 @@ function startSim (appPath, target) {
}
function iossimLaunch (appPath, devicetypeid, log, exit) {
- const f = path.resolve(path.dirname(require.resolve('ios-sim')), 'bin',
'ios-sim');
- const params = ['launch', appPath, '--devicetypeid', devicetypeid,
'--log', log, exit];
+ const subprocess = execa(
+ require.resolve('ios-sim/bin/ios-sim'),
+ ['launch', appPath, '--devicetypeid', devicetypeid, '--log', log,
exit],
+ { cwd: projectPath }
+ );
- return superspawn.spawn(f, params, { cwd: projectPath, printCommand: true
})
- .progress(stdio => {
- if (stdio.stderr) {
- events.emit('error', `[ios-sim] ${stdio.stderr}`);
- }
- if (stdio.stdout) {
- events.emit('log', `[ios-sim] ${stdio.stdout.trim()}`);
- }
- })
- .then(result => {
- events.emit('log', 'Simulator successfully started via
`ios-sim`.');
- });
+ const transformOutput = (channel, line) => {
+ events.emit(channel, `[ios-sim] ${line}`);
+ };
+
+ subprocess.stdout
+ .pipe(split2())
+ .on('data', transformOutput.bind(this, 'log'));
+
+ subprocess.stderr
+ .pipe(split2())
+ .on('data', transformOutput.bind(this, 'error'));
+
+ return (async () => {
+ const { stderr } = await subprocess;
+ const hasError = !!stderr;
+
+ events.emit('log', `Simulator ${hasError ? 'had an error while
starting' : 'successfully started'} via "ios-sim".`);
+ })();
Review comment:
Why not leave it at the equivalent of before?
```js
subprocess.then(() => {
events.emit('log', 'Simulator successfully started via
`ios-sim`.');
});
```
Can we really be sure we encountered an error when `stderr` is non-empty?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]