1
+ import { rimraf } from '../../utils/fs' ;
1
2
import { ng , npm } from '../../utils/process' ;
2
3
import { expectToFail } from '../../utils/utils' ;
3
4
4
- const errorText = 'The Angular CLI currently requires npm version 6. ' ;
5
+ const warningText = 'npm version 7.5.6 or higher is recommended ' ;
5
6
6
7
export default async function ( ) {
7
8
// Windows CI fails with permission errors when trying to replace npm
@@ -11,29 +12,66 @@ export default async function() {
11
12
12
13
const currentDirectory = process . cwd ( ) ;
13
14
try {
14
- // Install version 7.x
15
- await npm ( 'install' , '--global' , 'npm@7 ' ) ;
15
+ // Install version >=7.5.6
16
+ await npm ( 'install' , '--global' , 'npm@>=7.5.6 ' ) ;
16
17
17
- // Ensure `ng add` exits and shows npm error
18
+ // Ensure `ng update` does not show npm warning
19
+ const { stderr : stderrUpdate1 } = await ng ( 'update' ) ;
20
+ if ( stderrUpdate1 . includes ( warningText ) ) {
21
+ throw new Error ( 'ng update expected to not show npm version warning.' ) ;
22
+ }
23
+
24
+ // Install version <7.5.6
25
+ await npm ( 'install' , '--global' , '[email protected] ' ) ;
26
+
27
+ // Ensure `ng add` shows npm warning
18
28
const { message : stderrAdd } = await expectToFail ( ( ) => ng ( 'add' ) ) ;
19
- if ( ! stderrAdd . includes ( errorText ) ) {
20
- throw new Error ( 'ng add expected to show npm version error .' ) ;
29
+ if ( ! stderrAdd . includes ( warningText ) ) {
30
+ throw new Error ( 'ng add expected to show npm version warning .' ) ;
21
31
}
22
32
23
- // Ensure `ng update` exits and shows npm error
24
- const { message : stderrUpdate } = await expectToFail ( ( ) => ng ( 'update' ) ) ;
25
- if ( ! stderrUpdate . includes ( errorText ) ) {
26
- throw new Error ( 'ng update expected to show npm version error .' ) ;
33
+ // Ensure `ng update` shows npm warning
34
+ const { stderr : stderrUpdate2 } = await ng ( 'update' ) ;
35
+ if ( ! stderrUpdate2 . includes ( warningText ) ) {
36
+ throw new Error ( 'ng update expected to show npm version warning .' ) ;
27
37
}
28
38
29
- // Ensure `ng new` exits and shows npm error
39
+ // Ensure `ng build` executes successfully
40
+ const { stderr : stderrBuild } = await ng ( 'build' ) ;
41
+ if ( stderrBuild . includes ( warningText ) ) {
42
+ throw new Error ( 'ng build expected to not show npm version warning.' ) ;
43
+ }
44
+
45
+ // Ensure `ng new` shows npm warning
30
46
// Must be outside the project for `ng new`
31
47
process . chdir ( '..' ) ;
32
48
const { message : stderrNew } = await expectToFail ( ( ) => ng ( 'new' ) ) ;
33
- if ( ! stderrNew . includes ( errorText ) ) {
34
- throw new Error ( 'ng new expected to show npm version error.' ) ;
49
+ if ( ! stderrNew . includes ( warningText ) ) {
50
+ throw new Error ( 'ng new expected to show npm version warning.' ) ;
51
+ }
52
+
53
+ // Ensure `ng new --package-manager=npm` shows npm warning
54
+ const { message : stderrNewNpm } = await expectToFail ( ( ) => ng ( 'new' , '--package-manager=npm' ) ) ;
55
+ if ( ! stderrNewNpm . includes ( warningText ) ) {
56
+ throw new Error ( 'ng new expected to show npm version warning.' ) ;
57
+ }
58
+
59
+ // Ensure `ng new --skip-install` executes successfully
60
+ const { stderr : stderrNewSkipInstall } = await ng ( 'new' , 'npm-seven-skip' , '--skip-install' ) ;
61
+ if ( stderrNewSkipInstall . includes ( warningText ) ) {
62
+ throw new Error ( 'ng new --skip-install expected to not show npm version warning.' ) ;
63
+ }
64
+
65
+ // Ensure `ng new --package-manager=yarn` executes successfully
66
+ const { stderr : stderrNewYarn } = await ng ( 'new' , 'npm-seven-yarn' , '--package-manager=yarn' ) ;
67
+ if ( stderrNewYarn . includes ( warningText ) ) {
68
+ throw new Error ( 'ng new --package-manager=yarn expected to not show npm version warning.' ) ;
35
69
}
36
70
} finally {
71
+ // Cleanup extra test projects
72
+ await rimraf ( 'npm-seven-skip' ) ;
73
+ await rimraf ( 'npm-seven-yarn' ) ;
74
+
37
75
// Change directory back
38
76
process . chdir ( currentDirectory ) ;
39
77
0 commit comments