refactor(compiler-cli): ngcc entry-point manifest hash is now configurable (#42582)

The hash algorithm for the entry-point manifest was hardcoded to `md5`.
This can now be configured by the `hashAlgorithm` property on the
ngcc.config.js project configuration.

PR Close #42582
This commit is contained in:
Pete Bacon Darwin 2021-06-16 12:25:13 +01:00 committed by Jessica Janiuk
parent a3b6d65580
commit b8ef83b10f
2 changed files with 4 additions and 4 deletions

View File

@ -236,10 +236,12 @@ export class NgccConfiguration {
private projectConfig: PartiallyProcessedConfig; private projectConfig: PartiallyProcessedConfig;
private cache = new Map<string, VersionedPackageConfig>(); private cache = new Map<string, VersionedPackageConfig>();
readonly hash: string; readonly hash: string;
readonly hashAlgorithm: string;
constructor(private fs: ReadonlyFileSystem, baseDir: AbsoluteFsPath) { constructor(private fs: ReadonlyFileSystem, baseDir: AbsoluteFsPath) {
this.defaultConfig = this.processProjectConfig(DEFAULT_NGCC_CONFIG); this.defaultConfig = this.processProjectConfig(DEFAULT_NGCC_CONFIG);
this.projectConfig = this.processProjectConfig(this.loadProjectConfig(baseDir)); this.projectConfig = this.processProjectConfig(this.loadProjectConfig(baseDir));
this.hashAlgorithm = this.projectConfig.hashAlgorithm;
this.hash = this.computeHash(); this.hash = this.computeHash();
} }
@ -390,9 +392,7 @@ export class NgccConfiguration {
} }
private computeHash(): string { private computeHash(): string {
return createHash(this.projectConfig.hashAlgorithm) return createHash(this.hashAlgorithm).update(JSON.stringify(this.projectConfig)).digest('hex');
.update(JSON.stringify(this.projectConfig))
.digest('hex');
} }
} }

View File

@ -159,7 +159,7 @@ export class EntryPointManifest {
const lockFilePath = this.fs.resolve(directory, lockFileName); const lockFilePath = this.fs.resolve(directory, lockFileName);
if (this.fs.exists(lockFilePath)) { if (this.fs.exists(lockFilePath)) {
const lockFileContents = this.fs.readFile(lockFilePath); const lockFileContents = this.fs.readFile(lockFilePath);
return createHash('md5').update(lockFileContents).digest('hex'); return createHash(this.config.hashAlgorithm).update(lockFileContents).digest('hex');
} }
} }
return null; return null;