From dcf01604a20adb92efdb6b7b90c67b487689aab1 Mon Sep 17 00:00:00 2001 From: Liamolucko Date: Fri, 6 Nov 2020 08:56:54 +1100 Subject: [PATCH 1/2] Follow symlinks (to support PNPM) --- src/Walker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Walker.ts b/src/Walker.ts index 46cf1fd..f67449c 100644 --- a/src/Walker.ts +++ b/src/Walker.ts @@ -51,7 +51,7 @@ export class Walker { } private async walkDependenciesForModuleInModule(moduleName: string, modulePath: string, depType: DepType) { - let testPath = modulePath; + let testPath = await fs.realpath(modulePath); let discoveredPath: string | null = null; let lastRelative: string | null = null; // Try find it while searching recursively up the tree From 8c8ce1d3c64100d7bf99eabb803e8535338debb3 Mon Sep 17 00:00:00 2001 From: Liamolucko Date: Fri, 6 Nov 2020 09:34:55 +1100 Subject: [PATCH 2/2] Memoize realpaths --- src/Walker.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Walker.ts b/src/Walker.ts index f67449c..28f5e5b 100644 --- a/src/Walker.ts +++ b/src/Walker.ts @@ -25,6 +25,7 @@ export class Walker { private rootModule: string; private modules: Module[]; private walkHistory: Set = new Set(); + private realPaths: Map = new Map(); constructor(modulePath: string) { if (!modulePath || typeof modulePath !== 'string') { @@ -51,7 +52,11 @@ export class Walker { } private async walkDependenciesForModuleInModule(moduleName: string, modulePath: string, depType: DepType) { - let testPath = await fs.realpath(modulePath); + let testPath = this.realPaths.get(modulePath); + if (!testPath) { + testPath = await fs.realpath(modulePath); + this.realPaths.set(modulePath, testPath); + } let discoveredPath: string | null = null; let lastRelative: string | null = null; // Try find it while searching recursively up the tree