-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): standardize chunking elements passing to cli (#15322)
- Loading branch information
1 parent
8268207
commit bf08714
Showing
4 changed files
with
62 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { chunkify } from './chunkify'; | ||
|
||
describe('chunkify', () => { | ||
it('should wrap chunks at passed in size', () => { | ||
const files = ['aa', 'bb', 'cc', 'dd', 'ee']; | ||
expect(chunkify(files, 4)).toHaveLength(5); | ||
expect(chunkify(files, 7)).toHaveLength(3); | ||
expect(chunkify(files, 16)).toHaveLength(1); | ||
}); | ||
|
||
it('should contain all items from target', () => { | ||
const files = ['aa', 'bb', 'cc', 'dd', 'ee']; | ||
expect(chunkify(files, 7).flat()).toHaveLength(5); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { execSync } from 'child_process'; | ||
|
||
const TERMINAL_SIZE = | ||
process.platform === 'win32' ? 8192 : getUnixTerminalSize(); | ||
|
||
export function chunkify( | ||
target: string[], | ||
maxChunkLength: number = TERMINAL_SIZE - 500 | ||
): string[][] { | ||
const chunks = []; | ||
let currentChunk = []; | ||
let currentChunkLength = 0; | ||
for (const file of target) { | ||
if ( | ||
// Prevent empty chunk if first file path is longer than maxChunkLength | ||
currentChunk.length && | ||
// +1 accounts for the space between file names | ||
currentChunkLength + file.length + 1 >= maxChunkLength | ||
) { | ||
chunks.push(currentChunk); | ||
currentChunk = []; | ||
currentChunkLength = 0; | ||
} | ||
currentChunk.push(file); | ||
currentChunkLength += file.length + 1; | ||
} | ||
chunks.push(currentChunk); | ||
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; | ||
} | ||
} |
bf08714
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev