Chore: gracefully handle empty folders on dev machines

This commit is contained in:
Tobias Diez 2024-10-07 10:42:04 +08:00
parent e33f6714c6
commit 55d22d69f8

View File

@ -5,7 +5,7 @@ import * as process from 'node:process';
import { globalExternals } from '@fal-works/esbuild-plugin-global-externals';
import { spawn } from 'cross-spawn';
import * as esbuild from 'esbuild';
import { readJson } from 'fs-extra';
import { pathExists, readJson } from 'fs-extra';
import { glob } from 'glob';
import limit from 'p-limit';
import picocolors from 'picocolors';
@ -129,10 +129,19 @@ export const getWorkspace = async () => {
return Promise.all(
workspaces
.flatMap((p) => p.map((i) => join(CODE_DIRECTORY, i)))
.map(async (p) => {
const pkg = await readJson(join(p, 'package.json'));
return { ...pkg, path: p } as typefest.PackageJson &
.map(async (packagePath) => {
const packageJsonPath = join(packagePath, 'package.json');
if (!(await pathExists(packageJsonPath))) {
// If we delete a package, then an empty folder might still be left behind on some dev machines
// In this case, just ignore the folder
console.warn(
`No package.json found in ${packagePath}. You might want to delete this folder.`
);
return null;
}
const pkg = await readJson(packageJsonPath);
return { ...pkg, path: packagePath } as typefest.PackageJson &
Required<Pick<typefest.PackageJson, 'name' | 'version'>> & { path: string };
})
);
).then((packages) => packages.filter((p) => p !== null));
};