Skip to content

Commit

Permalink
Fixed mapping of PS output to right Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
levrik committed Sep 7, 2017
1 parent 5b2f6ae commit 1a7907f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
5 changes: 1 addition & 4 deletions packages/react-dev-utils/errorOverlayMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
*/
'use strict';

const { launchEditor } = require('./launchEditor');
const { launchEditor, tryLaunchPowerShellAgent } = require('./launchEditor');
const launchEditorEndpoint = require('./launchEditorEndpoint');

module.exports = function createLaunchEditorMiddleware() {
if (process.platform === 'win32' && !process.env.REACT_EDITOR) {
const {
tryLaunchPowerShellAgent,
} = require('react-dev-utils/launchEditor');
tryLaunchPowerShellAgent();
}

Expand Down
13 changes: 8 additions & 5 deletions packages/react-dev-utils/launchEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ class PowerShell extends EventEmitter {
throw new Error('Failed to start PowerShell');
}

// Initialize counters for mapping events
this._callbackCounter = 0;
this._resolveCounter = 0;

let output = [];
this._proc.stdout.on('data', data => {
if (data.indexOf(EOI) !== -1) {
this.emit('resolve', output.join(''));
const eventName = 'resolve' + ++this._callbackCounter;
this.emit(eventName, output.join(''));
output = [];
} else {
output.push(data);
Expand All @@ -51,10 +56,8 @@ class PowerShell extends EventEmitter {

invoke(cmd) {
return new Promise(resolve => {
this.on('resolve', data => {
resolve(data);
this.removeAllListeners('resolve');
});
const eventName = 'resolve' + ++this._resolveCounter;
this.once(eventName, resolve);

this._proc.stdin.write(cmd);
this._proc.stdin.write(os.EOL);
Expand Down

0 comments on commit 1a7907f

Please sign in to comment.