Skip to content

Commit

Permalink
spawn fewer locomotives in projects with many roots
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartine-ias committed May 7, 2024
1 parent 37737fc commit f4a2c13
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/jest-changed-files/src/sl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import type {SCMAdapter} from './types';
*/
const env = {...process.env, HGPLAIN: '1'};

// Whether `sl` is a steam locomotive or not
let isSteamLocomotive = false;

const adapter: SCMAdapter = {
findChangedFiles: async (cwd, options) => {
const includePaths = options.includePaths ?? [];
Expand Down Expand Up @@ -55,6 +58,10 @@ const adapter: SCMAdapter = {
},

getRoot: async cwd => {
if (isSteamLocomotive) {
return null;
}

try {
const subprocess = execa('sl', ['root'], {cwd, env});

Expand All @@ -65,6 +72,7 @@ const adapter: SCMAdapter = {
data = Buffer.isBuffer(data) ? data.toString() : data;
if (data.codePointAt(0) === 27) {
subprocess.cancel();
isSteamLocomotive = true;
}
});
}
Expand Down

0 comments on commit f4a2c13

Please sign in to comment.