-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathsnapshot-serializers.ts
40 lines (37 loc) · 1.07 KB
/
snapshot-serializers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function escapeRegExp(str: string) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function normalizeVersionOfPackage(str: string, pkg: string) {
const regex = new RegExp(
`("${escapeRegExp(pkg)}": "[~|^]\\d+\\.)(\\d+\\.\\d+)"`,
);
return str.replace(regex, '$1X.X"');
}
const dependenciesToNormalize = [
'@angular-devkit/build-angular',
'@angular/build',
'@angular/cli',
'@angular/compiler-cli',
'ng-packagr',
'typescript',
];
/**
* Normalize dependencies controlled by the Angular CLI so that only the major version is explicitly
* checked so that we can massively cut down on snapshot update noise across PRs.
*/
export const normalizeVersionsOfPackagesWeDoNotControl = {
serialize(str: string) {
for (const pkg of dependenciesToNormalize) {
str = normalizeVersionOfPackage(str, pkg);
}
return str;
},
test(val: string) {
// Only run if we think it's package.json contents
return (
val != null &&
typeof val === 'string' &&
dependenciesToNormalize.some((pkg) => val.includes(`"${pkg}"`))
);
},
};