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

feat(turbo-ignore) add a --max-buffer option for dry runs that have large outputs #6052

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
mehulkar marked this conversation as resolved.
Show resolved Hide resolved
maxBuffer?: number;
}