Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular/cli): verify Angular version is supported
- Loading branch information
1 parent
bab9eb6
commit 5ec27db
Showing
11 changed files
with
84 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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'] || getGlobalVariable('argv')['ivy']) { | ||
// Don't run this test in snapshots or Ivy test jobs. | ||
// The snapshots job won't work correctly because it doesn't use semver for Angular, and the | ||
// Ivy job will fail because Ivy wasn't stable in 7. | ||
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. | ||
await fakeCoreVersion(cliMajor + 1); | ||
await expectToFail(() => ng('build'), 'Should fail Major+1'); | ||
await ng('version'); | ||
await fakeCoreVersion(cliMajor - 1); | ||
await ng('version'); | ||
|
||
// Restore the original core package.json. | ||
await writeFile(angularCorePkgPath, originalAngularCorePkgJson); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters