From 4a77267dacc59d92b14f07fc8cccc8a75bdb4d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 5 Dec 2023 11:38:04 +0100 Subject: [PATCH] address comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../src/commands/api-reports/api-extractor.ts | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/repo-tools/src/commands/api-reports/api-extractor.ts b/packages/repo-tools/src/commands/api-reports/api-extractor.ts index 8f7a298764..b8c241bb0b 100644 --- a/packages/repo-tools/src/commands/api-reports/api-extractor.ts +++ b/packages/repo-tools/src/commands/api-reports/api-extractor.ts @@ -379,17 +379,21 @@ export async function runApiExtraction({ ); const names = group.map(ep => ep.name); - const staleReportFiles = fs.readdirSync(projectFolder).filter(filename => { - const match = - filename.match(/^(.+)-api-report\.md$/) || - filename.match(/^api-report-(.+)\.md$/); - return match && !names.includes(match[1]); - }); + const remainingReportFiles = new Set( + fs + .readdirSync(projectFolder) + .filter( + filename => + filename.match(/^(.+)-api-report\.md$/) || + filename.match(/^api-report(-.+)?\.md$/), + ), + ); for (const name of names) { const suffix = name === 'index' ? '' : `-${name}`; const reportFileName = `api-report${suffix}.md`; const reportPath = resolvePath(projectFolder, reportFileName); + remainingReportFiles.delete(reportFileName); const warningCountBefore = await countApiReportWarnings(reportPath); @@ -593,20 +597,21 @@ export async function runApiExtraction({ 'Please fix these warnings in order to keep the API Reports tidy.', ); } - if (staleReportFiles.length) { - if (noBail) { - for (const f of staleReportFiles) { - fs.rmSync(resolvePath(projectFolder, f)); - console.log(`Deleted deprecated API report ${f}`); - } - } else { - const staleList = staleReportFiles - .map(f => join(packageDir, f)) - .join(', '); - throw new Error( - `The API Report(s) ${staleList} are no longer relevant and should be deleted`, - ); + } + + if (remainingReportFiles.size > 0) { + if (isLocalBuild) { + for (const f of remainingReportFiles) { + fs.rmSync(resolvePath(projectFolder, f)); + console.log(`Deleted deprecated API report ${f}`); } + } else { + const staleList = [...remainingReportFiles] + .map(f => join(packageDir, f)) + .join(', '); + throw new Error( + `The API Report(s) ${staleList} are no longer relevant and should be deleted`, + ); } } }