-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathsupported-angular.ts
More file actions
37 lines (33 loc) · 1.55 KB
/
supported-angular.ts
File metadata and controls
37 lines (33 loc) · 1.55 KB
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
import { SemVer } from 'semver';
import { getGlobalVariable } from '../../utils/env';
import { readFile, writeFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { expectToFail } from '../../utils/utils';
export default async function () {
if (getGlobalVariable('argv')['ng-snapshots']) {
// The snapshots job won't work correctly because it doesn't use semver for Angular.
return;
}
const angularCliPkgJson = JSON.parse(await readFile('node_modules/@angular/cli/package.json'));
const cliMajor = new SemVer(angularCliPkgJson.version as string).major;
const angularCorePkgPath = 'node_modules/@angular/core/package.json';
const originalAngularCorePkgJson = await readFile(angularCorePkgPath);
// Fake version by writing over the @angular/core version, since that's what the CLI checks.
const fakeCoreVersion = async (newMajor: number) => {
const tmpPkgJson = JSON.parse(originalAngularCorePkgJson);
tmpPkgJson.version = `${newMajor}.0.0`;
await writeFile(angularCorePkgPath, JSON.stringify(tmpPkgJson));
};
// Major should succeed, but we don't need to test it here since it's tested everywhere else.
// Major+1 and -1 should fail architect commands, but allow other commands.
try {
await fakeCoreVersion(cliMajor + 1);
await expectToFail(() => ng('build'), 'Should fail Major+1');
await ng('version');
await fakeCoreVersion(cliMajor - 1);
await ng('version');
} finally {
// Restore the original core package.json.
await writeFile(angularCorePkgPath, originalAngularCorePkgJson);
}
}