Skip to content

Commit

Permalink
fix(wb): getAllProjects()
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Nov 6, 2023
1 parent a5cd812 commit fc6555f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
8 changes: 1 addition & 7 deletions packages/shared-lib-node/src/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ export async function calculateHashFromFiles(...paths: string[]): Promise<string
const dirents = await fs.promises.readdir(fileOrDirPath, { withFileTypes: true, recursive: true });
for (const dirent of dirents.sort((d1, d2) => d1.name.localeCompare(d2.name))) {
if (dirent.isFile()) {
// Node.js 18.17.0 or later has `dirent.path`
hash.update(
await fs.promises.readFile(
path.join((dirent as unknown as Record<'path', string>).path, dirent.name),
'utf8'
)
);
hash.update(await fs.promises.readFile(path.join(fileOrDirPath, dirent.name), 'utf8'));
}
}
} else if (stat.isFile()) {
Expand Down
17 changes: 9 additions & 8 deletions packages/wb/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,18 @@ export function findRootAndSelfProjects(

async function getAllProjects(argv: EnvReaderOptions, rootProject: Project, loadEnv: boolean): Promise<Project[]> {
const allProjects = [rootProject];
const packageDirPath = path.join(rootProject.dirPath, 'packages');
if (!fs.existsSync(packageDirPath)) return allProjects;
const packagesDirPath = path.join(rootProject.dirPath, 'packages');
if (!fs.existsSync(packagesDirPath)) return allProjects;

const packageDirs = await fs.promises.readdir(packageDirPath, { withFileTypes: true });
for (const packageDir of packageDirs) {
if (!packageDir.isDirectory()) continue;
const packageDirs = await fs.promises.readdir(packagesDirPath, { withFileTypes: true });
for (const subPackageDir of packageDirs) {
if (!subPackageDir.isDirectory()) continue;

const packageJsonPath = path.join(packageDirPath, 'package.json');
if (!fs.existsSync(packageJsonPath)) continue;
const subPackageDirPath = path.join(packagesDirPath, subPackageDir.name);
const subPackageJsonPath = path.join(subPackageDirPath, 'package.json');
if (!fs.existsSync(subPackageJsonPath)) continue;

allProjects.push(new Project(packageJsonPath, argv, loadEnv));
allProjects.push(new Project(subPackageJsonPath, argv, loadEnv));
}
return allProjects;
}

0 comments on commit fc6555f

Please sign in to comment.