build: check yarn version in check-environment (#14499)

As discussed in
https://github.com/angular/angular/pull/14382#discussion_r100620839.
This commit is contained in:
George Kalpakas 2017-02-23 06:55:25 +02:00 committed by Igor Minar
parent e8a27447c4
commit 175dbce354
5 changed files with 58 additions and 33 deletions

View File

@ -13,8 +13,9 @@
// NOTE: we are getting the value from the parent `angular/angular` package.json not the `/aio` one. // NOTE: we are getting the value from the parent `angular/angular` package.json not the `/aio` one.
const engines = require('../package.json').engines; const engines = require('../package.json').engines;
require('../tools/check-environment')({ require('../tools/check-environment')({
requiredNodeVersion: engines.node,
requiredNpmVersion: engines.npm, requiredNpmVersion: engines.npm,
requiredNodeVersion: engines.node requiredYarnVersion: engines.yarn
}); });
const gulp = require('gulp'); const gulp = require('gulp');
@ -32,3 +33,4 @@ gulp.task('doc-gen-test', loadTask('docs', 'test'));
gulp.task('docs-app', loadTask('docs-app')); gulp.task('docs-app', loadTask('docs-app'));
gulp.task('docs-app-test', () => {}); gulp.task('docs-app-test', () => {});
gulp.task('docs-test', ['doc-gen-test', 'docs-app-test']); gulp.task('docs-test', ['doc-gen-test', 'docs-app-test']);
gulp.task('check-env', () => { /* this is a noop because the env test ran already above */ });

View File

@ -7,16 +7,17 @@
"license": "MIT", "license": "MIT",
"angular-cli": {}, "angular-cli": {},
"scripts": { "scripts": {
"ng": "ng", "ng": "yarn run check-env && ng",
"start": "ng serve", "start": "yarn run check-env && ng serve",
"build": "ng build", "build": "yarn run check-env && ng build",
"test": "ng test", "test": "yarn run check-env && ng test",
"lint": "ng lint", "lint": "yarn run check-env && ng lint",
"pree2e": "webdriver-manager update --standalone false --gecko false", "pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "ng e2e --no-webdriver-update", "e2e": "yarn run check-env && ng e2e --no-webdriver-update",
"deploy-staging": "firebase use staging --token \"$FIREBASE_TOKEN\" && yarn run ~~deploy", "deploy-staging": "firebase use staging --token \"$FIREBASE_TOKEN\" && yarn run ~~deploy",
"pre~~deploy": "ng build --prod", "pre~~deploy": "yarn run check-env && ng build --prod",
"~~deploy": "firebase deploy --message \"Commit: $TRAVIS_COMMIT\" --non-interactive --token \"$FIREBASE_TOKEN\"" "~~deploy": "firebase deploy --message \"Commit: $TRAVIS_COMMIT\" --non-interactive --token \"$FIREBASE_TOKEN\"",
"check-env": "gulp check-env"
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {

View File

@ -12,8 +12,11 @@
// THIS CHECK SHOULD BE THE FIRST THING IN THIS FILE // THIS CHECK SHOULD BE THE FIRST THING IN THIS FILE
// This is to ensure that we catch env issues before we error while requiring other dependencies. // This is to ensure that we catch env issues before we error while requiring other dependencies.
const engines = require('./package.json').engines; const engines = require('./package.json').engines;
require('./tools/check-environment')( require('./tools/check-environment')({
{requiredNpmVersion: engines.npm, requiredNodeVersion: engines.node}); requiredNodeVersion: engines.node,
requiredNpmVersion: engines.npm,
requiredYarnVersion: engines.yarn
});
const gulp = require('gulp'); const gulp = require('gulp');
@ -37,3 +40,4 @@ gulp.task('check-cycle', loadTask('check-cycle'));
gulp.task('serve', loadTask('serve', 'default')); gulp.task('serve', loadTask('serve', 'default'));
gulp.task('serve-examples', loadTask('serve', 'examples')); gulp.task('serve-examples', loadTask('serve', 'examples'));
gulp.task('changelog', loadTask('changelog')); gulp.task('changelog', loadTask('changelog'));
gulp.task('check-env', () => {/* this is a noop because the env test ran already above */});

View File

@ -8,15 +8,17 @@
"bugs": "https://github.com/angular/angular/issues", "bugs": "https://github.com/angular/angular/issues",
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">= 6.9.5 < 7.0.0", "node": ">=6.9.5 <7.0.0",
"npm": ">=3.10.7 <4.0.0" "npm": ">=3.10.7 <4.0.0",
"yarn": ">=0.19.1 <0.21.0"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/angular/angular.git" "url": "https://github.com/angular/angular.git"
}, },
"scripts": { "scripts": {
"postinstall": "node tools/npm/copy-npm-shrinkwrap && webdriver-manager update" "postinstall": "node tools/npm/copy-npm-shrinkwrap && webdriver-manager update",
"check-env": "gulp check-env"
}, },
"dependencies": { "dependencies": {
"core-js": "^2.4.1", "core-js": "^2.4.1",

View File

@ -54,30 +54,46 @@ try {
} }
function checkEnvironment(reqs) { function checkEnvironment(reqs) {
exec('npm --version', function(e, stdout) { exec('npm --version', function(npmErr, npmStdout) {
var foundNpmVersion = semver.clean(stdout); exec('yarn --version', function(yarnErr, yarnStdout) {
var foundNodeVersion = process.version; var foundNodeVersion = process.version;
var issues = []; var foundNpmVersion = semver.clean(npmStdout);
var foundYarnVersion = !yarnErr && semver.clean(yarnStdout);
var issues = [];
if (!semver.satisfies(foundNodeVersion, reqs.requiredNodeVersion)) { if (!semver.satisfies(foundNodeVersion, reqs.requiredNodeVersion)) {
issues.push( issues.push(
'You are running unsupported node version. Found: ' + foundNodeVersion + ' Expected: ' + 'You are running unsupported node version. Found: ' + foundNodeVersion + ' Expected: ' +
reqs.requiredNodeVersion + '. Use nvm to update your node version.'); reqs.requiredNodeVersion + '. Use nvm to update your node version.');
} }
if (!semver.satisfies(foundNpmVersion, reqs.requiredNpmVersion)) { if (!semver.satisfies(foundNpmVersion, reqs.requiredNpmVersion)) {
issues.push( issues.push(
'You are running unsupported npm version. Found: ' + foundNpmVersion + ' Expected: ' + 'You are running unsupported npm version. Found: ' + foundNpmVersion + ' Expected: ' +
reqs.requiredNpmVersion + '. Run: npm update -g npm'); reqs.requiredNpmVersion + '. Run: npm update -g npm');
} }
if (!checkNodeModules()) { if (yarnErr) {
issues.push( issues.push(
'Your node_modules directory is stale or out of sync with npm-shrinkwrap.json. Run: npm install'); 'You don\'t have yarn globally installed. This is required if you want to work on ' +
} 'certain areas, such as `aio/` and `integration/`. Installation instructions: ' +
'https://yarnpkg.com/lang/en/docs/install/');
} else if (!semver.satisfies(foundYarnVersion, reqs.requiredYarnVersion)) {
issues.push(
'You are running unsupported yarn version. Found: ' + foundYarnVersion + ' Expected: ' +
reqs.requiredYarnVersion + '. This is required if you want to work on ' +
'certain areas, such as `aio/` and `integration/`. See: ' +
'https://yarnpkg.com/lang/en/docs/install/');
}
printWarning(issues); if (!checkNodeModules()) {
issues.push(
'Your node_modules directory is stale or out of sync with npm-shrinkwrap.json. Run: npm install');
}
printWarning(issues);
})
}); });
} }