|
| 1 | +import { getActivePackageManager } from '../../utils/packages'; |
| 2 | +import { ng, npm } from '../../utils/process'; |
| 3 | +import { expectToFail } from '../../utils/utils'; |
| 4 | + |
| 5 | +const errorText = 'The Angular CLI currently requires npm version 6.'; |
| 6 | + |
| 7 | +export default async function() { |
| 8 | + // Only relevant with npm as a package manager |
| 9 | + if (getActivePackageManager() !== 'npm') { |
| 10 | + return; |
| 11 | + } |
| 12 | + |
| 13 | + const currentDirectory = process.cwd(); |
| 14 | + try { |
| 15 | + // Install version 7.x |
| 16 | + await npm('install', '--global', 'npm@7'); |
| 17 | + |
| 18 | + // Ensure `ng add` exits and shows npm error |
| 19 | + const { message: stderrAdd } = await expectToFail(() => ng('add')); |
| 20 | + if (!stderrAdd.includes(errorText)) { |
| 21 | + throw new Error('ng add expected to show npm version error.'); |
| 22 | + } |
| 23 | + |
| 24 | + // Ensure `ng update` exits and shows npm error |
| 25 | + const { message: stderrUpdate } = await expectToFail(() => ng('update')); |
| 26 | + if (!stderrUpdate.includes(errorText)) { |
| 27 | + throw new Error('ng update expected to show npm version error.'); |
| 28 | + } |
| 29 | + |
| 30 | + // Ensure `ng new` exits and shows npm error |
| 31 | + // Must be outside the project for `ng new` |
| 32 | + process.chdir('..'); |
| 33 | + const { message: stderrNew } = await expectToFail(() => ng('new')); |
| 34 | + if (!stderrNew.includes(errorText)) { |
| 35 | + throw new Error('ng new expected to show npm version error.'); |
| 36 | + } |
| 37 | + } finally { |
| 38 | + // Change directory back |
| 39 | + process.chdir(currentDirectory); |
| 40 | + |
| 41 | + // Reset version back to 6.x |
| 42 | + await npm('install', '--global', 'npm@6'); |
| 43 | + } |
| 44 | + |
| 45 | +} |
0 commit comments