From 1317e470ec74d1dd9dced2d0ec0022abfe921995 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 2 Feb 2022 14:21:50 +0100 Subject: [PATCH] fix(@ngtools/webpack): support locating PNPM lock file during NGCC processing Previously, we only handled Yarn and NPM lock files even though PNPM is supported as package manager. The lock file is used to perform checks to determine if an initial execution of NGCC was already performed. Closes #22632 (cherry picked from commit 966dd01eab02cc10eee750c8638b5cf4b58afffe) --- .../ngtools/webpack/src/ngcc_processor.ts | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/ngtools/webpack/src/ngcc_processor.ts b/packages/ngtools/webpack/src/ngcc_processor.ts index 5c9a9a79453b..a7e9c2691f37 100644 --- a/packages/ngtools/webpack/src/ngcc_processor.ts +++ b/packages/ngtools/webpack/src/ngcc_processor.ts @@ -73,15 +73,6 @@ export class NgccProcessor { const runHashBasePath = path.join(this._nodeModulesDirectory, '.cli-ngcc'); const projectBasePath = path.join(this._nodeModulesDirectory, '..'); try { - let lockData; - let lockFile = 'yarn.lock'; - try { - lockData = readFileSync(path.join(projectBasePath, lockFile)); - } catch { - lockFile = 'package-lock.json'; - lockData = readFileSync(path.join(projectBasePath, lockFile)); - } - let ngccConfigData; try { ngccConfigData = readFileSync(path.join(projectBasePath, 'ngcc.config.js')); @@ -91,11 +82,12 @@ export class NgccProcessor { const relativeTsconfigPath = path.relative(projectBasePath, this.tsConfigPath); const tsconfigData = readFileSync(this.tsConfigPath); + const { lockFileData, lockFilePath } = this.findPackageManagerLockFile(projectBasePath); // Generate a hash that represents the state of the package lock file and used tsconfig const runHash = createHash('sha256') - .update(lockData) - .update(lockFile) + .update(lockFileData) + .update(lockFilePath) .update(ngccConfigData) .update(tsconfigData) .update(relativeTsconfigPath) @@ -248,6 +240,24 @@ export class NgccProcessor { throw new Error(`Cannot locate the 'node_modules' directory.`); } + + private findPackageManagerLockFile(projectBasePath: string): { + lockFilePath: string; + lockFileData: Buffer; + } { + for (const lockFile of ['yarn.lock', 'pnpm-lock.yaml', 'package-lock.json']) { + const lockFilePath = path.join(projectBasePath, lockFile); + + try { + return { + lockFilePath, + lockFileData: readFileSync(lockFilePath), + }; + } catch {} + } + + throw new Error('Cannot locate a package manager lock file.'); + } } class NgccLogger implements Logger {