Skip to content

Commit 1a7907f

Browse files
committed
Fixed mapping of PS output to right Promise
1 parent 5b2f6ae commit 1a7907f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

packages/react-dev-utils/errorOverlayMiddleware.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
*/
99
'use strict';
1010

11-
const { launchEditor } = require('./launchEditor');
11+
const { launchEditor, tryLaunchPowerShellAgent } = require('./launchEditor');
1212
const launchEditorEndpoint = require('./launchEditorEndpoint');
1313

1414
module.exports = function createLaunchEditorMiddleware() {
1515
if (process.platform === 'win32' && !process.env.REACT_EDITOR) {
16-
const {
17-
tryLaunchPowerShellAgent,
18-
} = require('react-dev-utils/launchEditor');
1916
tryLaunchPowerShellAgent();
2017
}
2118

packages/react-dev-utils/launchEditor.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ class PowerShell extends EventEmitter {
3838
throw new Error('Failed to start PowerShell');
3939
}
4040

41+
// Initialize counters for mapping events
42+
this._callbackCounter = 0;
43+
this._resolveCounter = 0;
44+
4145
let output = [];
4246
this._proc.stdout.on('data', data => {
4347
if (data.indexOf(EOI) !== -1) {
44-
this.emit('resolve', output.join(''));
48+
const eventName = 'resolve' + ++this._callbackCounter;
49+
this.emit(eventName, output.join(''));
4550
output = [];
4651
} else {
4752
output.push(data);
@@ -51,10 +56,8 @@ class PowerShell extends EventEmitter {
5156

5257
invoke(cmd) {
5358
return new Promise(resolve => {
54-
this.on('resolve', data => {
55-
resolve(data);
56-
this.removeAllListeners('resolve');
57-
});
59+
const eventName = 'resolve' + ++this._resolveCounter;
60+
this.once(eventName, resolve);
5861

5962
this._proc.stdin.write(cmd);
6063
this._proc.stdin.write(os.EOL);

0 commit comments

Comments
 (0)