()
| 92 | }; |
| 93 | |
| 94 | export async function findNewPieces(): Promise<PieceMetadata[]> { |
| 95 | const changedDistPaths = getChangedPiecesDistPaths() |
| 96 | const paths = changedDistPaths ?? await findAllDistPaths() |
| 97 | |
| 98 | console.info(`[findNewPieces] scanning ${paths.length} dist paths${changedDistPaths ? ' (scoped to changed)' : ' (all)'}`) |
| 99 | |
| 100 | const changedPieces: PieceMetadata[] = [] |
| 101 | |
| 102 | // Adding batches because of memory limit when we have a lot of pieces |
| 103 | const batchSize = 75 |
| 104 | for (let i = 0; i < paths.length; i += batchSize) { |
| 105 | const batch = paths.slice(i, i + batchSize) |
| 106 | const batchResults = await Promise.all(batch.map(async (folderPath) => { |
| 107 | const packageJson = await readPackageJson(folderPath); |
| 108 | if (NON_PIECES_PACKAGES.includes(packageJson.name)) { |
| 109 | return null; |
| 110 | } |
| 111 | const exists = await pieceMetadataExists(packageJson.name, packageJson.version) |
| 112 | if (!exists) { |
| 113 | try { |
| 114 | return loadPieceFromFolder(folderPath); |
| 115 | } catch (ex) { |
| 116 | return null; |
| 117 | } |
| 118 | } |
| 119 | return null; |
| 120 | })) |
| 121 | |
| 122 | const validResults = batchResults.filter((piece): piece is PieceMetadata => piece !== null) |
| 123 | changedPieces.push(...validResults) |
| 124 | } |
| 125 | |
| 126 | return changedPieces; |
| 127 | } |
| 128 | |
| 129 | function getChangedPiecesDistPaths(): string[] | null { |
| 130 | const changedPieces = process.env['CHANGED_PIECES'] |
no test coverage detected