mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-26 09:21:51 +08:00
fix(@angular/cli): remove npm 7 incompatibility notification
npm 7.5.6 contains several fixes that allow it to work successfully with the Angular CLI. The minimum npm engine value is now set to support npm versions greater than 7.5.6 (npm 6 support remains unchanged). A warning will be shown to users with npm 7 versions less than 7.5.6 when used with the new, add, or update commands.
This commit is contained in:
parent
7ef73c8524
commit
065ac4546f
@ -88,7 +88,7 @@ function loadPackageJson(p: string) {
|
|||||||
case 'engines':
|
case 'engines':
|
||||||
pkg['engines'] = {
|
pkg['engines'] = {
|
||||||
'node': '>= 12.13.0',
|
'node': '>= 12.13.0',
|
||||||
'npm': '^6.11.0',
|
'npm': '^6.11.0 || ^7.5.6',
|
||||||
'yarn': '>= 1.13.0',
|
'yarn': '>= 1.13.0',
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
import { satisfies, valid } from 'semver';
|
||||||
import { PackageManager } from '../lib/config/schema';
|
import { PackageManager } from '../lib/config/schema';
|
||||||
import { getConfiguredPackageManager } from './config';
|
import { getConfiguredPackageManager } from './config';
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ export async function getPackageManager(root: string): Promise<PackageManager> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the npm version is version 6.x. If not, display a message and exit.
|
* Checks if the npm version is a supported 7.x version. If not, display a warning.
|
||||||
*/
|
*/
|
||||||
export async function ensureCompatibleNpm(root: string): Promise<void> {
|
export async function ensureCompatibleNpm(root: string): Promise<void> {
|
||||||
if ((await getPackageManager(root)) !== PackageManager.Npm) {
|
if ((await getPackageManager(root)) !== PackageManager.Npm) {
|
||||||
@ -64,21 +65,19 @@ export async function ensureCompatibleNpm(root: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const version = execSync('npm --version', {encoding: 'utf8', stdio: 'pipe'}).trim();
|
const versionText = execSync('npm --version', {encoding: 'utf8', stdio: 'pipe'}).trim();
|
||||||
const major = Number(version.match(/^(\d+)\./)?.[1]);
|
const version = valid(versionText);
|
||||||
if (major <= 6) {
|
if (!version) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tslint:disable-next-line: no-console
|
if (satisfies(version, '>=7 <7.5.6')) {
|
||||||
console.error(
|
// tslint:disable-next-line: no-console
|
||||||
`npm version ${version} detected. The Angular CLI temporarily requires npm version 6 while upstream issues are addressed.\n\n` +
|
console.warn(
|
||||||
'Please install a compatible version to proceed (`npm install --global npm@6`).\n' +
|
`npm version ${version} detected.` +
|
||||||
'For additional information and alternative workarounds, please see ' +
|
' When using npm 7 with the Angular CLI, npm version 7.5.6 or higher is recommended.',
|
||||||
'https://github.com/angular/angular-cli/issues/19957#issuecomment-775407654',
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
process.exit(3);
|
|
||||||
} catch {
|
} catch {
|
||||||
// npm is not installed
|
// npm is not installed
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { getActivePackageManager } from '../../utils/packages';
|
|||||||
import { ng, npm } from '../../utils/process';
|
import { ng, npm } from '../../utils/process';
|
||||||
import { expectToFail } from '../../utils/utils';
|
import { expectToFail } from '../../utils/utils';
|
||||||
|
|
||||||
const errorText = 'The Angular CLI temporarily requires npm version 6';
|
const warningText = 'npm version 7.5.6 or higher is recommended';
|
||||||
|
|
||||||
export default async function() {
|
export default async function() {
|
||||||
// Only relevant with npm as a package manager
|
// Only relevant with npm as a package manager
|
||||||
@ -18,53 +18,62 @@ export default async function() {
|
|||||||
|
|
||||||
const currentDirectory = process.cwd();
|
const currentDirectory = process.cwd();
|
||||||
try {
|
try {
|
||||||
// Install version 7.x
|
// Install version >=7.5.6
|
||||||
await npm('install', '--global', 'npm@7');
|
await npm('install', '--global', 'npm@>=7.5.6');
|
||||||
|
|
||||||
// Ensure `ng add` exits and shows npm error
|
// Ensure `ng update` does not show npm warning
|
||||||
const { message: stderrAdd } = await expectToFail(() => ng('add'));
|
const { stderr: stderrUpdate1 } = await ng('update');
|
||||||
if (!stderrAdd.includes(errorText)) {
|
if (stderrUpdate1.includes(warningText)) {
|
||||||
throw new Error('ng add expected to show npm version error.');
|
throw new Error('ng update expected to not show npm version warning.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure `ng update` exits and shows npm error
|
// Install version <7.5.6
|
||||||
const { message: stderrUpdate } = await expectToFail(() => ng('update'));
|
await npm('install', '--global', 'npm@7.4.0');
|
||||||
if (!stderrUpdate.includes(errorText)) {
|
|
||||||
throw new Error('ng update expected to show npm version error.');
|
// Ensure `ng add` shows npm warning
|
||||||
|
const { message: stderrAdd } = await expectToFail(() => ng('add'));
|
||||||
|
if (!stderrAdd.includes(warningText)) {
|
||||||
|
throw new Error('ng add expected to show npm version warning.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure `ng update` shows npm warning
|
||||||
|
const { stderr: stderrUpdate2 } = await ng('update');
|
||||||
|
if (!stderrUpdate2.includes(warningText)) {
|
||||||
|
throw new Error('ng update expected to show npm version warning.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure `ng build` executes successfully
|
// Ensure `ng build` executes successfully
|
||||||
const { stderr: stderrBuild } = await ng('build');
|
const { stderr: stderrBuild } = await ng('build');
|
||||||
if (stderrBuild.includes(errorText)) {
|
if (stderrBuild.includes(warningText)) {
|
||||||
throw new Error('ng build expected to not show npm version error.');
|
throw new Error('ng build expected to not show npm version warning.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure `ng new` exits and shows npm error
|
// Ensure `ng new` shows npm warning
|
||||||
// Must be outside the project for `ng new`
|
// Must be outside the project for `ng new`
|
||||||
process.chdir('..');
|
process.chdir('..');
|
||||||
const { message: stderrNew } = await expectToFail(() => ng('new'));
|
const { message: stderrNew } = await expectToFail(() => ng('new'));
|
||||||
if (!stderrNew.includes(errorText)) {
|
if (!stderrNew.includes(warningText)) {
|
||||||
throw new Error('ng new expected to show npm version error.');
|
throw new Error('ng new expected to show npm version warning.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure `ng new --package-manager=npm` exits and shows npm error
|
// Ensure `ng new --package-manager=npm` shows npm warning
|
||||||
const { message: stderrNewNpm } = await expectToFail(() => ng('new', '--package-manager=npm'));
|
const { message: stderrNewNpm } = await expectToFail(() => ng('new', '--package-manager=npm'));
|
||||||
if (!stderrNewNpm.includes(errorText)) {
|
if (!stderrNewNpm.includes(warningText)) {
|
||||||
throw new Error('ng new expected to show npm version error.');
|
throw new Error('ng new expected to show npm version warning.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure `ng new --skip-install` executes successfully
|
// Ensure `ng new --skip-install` executes successfully
|
||||||
const { stderr: stderrNewSkipInstall } = await ng('new', 'npm-seven-skip', '--skip-install');
|
const { stderr: stderrNewSkipInstall } = await ng('new', 'npm-seven-skip', '--skip-install');
|
||||||
if (stderrNewSkipInstall.includes(errorText)) {
|
if (stderrNewSkipInstall.includes(warningText)) {
|
||||||
throw new Error('ng new --skip-install expected to not show npm version error.');
|
throw new Error('ng new --skip-install expected to not show npm version warning.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure `ng new --package-manager=yarn` executes successfully
|
// Ensure `ng new --package-manager=yarn` executes successfully
|
||||||
// Need an additional npmrc file since yarn does not use the NPM registry environment variable
|
// Need an additional npmrc file since yarn does not use the NPM registry environment variable
|
||||||
await writeFile('.npmrc', 'registry=http://localhost:4873')
|
await writeFile('.npmrc', 'registry=http://localhost:4873')
|
||||||
const { stderr: stderrNewYarn } = await ng('new', 'npm-seven-yarn', '--package-manager=yarn');
|
const { stderr: stderrNewYarn } = await ng('new', 'npm-seven-yarn', '--package-manager=yarn');
|
||||||
if (stderrNewYarn.includes(errorText)) {
|
if (stderrNewYarn.includes(warningText)) {
|
||||||
throw new Error('ng new --package-manager=yarn expected to not show npm version error.');
|
throw new Error('ng new --package-manager=yarn expected to not show npm version warning.');
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Cleanup extra test projects
|
// Cleanup extra test projects
|
||||||
|
Loading…
x
Reference in New Issue
Block a user