From c267509df154a97609c0eebe795bd354f361c621 Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Thu, 24 Jun 2021 15:37:19 +0200 Subject: [PATCH] api-extractor: check whether folder has a package.json Often when switching between branches, I have empty folders in my working copy and Git doesn't track folders. Another case is the now deleted `core` package which remains as an empty folder locally (due to the node_modules folder still being there). Sadly, api-extractor crashes on empty folder, so this introduces a check that the folder is a package by checking for the package.json file. Signed-off-by: Oliver Sand --- scripts/api-extractor.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/api-extractor.ts b/scripts/api-extractor.ts index 3660c72932..2631f7de93 100644 --- a/scripts/api-extractor.ts +++ b/scripts/api-extractor.ts @@ -21,6 +21,7 @@ import { resolve as resolvePath, relative as relativePath, dirname, + join, } from 'path'; import fs from 'fs-extra'; import { @@ -96,6 +97,13 @@ async function findPackageDirs() { continue; } + try { + const packageJsonPath = join(fullPackageDir, 'package.json'); + await fs.access(packageJsonPath); + } catch (_) { + continue; + } + const packageDir = relativePath(projectRoot, fullPackageDir); if (!SKIPPED_PACKAGES.includes(packageDir)) { packageDirs.push(packageDir);