Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

iclanton
Copy link
Member

Summary

This PR refactors the executeCommand and related functions to be async. This is in preparation for some follow-up work to merge executeCommandAndProcessOutputWithRetryAsync into the executeCommandAsync function.

How it was tested

This change needs some more testing.

result = child_process.spawnSync(command + '.cmd', args, options);
const stdoutBuffers: string[] = [];
process.stdout?.on('data', (chunk) => {
stdoutBuffers.push(chunk.toString());
Copy link
Member

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());
Copy link
Member

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');
Copy link
Member

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}`);
Copy link
Member

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.

@iclanton iclanton force-pushed the refactor-executeCommand branch 2 times, most recently from e853889 to a16f097 Compare March 30, 2024 02:29
if (!this._targetBranchName) {
this._targetBranchName = this._targetBranchParameter.value || this._git.getRemoteDefaultBranch();
this._targetBranchName =
this._targetBranchParameter.value || (await this._git.getRemoteDefaultBranch());
Copy link
Member

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 () => {
Copy link
Member

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('');
Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

None yet

2 participants