From 45ce663ca6c134e7a0792e689750c95b41b464bd Mon Sep 17 00:00:00 2001 From: Mehul Kar Date: Thu, 28 Sep 2023 15:02:27 -0500 Subject: [PATCH 1/5] feat(turbo-ignore) add a --max-buffer option for dry runs that have large outputs --- packages/turbo-ignore/src/cli.ts | 6 +++ packages/turbo-ignore/src/ignore.ts | 84 +++++++++++++++-------------- packages/turbo-ignore/src/types.ts | 2 + 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/packages/turbo-ignore/src/cli.ts b/packages/turbo-ignore/src/cli.ts index bb0a88dd005d3..f339af3607158 100755 --- a/packages/turbo-ignore/src/cli.ts +++ b/packages/turbo-ignore/src/cli.ts @@ -30,6 +30,12 @@ turboIgnoreCli "The directory to run in (default: cwd)" ) ) + .addOption( + new Option( + "-b, --max-buffer ", + "maxBuffer for the child process in KB (default: 1024 * 1024)" + ).argParser((val) => parseInt(val, 10)) + ) .version(cliPkg.version, "-v, --version", "Output the current version") .helpOption("-h, --help", "Display help for command") .showHelpAfterError(false) diff --git a/packages/turbo-ignore/src/ignore.ts b/packages/turbo-ignore/src/ignore.ts index 764ec8e8010af..66374dfe32875 100644 --- a/packages/turbo-ignore/src/ignore.ts +++ b/packages/turbo-ignore/src/ignore.ts @@ -95,50 +95,54 @@ 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; + } + + info(`execOptions: ${JSON.stringify(execOptions, null, 2)}`); + 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(); } - ); + }); } diff --git a/packages/turbo-ignore/src/types.ts b/packages/turbo-ignore/src/types.ts index 34ad4e759ddfc..1ff1b1d24da70 100644 --- a/packages/turbo-ignore/src/types.ts +++ b/packages/turbo-ignore/src/types.ts @@ -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; } From ed7a0813410dd03dc2f6fce155fb36f1c713b3cf Mon Sep 17 00:00:00 2001 From: Mehul Kar Date: Thu, 28 Sep 2023 15:34:20 -0500 Subject: [PATCH 2/5] Update packages/turbo-ignore/src/cli.ts Co-authored-by: Chris Olszewski --- packages/turbo-ignore/src/cli.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/turbo-ignore/src/cli.ts b/packages/turbo-ignore/src/cli.ts index f339af3607158..4b17b284db029 100755 --- a/packages/turbo-ignore/src/cli.ts +++ b/packages/turbo-ignore/src/cli.ts @@ -33,8 +33,8 @@ turboIgnoreCli .addOption( new Option( "-b, --max-buffer ", - "maxBuffer for the child process in KB (default: 1024 * 1024)" - ).argParser((val) => parseInt(val, 10)) + "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") From ad151905f79ce9a9f0ec4d78976413fbcc3bfd3d Mon Sep 17 00:00:00 2001 From: Mehul Kar Date: Thu, 28 Sep 2023 15:34:25 -0500 Subject: [PATCH 3/5] Update packages/turbo-ignore/src/types.ts Co-authored-by: Chris Olszewski --- packages/turbo-ignore/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/turbo-ignore/src/types.ts b/packages/turbo-ignore/src/types.ts index 1ff1b1d24da70..d32f602afc4d4 100644 --- a/packages/turbo-ignore/src/types.ts +++ b/packages/turbo-ignore/src/types.ts @@ -23,6 +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 + // The maxBuffer for the child process in bytes maxBuffer?: number; } From a62f0656f6db68faee10c28dd45f107b957619c9 Mon Sep 17 00:00:00 2001 From: Mehul Kar Date: Thu, 28 Sep 2023 15:34:39 -0500 Subject: [PATCH 4/5] rm debug log --- packages/turbo-ignore/src/ignore.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/turbo-ignore/src/ignore.ts b/packages/turbo-ignore/src/ignore.ts index 66374dfe32875..0ad049f10fddd 100644 --- a/packages/turbo-ignore/src/ignore.ts +++ b/packages/turbo-ignore/src/ignore.ts @@ -104,7 +104,6 @@ export function turboIgnore( execOptions.maxBuffer = opts.maxBuffer; } - info(`execOptions: ${JSON.stringify(execOptions, null, 2)}`); exec(command, execOptions, (err, stdout) => { if (err) { const { level, code, message } = shouldWarn({ err: err.message }); From aad4b563a041f3be950b3d4eb37d279e798690a9 Mon Sep 17 00:00:00 2001 From: Mehul Kar Date: Thu, 28 Sep 2023 15:35:46 -0500 Subject: [PATCH 5/5] Update packages/turbo-ignore/src/types.ts --- packages/turbo-ignore/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/turbo-ignore/src/types.ts b/packages/turbo-ignore/src/types.ts index d32f602afc4d4..1ff1b1d24da70 100644 --- a/packages/turbo-ignore/src/types.ts +++ b/packages/turbo-ignore/src/types.ts @@ -23,6 +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 bytes + // The maxBuffer for the child process in KB maxBuffer?: number; }