Skip to content

Commit

Permalink
feat(turbo-ignore) add a --max-buffer option for dry runs that have l…
Browse files Browse the repository at this point in the history
…arge outputs (#6052)

Closes TURBO-1371

---------

Co-authored-by: Chris Olszewski <chris.olszewski@vercel.com>
  • Loading branch information
mehulkar and chris-olszewski committed Sep 28, 2023
1 parent 60636fb commit 3cad01a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 40 deletions.
6 changes: 6 additions & 0 deletions packages/turbo-ignore/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ turboIgnoreCli
"The directory to run in (default: cwd)"
)
)
.addOption(
new Option(
"-b, --max-buffer <number>",
"maxBuffer for the child process in KB (default: 1024 KB)"
).argParser((val) => parseInt(val, 10) * 1024)
)
.version(cliPkg.version, "-v, --version", "Output the current version")
.helpOption("-h, --help", "Display help for command")
.showHelpAfterError(false)
Expand Down
83 changes: 43 additions & 40 deletions packages/turbo-ignore/src/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,50 +95,53 @@ export function turboIgnore(
// Build, and execute the command
const command = `npx turbo run ${task} --filter=${workspace}...[${comparison.ref}] --dry=json`;
info(`Analyzing results of \`${command}\``);
exec(
command,
{
cwd: root,
},
(err, stdout) => {
if (err) {
const { level, code, message } = shouldWarn({ err: err.message });
if (level === "warn") {
warn(message);
} else {
error(`${code}: ${err.message}`);
}
return continueBuild();

const execOptions: { cwd: string; maxBuffer?: number } = {
cwd: root,
};

if (opts.maxBuffer) {
execOptions.maxBuffer = opts.maxBuffer;
}

exec(command, execOptions, (err, stdout) => {
if (err) {
const { level, code, message } = shouldWarn({ err: err.message });
if (level === "warn") {
warn(message);
} else {
error(`${code}: ${err.message}`);
}
return continueBuild();
}

try {
const parsed = JSON.parse(stdout) as DryRun | null;
if (parsed === null) {
error(`Failed to parse JSON output from \`${command}\`.`);
return continueBuild();
}
const { packages } = parsed;
if (packages.length > 0) {
if (packages.length === 1) {
info(`This commit affects "${workspace}"`);
} else {
// subtract 1 because the first package is the workspace itself
info(
`This commit affects "${workspace}" and ${packages.length - 1} ${
packages.length - 1 === 1 ? "dependency" : "dependencies"
} (${packages.slice(1).join(", ")})`
);
}

return continueBuild();
}
info(`This project and its dependencies are not affected`);
return ignoreBuild();
} catch (e) {
try {
const parsed = JSON.parse(stdout) as DryRun | null;
if (parsed === null) {
error(`Failed to parse JSON output from \`${command}\`.`);
error(e);
return continueBuild();
}
const { packages } = parsed;
if (packages.length > 0) {
if (packages.length === 1) {
info(`This commit affects "${workspace}"`);
} else {
// subtract 1 because the first package is the workspace itself
info(
`This commit affects "${workspace}" and ${packages.length - 1} ${
packages.length - 1 === 1 ? "dependency" : "dependencies"
} (${packages.slice(1).join(", ")})`
);
}

return continueBuild();
}
info(`This project and its dependencies are not affected`);
return ignoreBuild();
} catch (e) {
error(`Failed to parse JSON output from \`${command}\`.`);
error(e);
return continueBuild();
}
);
});
}
2 changes: 2 additions & 0 deletions packages/turbo-ignore/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ export interface TurboIgnoreOptions {
task?: string;
// A ref/head to compare against if no previously deployed SHA is available
fallback?: string;
// The maxBuffer for the child process in KB
maxBuffer?: number;
}

0 comments on commit 3cad01a

Please sign in to comment.