Skip to content

Commit 175dbce

Browse files
gkalpakIgorMinar
authored andcommitted
build: check yarn version in check-environment (angular#14499)
As discussed in angular#14382 (comment).
1 parent e8a2744 commit 175dbce

File tree

5 files changed

+63
-38
lines changed

5 files changed

+63
-38
lines changed

aio/gulpfile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
// NOTE: we are getting the value from the parent `angular/angular` package.json not the `/aio` one.
1414
const engines = require('../package.json').engines;
1515
require('../tools/check-environment')({
16+
requiredNodeVersion: engines.node,
1617
requiredNpmVersion: engines.npm,
17-
requiredNodeVersion: engines.node
18+
requiredYarnVersion: engines.yarn
1819
});
1920

2021
const gulp = require('gulp');
@@ -32,3 +33,4 @@ gulp.task('doc-gen-test', loadTask('docs', 'test'));
3233
gulp.task('docs-app', loadTask('docs-app'));
3334
gulp.task('docs-app-test', () => {});
3435
gulp.task('docs-test', ['doc-gen-test', 'docs-app-test']);
36+
gulp.task('check-env', () => { /* this is a noop because the env test ran already above */ });

aio/package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
"license": "MIT",
88
"angular-cli": {},
99
"scripts": {
10-
"ng": "ng",
11-
"start": "ng serve",
12-
"build": "ng build",
13-
"test": "ng test",
14-
"lint": "ng lint",
10+
"ng": "yarn run check-env && ng",
11+
"start": "yarn run check-env && ng serve",
12+
"build": "yarn run check-env && ng build",
13+
"test": "yarn run check-env && ng test",
14+
"lint": "yarn run check-env && ng lint",
1515
"pree2e": "webdriver-manager update --standalone false --gecko false",
16-
"e2e": "ng e2e --no-webdriver-update",
16+
"e2e": "yarn run check-env && ng e2e --no-webdriver-update",
1717
"deploy-staging": "firebase use staging --token \"$FIREBASE_TOKEN\" && yarn run ~~deploy",
18-
"pre~~deploy": "ng build --prod",
19-
"~~deploy": "firebase deploy --message \"Commit: $TRAVIS_COMMIT\" --non-interactive --token \"$FIREBASE_TOKEN\""
18+
"pre~~deploy": "yarn run check-env && ng build --prod",
19+
"~~deploy": "firebase deploy --message \"Commit: $TRAVIS_COMMIT\" --non-interactive --token \"$FIREBASE_TOKEN\"",
20+
"check-env": "gulp check-env"
2021
},
2122
"private": true,
2223
"dependencies": {

gulpfile.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
// THIS CHECK SHOULD BE THE FIRST THING IN THIS FILE
1313
// This is to ensure that we catch env issues before we error while requiring other dependencies.
1414
const engines = require('./package.json').engines;
15-
require('./tools/check-environment')(
16-
{requiredNpmVersion: engines.npm, requiredNodeVersion: engines.node});
15+
require('./tools/check-environment')({
16+
requiredNodeVersion: engines.node,
17+
requiredNpmVersion: engines.npm,
18+
requiredYarnVersion: engines.yarn
19+
});
1720

1821
const gulp = require('gulp');
1922

@@ -37,3 +40,4 @@ gulp.task('check-cycle', loadTask('check-cycle'));
3740
gulp.task('serve', loadTask('serve', 'default'));
3841
gulp.task('serve-examples', loadTask('serve', 'examples'));
3942
gulp.task('changelog', loadTask('changelog'));
43+
gulp.task('check-env', () => {/* this is a noop because the env test ran already above */});

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
"bugs": "https://github.com/angular/angular/issues",
99
"license": "MIT",
1010
"engines": {
11-
"node": ">= 6.9.5 < 7.0.0",
12-
"npm": ">=3.10.7 <4.0.0"
11+
"node": ">=6.9.5 <7.0.0",
12+
"npm": ">=3.10.7 <4.0.0",
13+
"yarn": ">=0.19.1 <0.21.0"
1314
},
1415
"repository": {
1516
"type": "git",
1617
"url": "https://github.com/angular/angular.git"
1718
},
1819
"scripts": {
19-
"postinstall": "node tools/npm/copy-npm-shrinkwrap && webdriver-manager update"
20+
"postinstall": "node tools/npm/copy-npm-shrinkwrap && webdriver-manager update",
21+
"check-env": "gulp check-env"
2022
},
2123
"dependencies": {
2224
"core-js": "^2.4.1",

tools/check-environment.js

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,46 @@ try {
5454
}
5555

5656
function checkEnvironment(reqs) {
57-
exec('npm --version', function(e, stdout) {
58-
var foundNpmVersion = semver.clean(stdout);
59-
var foundNodeVersion = process.version;
60-
var issues = [];
61-
62-
63-
if (!semver.satisfies(foundNodeVersion, reqs.requiredNodeVersion)) {
64-
issues.push(
65-
'You are running unsupported node version. Found: ' + foundNodeVersion + ' Expected: ' +
66-
reqs.requiredNodeVersion + '. Use nvm to update your node version.');
67-
}
68-
69-
if (!semver.satisfies(foundNpmVersion, reqs.requiredNpmVersion)) {
70-
issues.push(
71-
'You are running unsupported npm version. Found: ' + foundNpmVersion + ' Expected: ' +
72-
reqs.requiredNpmVersion + '. Run: npm update -g npm');
73-
}
74-
75-
if (!checkNodeModules()) {
76-
issues.push(
77-
'Your node_modules directory is stale or out of sync with npm-shrinkwrap.json. Run: npm install');
78-
}
79-
80-
printWarning(issues);
57+
exec('npm --version', function(npmErr, npmStdout) {
58+
exec('yarn --version', function(yarnErr, yarnStdout) {
59+
var foundNodeVersion = process.version;
60+
var foundNpmVersion = semver.clean(npmStdout);
61+
var foundYarnVersion = !yarnErr && semver.clean(yarnStdout);
62+
var issues = [];
63+
64+
65+
if (!semver.satisfies(foundNodeVersion, reqs.requiredNodeVersion)) {
66+
issues.push(
67+
'You are running unsupported node version. Found: ' + foundNodeVersion + ' Expected: ' +
68+
reqs.requiredNodeVersion + '. Use nvm to update your node version.');
69+
}
70+
71+
if (!semver.satisfies(foundNpmVersion, reqs.requiredNpmVersion)) {
72+
issues.push(
73+
'You are running unsupported npm version. Found: ' + foundNpmVersion + ' Expected: ' +
74+
reqs.requiredNpmVersion + '. Run: npm update -g npm');
75+
}
76+
77+
if (yarnErr) {
78+
issues.push(
79+
'You don\'t have yarn globally installed. This is required if you want to work on ' +
80+
'certain areas, such as `aio/` and `integration/`. Installation instructions: ' +
81+
'https://yarnpkg.com/lang/en/docs/install/');
82+
} else if (!semver.satisfies(foundYarnVersion, reqs.requiredYarnVersion)) {
83+
issues.push(
84+
'You are running unsupported yarn version. Found: ' + foundYarnVersion + ' Expected: ' +
85+
reqs.requiredYarnVersion + '. This is required if you want to work on ' +
86+
'certain areas, such as `aio/` and `integration/`. See: ' +
87+
'https://yarnpkg.com/lang/en/docs/install/');
88+
}
89+
90+
if (!checkNodeModules()) {
91+
issues.push(
92+
'Your node_modules directory is stale or out of sync with npm-shrinkwrap.json. Run: npm install');
93+
}
94+
95+
printWarning(issues);
96+
})
8197
});
8298
}
8399

0 commit comments

Comments
 (0)