diff --git a/packages/repo-tools/src/commands/api-reports/api-reports.ts b/packages/repo-tools/src/commands/api-reports/api-reports.ts index b8b9f9fb23..4e568102d9 100644 --- a/packages/repo-tools/src/commands/api-reports/api-reports.ts +++ b/packages/repo-tools/src/commands/api-reports/api-reports.ts @@ -24,7 +24,6 @@ import { } from './api-extractor'; import { paths as cliPaths, resolvePackagePaths } from '../../lib/paths'; import { generateTypeDeclarations } from './generateTypeDeclarations'; -import fs from 'fs/promises'; type Options = { ci?: boolean; @@ -50,10 +49,6 @@ export const buildApiReports = async (paths: string[] = [], opts: Options) => { const isAllPackages = !paths?.length; - if (!isAllPackages) { - checkValidPaths(paths); - } - const selectedPackageDirs = await resolvePackagePaths({ paths, include: opts.include, @@ -143,19 +138,3 @@ function parseArrayOption(value: string | undefined) { .filter(Boolean) : []; } - -/** - * Checks if the provided paths are valid. - * - * @throws Error if any of the paths are invalid. - * @param paths An array of paths to check. - */ -function checkValidPaths(paths: string[]) { - paths.forEach(async path => { - try { - await fs.access(path); - } catch (error) { - throw new Error(`Invalid path provided: ${path}`); - } - }); -} diff --git a/packages/repo-tools/src/lib/paths.ts b/packages/repo-tools/src/lib/paths.ts index 96fc92f035..0dcec32ff1 100644 --- a/packages/repo-tools/src/lib/paths.ts +++ b/packages/repo-tools/src/lib/paths.ts @@ -36,6 +36,23 @@ export async function resolvePackagePaths( const { paths: providedPaths, include, exclude } = options; let packages = await PackageGraph.listTargetPackages(); + if (providedPaths && providedPaths.length > 0) { + const invalidPaths: string[] = []; + for (const path of providedPaths) { + const matches = packages.some( + ({ dir }) => + new Minimatch(path).match(relativePath(paths.targetRoot, dir)) || + isChildPath(dir, path), + ); + if (!matches) { + invalidPaths.push(path); + } + } + if (invalidPaths.length > 0) { + throw new Error(`Invalid paths provided: ${invalidPaths.join(', ')}`); + } + } + if (providedPaths && providedPaths.length > 0) { packages = packages.filter(({ dir }) => providedPaths.some(