Skip to content

Commit 1df8f4f

Browse files
committed
use await memoized exists
1 parent e042588 commit 1df8f4f

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

packages/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ export abstract class NodeModulesCollector<ProdDepType extends Dependency<ProdDe
172172
return this.cache.realPath.get(filePath)!
173173
}
174174

175+
protected requireMemoized(pkgPath: string): PackageJson {
176+
if (!this.cache.packageJson.has(pkgPath)) {
177+
this.cache.packageJson.set(pkgPath, require(pkgPath))
178+
}
179+
return this.cache.packageJson.get(pkgPath)!
180+
}
181+
182+
protected existsSyncMemoized(filePath: string): boolean {
183+
if (!this.cache.exists.has(filePath)) {
184+
this.cache.exists.set(filePath, fs.existsSync(filePath))
185+
}
186+
return this.cache.exists.get(filePath)!
187+
}
188+
175189
protected async resolvePath(filePath: string): Promise<string> {
176190
// Check if we've already resolved this path
177191
if (this.cache.realPath.has(filePath)) {
@@ -254,20 +268,6 @@ export abstract class NodeModulesCollector<ProdDepType extends Dependency<ProdDe
254268
return null
255269
}
256270

257-
protected requireMemoized(pkgPath: string): PackageJson {
258-
if (!this.cache.packageJson.has(pkgPath)) {
259-
this.cache.packageJson.set(pkgPath, require(pkgPath))
260-
}
261-
return this.cache.packageJson.get(pkgPath)!
262-
}
263-
264-
protected existsSyncMemoized(filePath: string): boolean {
265-
if (!this.cache.exists.has(filePath)) {
266-
this.cache.exists.set(filePath, fs.existsSync(filePath))
267-
}
268-
return this.cache.exists.get(filePath)!
269-
}
270-
271271
protected cacheKey(pkg: ProdDepType): string {
272272
const rel = path.relative(this.rootDir, pkg.path)
273273
return `${pkg.name}::${pkg.version}::${rel ?? "."}`

packages/app-builder-lib/src/node-module-collector/pnpmNodeModulesCollector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmDependenc
2020
const packageName = depTree.name || depTree.from
2121
if (packageName) {
2222
const hoistedPath = path.join(this.rootDir, "node_modules", packageName)
23-
if (this.existsSyncMemoized(hoistedPath)) {
23+
if (await this.existsMemoized(hoistedPath)) {
2424
return hoistedPath
2525
}
2626
}
@@ -74,7 +74,7 @@ export class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmDependenc
7474
// Then check if optional dependency path exists (using actual resolved path)
7575
if (json?.optionalDependencies?.[packageName]) {
7676
const actualPath = await this.resolveActualPath(dependency)
77-
if (!this.existsSyncMemoized(actualPath)) {
77+
if (!(await this.existsMemoized(actualPath))) {
7878
log.debug(null, `Optional dependency ${packageName}@${dependency.version} path doesn't exist: ${actualPath}`)
7979
return undefined
8080
}

0 commit comments

Comments
 (0)