Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f04fcdf

Browse files
chore(grunt): check node, yarn and grunt-cli versions
If global versions of node, yarn or grunt-cli don't match what we expect then blow up.
1 parent 5dd3a35 commit f04fcdf

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

Gruntfile.js

+54-10
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,63 @@ var path = require('path');
1010
var e2e = require('./test/e2e/tools');
1111

1212
var semver = require('semver');
13-
var fs = require('fs');
13+
var exec = require('shelljs').exec;
14+
var pkg = require(__dirname + '/package.json');
1415

15-
var useNodeVersion = fs.readFileSync('.nvmrc', 'utf8');
16-
if (!semver.satisfies(process.version, useNodeVersion)) {
17-
throw new Error('Invalid node version; please use node v' + useNodeVersion);
16+
// Node.js version checks
17+
if (!semver.satisfies(process.version, pkg.engines.node)) {
18+
reportOrFail('Invalid node version (' + process.version + '). ' +
19+
'Please use a version that satisfies ' + pkg.engines.node);
1820
}
1921

22+
// Yarn version checks
23+
var expectedYarnVersion = pkg.engines.yarn;
24+
var currentYarnVersion = exec('yarn --version', {silent: true}).stdout.trim();
25+
if (!semver.satisfies(currentYarnVersion, expectedYarnVersion)) {
26+
reportOrFail('Invalid yarn version (' + currentYarnVersion + '). ' +
27+
'Please use a version that satisfies ' + expectedYarnVersion);
28+
}
29+
30+
// Grunt CLI version checks
31+
var expectedGruntVersion = pkg.engines.grunt;
32+
var currentGruntVersions = exec('grunt --version', {silent: true}).stdout;
33+
var match = /^grunt-cli v(.+)$/m.exec(currentGruntVersions);
34+
if (!match) {
35+
reportOrFail('Unable to compute the current grunt-cli version. We found:\n' +
36+
currentGruntVersions);
37+
} else {
38+
if (!semver.satisfies(match[1], expectedGruntVersion)) {
39+
reportOrFail('Invalid grunt-cli version (' + match[1] + '). ' +
40+
'Please use a version that satisfies ' + expectedGruntVersion);
41+
}
42+
}
43+
44+
// Ensure Node.js dependencies have been installed
45+
if (!process.env.TRAVIS && !process.env.JENKINS_HOME) {
46+
var yarnOutput = exec('yarn install');
47+
if (yarnOutput.code !== 0) {
48+
throw new Error('Yarn install failed: ' + yarnOutput.stderr);
49+
}
50+
}
51+
52+
2053
module.exports = function(grunt) {
21-
//grunt plugins
54+
55+
// this loads all the node_modules that start with `grunt-` as plugins
2256
require('load-grunt-tasks')(grunt);
2357

58+
// load additional grunt tasks
2459
grunt.loadTasks('lib/grunt');
2560
grunt.loadNpmTasks('angular-benchpress');
2661

62+
// compute version related info for this build
2763
var NG_VERSION = versionInfo.currentVersion;
2864
NG_VERSION.cdn = versionInfo.cdnVersion;
2965
var dist = 'angular-' + NG_VERSION.full;
3066

3167
if (versionInfo.cdnVersion == null) {
32-
throw new Error('Unable to read CDN version, are you offline or has the CDN not been properly pushed?');
68+
throw new Error('Unable to read CDN version, are you offline or has the CDN not been properly pushed?\n' +
69+
'Perhaps you want to set the NG1_BUILD_NO_REMOTE_VERSION_REQUESTS environment variable?');
3370
}
3471

3572
//config
@@ -321,10 +358,6 @@ module.exports = function(grunt) {
321358
}
322359
});
323360

324-
if (!process.env.TRAVIS) {
325-
grunt.task.run('shell:install-node-dependencies');
326-
}
327-
328361
//alias tasks
329362
grunt.registerTask('test', 'Run unit, docs and e2e tests with Karma', ['eslint', 'package', 'test:unit', 'test:promises-aplus', 'tests:docs', 'test:protractor']);
330363
grunt.registerTask('test:jqlite', 'Run the unit tests with Karma' , ['tests:jqlite']);
@@ -346,3 +379,14 @@ module.exports = function(grunt) {
346379
grunt.registerTask('ci-checks', ['ddescribe-iit', 'merge-conflict', 'eslint']);
347380
grunt.registerTask('default', ['package']);
348381
};
382+
383+
384+
function reportOrFail(message) {
385+
if (process.env.TRAVIS || process.env.JENKINS_HOME) {
386+
throw new Error(message);
387+
} else {
388+
console.log('===============================================================================');
389+
console.log(message);
390+
console.log('===============================================================================');
391+
}
392+
}

0 commit comments

Comments
 (0)