Skip to content

Commit 1317e47

Browse files
alan-agius4filipesilva
authored andcommittedFeb 7, 2022
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 966dd01)
1 parent c6b97eb commit 1317e47

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed
 

‎packages/ngtools/webpack/src/ngcc_processor.ts

+21-11
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,6 @@ export class NgccProcessor {
7373
const runHashBasePath = path.join(this._nodeModulesDirectory, '.cli-ngcc');
7474
const projectBasePath = path.join(this._nodeModulesDirectory, '..');
7575
try {
76-
let lockData;
77-
let lockFile = 'yarn.lock';
78-
try {
79-
lockData = readFileSync(path.join(projectBasePath, lockFile));
80-
} catch {
81-
lockFile = 'package-lock.json';
82-
lockData = readFileSync(path.join(projectBasePath, lockFile));
83-
}
84-
8576
let ngccConfigData;
8677
try {
8778
ngccConfigData = readFileSync(path.join(projectBasePath, 'ngcc.config.js'));
@@ -91,11 +82,12 @@ export class NgccProcessor {
9182

9283
const relativeTsconfigPath = path.relative(projectBasePath, this.tsConfigPath);
9384
const tsconfigData = readFileSync(this.tsConfigPath);
85+
const { lockFileData, lockFilePath } = this.findPackageManagerLockFile(projectBasePath);
9486

9587
// Generate a hash that represents the state of the package lock file and used tsconfig
9688
const runHash = createHash('sha256')
97-
.update(lockData)
98-
.update(lockFile)
89+
.update(lockFileData)
90+
.update(lockFilePath)
9991
.update(ngccConfigData)
10092
.update(tsconfigData)
10193
.update(relativeTsconfigPath)
@@ -248,6 +240,24 @@ export class NgccProcessor {
248240

249241
throw new Error(`Cannot locate the 'node_modules' directory.`);
250242
}
243+
244+
private findPackageManagerLockFile(projectBasePath: string): {
245+
lockFilePath: string;
246+
lockFileData: Buffer;
247+
} {
248+
for (const lockFile of ['yarn.lock', 'pnpm-lock.yaml', 'package-lock.json']) {
249+
const lockFilePath = path.join(projectBasePath, lockFile);
250+
251+
try {
252+
return {
253+
lockFilePath,
254+
lockFileData: readFileSync(lockFilePath),
255+
};
256+
} catch {}
257+
}
258+
259+
throw new Error('Cannot locate a package manager lock file.');
260+
}
251261
}
252262

253263
class NgccLogger implements Logger {

0 commit comments

Comments
 (0)
Please sign in to comment.