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

Abort sl root call if output resembles a steam locomotive #15053

Merged
merged 5 commits into from
May 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/jest-changed-files/src/sl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,28 @@

getRoot: async cwd => {
try {
const result = await execa('sl', ['root'], {cwd, env});
const subprocess = execa('sl', ['root'], {cwd, env});
if (subprocess.stdout == null) {
return null;
}

// Check if we're calling sl (steam locomotive) instead of sl (sapling)
// by looking for the escape character in the first chunk of data.
let firstChunk = true;
subprocess.stdout.on('data', data => {
if (!firstChunk) {
return;
}
if (data.toString().codePointAt(0) === 27) {

Check failure on line 71 in packages/jest-changed-files/src/sl.ts

View workflow job for this annotation

GitHub Actions / TypeScript Compatibility

Unsafe call of an `any` typed value

Check failure on line 71 in packages/jest-changed-files/src/sl.ts

View workflow job for this annotation

GitHub Actions / TypeScript Compatibility

Unsafe call of an `any` typed value

Check failure on line 71 in packages/jest-changed-files/src/sl.ts

View workflow job for this annotation

GitHub Actions / TypeScript Compatibility

Unsafe member access .toString on an `any` value

Check failure on line 71 in packages/jest-changed-files/src/sl.ts

View workflow job for this annotation

GitHub Actions / TypeScript Compatibility

Unsafe member access .codePointAt on an `any` value
subprocess.cancel();
}
firstChunk = false;
});

const result = await subprocess;
if (result.killed) {
return null;
}

return result.stdout;
} catch {
Expand Down
Loading