diff --git a/packages/nx-semantic-release/src/utils/promise-filter.ts b/packages/nx-semantic-release/src/utils/promise-filter.ts index 5340d679..7c4b48c0 100644 --- a/packages/nx-semantic-release/src/utils/promise-filter.ts +++ b/packages/nx-semantic-release/src/utils/promise-filter.ts @@ -1,9 +1,21 @@ -export const promiseFilter = ( +export const promiseFilter = async ( array: T[], predicate: (item: T) => Promise -): Promise => - Promise.all( - array.map((item) => - predicate(item).then((result) => (result ? item : null)) - ) - ).then((results) => results.filter(Boolean)) as Promise; +): Promise => { + const chunkSize = 2000; + const chunks = Array(Math.ceil(array.length / chunkSize)) + .fill(null) + .map((_, index) => array.slice(index * chunkSize, (index + 1) * chunkSize)); + + const results = []; + for (const chunk of chunks) { + const chunkResults = await Promise.all( + chunk.map((item) => predicate(item).then((result) => ({ item, result }))) + ); + results.push( + ...chunkResults.filter(({ result }) => result).map(({ item }) => item) + ); + } + + return results; +};