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

fix(core): use argument length that match the actual size of the argument length #21074

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Changes from all commits
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
31 changes: 18 additions & 13 deletions packages/nx/src/utils/chunkify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { execSync } from 'child_process';

const TERMINAL_SIZE =
process.platform === 'win32' ? 8192 : getUnixTerminalSize();
const TERMINAL_SIZE = getMaxArgLength();

export function chunkify(
target: string[],
Expand All @@ -28,14 +25,22 @@ export function chunkify(
return chunks;
}

function getUnixTerminalSize() {
try {
const argMax = execSync('getconf ARG_MAX').toString().trim();
return Number.parseInt(argMax);
} catch {
// This number varies by system, but 100k seems like a safe
// number from some research...
// https://stackoverflow.com/questions/19354870/bash-command-line-and-input-limit
return 100000;
/**
* Get the maximum length of a command-line argument string based on current platform
*
* https://serverfault.com/questions/69430/what-is-the-maximum-length-of-a-command-line-in-mac-os-x
* https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation
* https://unix.stackexchange.com/a/120652
*
* Taken from: https://github.com/lint-staged/lint-staged/blob/adf50b00669f6aac2eeca25dd28ff86a9a3c2a48/lib/index.js#L21-L37
*/
export function getMaxArgLength() {
switch (process.platform) {
case 'darwin':
return 262144;
case 'win32':
return 8191;
default:
return 131072;
}
}