From fc6555f48467c91b51e52c2efb2d1402ed24458b Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Mon, 6 Nov 2023 21:59:44 +0900 Subject: [PATCH] fix(wb): getAllProjects() --- packages/shared-lib-node/src/hash.ts | 8 +------- packages/wb/src/project.ts | 17 +++++++++-------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/shared-lib-node/src/hash.ts b/packages/shared-lib-node/src/hash.ts index 8e660969..ea564042 100644 --- a/packages/shared-lib-node/src/hash.ts +++ b/packages/shared-lib-node/src/hash.ts @@ -51,13 +51,7 @@ export async function calculateHashFromFiles(...paths: string[]): Promise 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()) { diff --git a/packages/wb/src/project.ts b/packages/wb/src/project.ts index 90fb2091..7a9f9810 100644 --- a/packages/wb/src/project.ts +++ b/packages/wb/src/project.ts @@ -156,17 +156,18 @@ export function findRootAndSelfProjects( async function getAllProjects(argv: EnvReaderOptions, rootProject: Project, loadEnv: boolean): Promise { 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; }