From 511218f10fd36a8a46d209e348095fe3b558addc Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Wed, 10 Aug 2022 13:26:54 -0700 Subject: [PATCH] fix: support deeply nested pnpm virtual store node_modules paths in resolveAndRunNgcc (#1742) Uses indexOf instead of lastIndexOf in resolveAndRunNgcc. This resolves the case where a user is using pnpm and ngcc is resolved through symlinks to a deeply nested virtual store node_modules location: `some/user/path/node_modules/.pnpm/@angular/compiler-cli@1.2.3/node_modules/@angular/compiler-cli/...` lastIndexOf would resolve to `some/user/path/node_modules/.pnpm/@angular/compiler-cli@1.2.3` which is incorrect. indexOf gets you to the desired `some/user/path` --- server/src/ngcc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/ngcc.ts b/server/src/ngcc.ts index 1b0cb85606..a62713de40 100644 --- a/server/src/ngcc.ts +++ b/server/src/ngcc.ts @@ -27,7 +27,7 @@ export async function resolveAndRunNgcc(tsconfig: string, progress: Progress): P if (!ngcc) { throw new Error(`Failed to resolve ngcc from ${directory}`); } - const index = ngcc.resolvedPath.lastIndexOf('node_modules'); + const index = ngcc.resolvedPath.indexOf('node_modules'); // By default, ngcc assumes the node_modules directory that it needs to process // is in the cwd. In our case, we should set cwd to the directory where ngcc // is resolved to, not the directory where tsconfig.json is located. See