Skip to content

Commit

Permalink
fix(@ngtools/webpack): support locating PNPM lock file during NGCC pr…
Browse files Browse the repository at this point in the history
…ocessing

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 966dd01)
  • Loading branch information
alan-agius4 authored and filipesilva committed Feb 7, 2022
1 parent c6b97eb commit 1317e47
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions packages/ngtools/webpack/src/ngcc_processor.ts
Expand Up @@ -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'));
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1317e47

Please sign in to comment.