New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rush] Update the functionality that runs external lifecycle processes to be async. #4350
base: main
Are you sure you want to change the base?
Conversation
result = child_process.spawnSync(command + '.cmd', args, options); | ||
const stdoutBuffers: string[] = []; | ||
process.stdout?.on('data', (chunk) => { | ||
stdoutBuffers.push(chunk.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we care about encoding here?
|
||
const stderrBuffers: string[] = []; | ||
process.stderr?.on('data', (chunk) => { | ||
stderrBuffers.push(chunk.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or here?
|
||
let error: Error | undefined; | ||
try { | ||
await once(process, 'close'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was some outcome that we came to with which event we should wait on before exiting. Is this the one we settled on?
(result.stderr ? result.stderr.toString() : '') | ||
); | ||
if (status) { | ||
throw new Error(`The command failed with exit code ${status}\n${stderr}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did non-zero exit codes always throw spawnSync
? I know some tools intentionally return non-zero exit codes. Whatever we do here should be compatible with what spawnSync
does.
e853889
to
a16f097
Compare
if (!this._targetBranchName) { | ||
this._targetBranchName = this._targetBranchParameter.value || this._git.getRemoteDefaultBranch(); | ||
this._targetBranchName = | ||
this._targetBranchParameter.value || (await this._git.getRemoteDefaultBranch()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Label this as an async method
@@ -10,8 +10,8 @@ describe('CLI', () => { | |||
const workingDir: string = '/'; | |||
const startPath: string = path.resolve(__dirname, '../../../lib-commonjs/start.js'); | |||
|
|||
expect(() => { | |||
Utilities.executeCommand({ | |||
expect(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have to await these expects?
(result.stderr ? result.stderr.toString() : '') | ||
); | ||
const stderr: string = stderrBuffers.join(''); | ||
const stdout: string = stdoutBuffers.join(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like a lot of this should exist under the Executable class... but it may not? (On mobile)
a16f097
to
0062d82
Compare
0062d82
to
ebe2934
Compare
Summary
This PR refactors the
executeCommand
and related functions to be async. This is in preparation for some follow-up work to mergeexecuteCommandAndProcessOutputWithRetryAsync
into theexecuteCommandAsync
function.How it was tested
This change needs some more testing.