Skip to content

Commit 17ffedc

Browse files
committed
refactor(@angular/cli): remove legacy NPM compatibility check
This check should no longer be needed as on supported versions of Node.js NPM 7.5 is no longer installed by default.
1 parent fe12723 commit 17ffedc

File tree

6 files changed

+43
-185
lines changed

6 files changed

+43
-185
lines changed

packages/angular/cli/src/commands/add/cli.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ export default class AddCommadModule
112112
async run(options: Options<AddCommandArgs> & OtherOptions): Promise<number | void> {
113113
const { logger, packageManager } = this.context;
114114
const { verbose, registry, collection, skipConfirmation } = options;
115-
packageManager.ensureCompatibility();
116115

117116
let packageIdentifier;
118117
try {

packages/angular/cli/src/commands/new/cli.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ export default class NewCommandModule
7474
});
7575
workflow.registry.addSmartDefaultProvider('ng-cli-version', () => VERSION.full);
7676

77-
// Compatibility check for NPM 7
78-
if (
79-
collectionName === '@schematics/angular' &&
80-
!schematicOptions.skipInstall &&
81-
(schematicOptions.packageManager === undefined || schematicOptions.packageManager === 'npm')
82-
) {
83-
this.context.packageManager.ensureCompatibility();
84-
}
85-
8677
return this.runSchematic({
8778
collectionName,
8879
schematicName: this.schematicName,

packages/angular/cli/src/commands/update/cli.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ export default class UpdateCommandModule extends CommandModule<UpdateCommandArgs
178178
async run(options: Options<UpdateCommandArgs>): Promise<number | void> {
179179
const { logger, packageManager } = this.context;
180180

181-
packageManager.ensureCompatibility();
182-
183181
// Check if the current installed CLI version is older than the latest compatible version.
184182
// Skip when running `ng update` without a package name as this will not trigger an actual update.
185183
if (!disableVersionCheck && options.packages?.length) {

packages/angular/cli/src/utilities/package-manager.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { execSync, spawn } from 'child_process';
1111
import { existsSync, promises as fs, realpathSync, rmSync } from 'fs';
1212
import { tmpdir } from 'os';
1313
import { join } from 'path';
14-
import { satisfies, valid } from 'semver';
1514
import { PackageManager } from '../../lib/config/workspace-schema';
1615
import { AngularWorkspace, getProjectByCwd } from './config';
1716
import { memoize } from './memoize';
@@ -44,32 +43,6 @@ export class PackageManagerUtils {
4443
return this.getVersion(this.name);
4544
}
4645

47-
/**
48-
* Checks if the package manager is supported. If not, display a warning.
49-
*/
50-
ensureCompatibility(): void {
51-
if (this.name !== PackageManager.Npm) {
52-
return;
53-
}
54-
55-
try {
56-
const version = valid(this.version);
57-
if (!version) {
58-
return;
59-
}
60-
61-
if (satisfies(version, '>=7 <7.5.6')) {
62-
// eslint-disable-next-line no-console
63-
console.warn(
64-
`npm version ${version} detected.` +
65-
' When using npm 7 with the Angular CLI, npm version 7.5.6 or higher is recommended.',
66-
);
67-
}
68-
} catch {
69-
// npm is not installed.
70-
}
71-
}
72-
7346
/** Install a single package. */
7447
async install(
7548
packageName: string,
Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
import { expectFileToMatch, writeFile } from '../../utils/fs';
1+
import { expectFileToMatch, rimraf, writeFile } from '../../utils/fs';
2+
import { gitClean } from '../../utils/git';
23
import { installWorkspacePackages } from '../../utils/packages';
34
import { ng } from '../../utils/process';
45
import { updateJsonFile } from '../../utils/project';
56
import { expectToFail } from '../../utils/utils';
67

78
export default async function () {
8-
// Force duplicate modules
9-
await updateJsonFile('package.json', (json) => {
10-
json.dependencies = {
11-
...json.dependencies,
12-
'tslib': '2.0.0',
13-
'tslib-1': 'npm:[email protected]',
14-
'tslib-1-copy': 'npm:[email protected]',
15-
};
16-
});
9+
try {
10+
// Force duplicate modules
11+
await updateJsonFile('package.json', (json) => {
12+
json.dependencies = {
13+
...json.dependencies,
14+
'tslib': '2.0.0',
15+
'tslib-1': 'npm:[email protected]',
16+
'tslib-1-copy': 'npm:[email protected]',
17+
};
18+
});
1719

18-
await installWorkspacePackages();
20+
await installWorkspacePackages();
1921

20-
await writeFile(
21-
'./src/main.ts',
22-
`
22+
await writeFile(
23+
'./src/main.ts',
24+
`
2325
import { __assign as __assign_0 } from 'tslib';
2426
import { __assign as __assign_1 } from 'tslib-1';
2527
import { __assign as __assign_2 } from 'tslib-1-copy';
@@ -30,29 +32,34 @@ export default async function () {
3032
__assign_2,
3133
})
3234
`,
33-
);
34-
35-
const { stderr } = await ng(
36-
'build',
37-
'--verbose',
38-
'--no-vendor-chunk',
39-
'--no-progress',
40-
'--configuration=development',
41-
);
42-
const outFile = 'dist/test-project/main.js';
35+
);
4336

44-
if (/\[DedupeModuleResolvePlugin\]:.+tslib-1-copy.+ -> .+tslib-1.+/.test(stderr)) {
45-
await expectFileToMatch(outFile, './node_modules/tslib-1/tslib.es6.js');
46-
await expectToFail(() =>
47-
expectFileToMatch(outFile, './node_modules/tslib-1-copy/tslib.es6.js'),
37+
const { stderr } = await ng(
38+
'build',
39+
'--verbose',
40+
'--no-vendor-chunk',
41+
'--no-progress',
42+
'--configuration=development',
4843
);
49-
} else if (/\[DedupeModuleResolvePlugin\]:.+tslib-1.+ -> .+tslib-1-copy.+/.test(stderr)) {
50-
await expectFileToMatch(outFile, './node_modules/tslib-1-copy/tslib.es6.js');
51-
await expectToFail(() => expectFileToMatch(outFile, './node_modules/tslib-1/tslib.es6.js'));
52-
} else {
53-
console.error(`\n\n\n${stderr}\n\n\n`);
54-
throw new Error('Expected stderr to contain [DedupeModuleResolvePlugin] log for tslib.');
55-
}
44+
const outFile = 'dist/test-project/main.js';
5645

57-
await expectFileToMatch(outFile, './node_modules/tslib/tslib.es6.js');
46+
if (/\[DedupeModuleResolvePlugin\]:.+tslib-1-copy.+ -> .+tslib-1.+/.test(stderr)) {
47+
await expectFileToMatch(outFile, './node_modules/tslib-1/tslib.es6.js');
48+
await expectToFail(() =>
49+
expectFileToMatch(outFile, './node_modules/tslib-1-copy/tslib.es6.js'),
50+
);
51+
} else if (/\[DedupeModuleResolvePlugin\]:.+tslib-1.+ -> .+tslib-1-copy.+/.test(stderr)) {
52+
await expectFileToMatch(outFile, './node_modules/tslib-1-copy/tslib.es6.js');
53+
await expectToFail(() => expectFileToMatch(outFile, './node_modules/tslib-1/tslib.es6.js'));
54+
} else {
55+
console.error(`\n\n\n${stderr}\n\n\n`);
56+
throw new Error('Expected stderr to contain [DedupeModuleResolvePlugin] log for tslib.');
57+
}
58+
59+
await expectFileToMatch(outFile, './node_modules/tslib/tslib.es6.js');
60+
} finally {
61+
await rimraf('node_modules/tslib');
62+
await gitClean();
63+
await installWorkspacePackages();
64+
}
5865
}

tests/legacy-cli/e2e/tests/misc/npm-7.ts

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)