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

Commit 250fcec

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 0b81a26 commit 250fcec

File tree

1 file changed

+58
-6
lines changed

1 file changed

+58
-6
lines changed

Gruntfile.js

+58-6
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,64 @@ var versionInfo = require('./lib/versions/version-info');
99
var path = require('path');
1010
var e2e = require('./test/e2e/tools');
1111

12+
var semver = require('semver');
13+
var exec = require('shelljs').exec;
14+
var pkg = require(__dirname + '/package.json');
15+
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);
20+
}
21+
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+
1253
module.exports = function(grunt) {
13-
//grunt plugins
54+
55+
// this loads all the node_modules that start with `grunt-` as plugins
1456
require('load-grunt-tasks')(grunt);
1557

58+
// load additional grunt tasks
1659
grunt.loadTasks('lib/grunt');
1760
grunt.loadNpmTasks('angular-benchpress');
1861

62+
// compute version related info for this build
1963
var NG_VERSION = versionInfo.currentVersion;
2064
NG_VERSION.cdn = versionInfo.cdnVersion;
2165
var dist = 'angular-' + NG_VERSION.full;
2266

2367
if (versionInfo.cdnVersion == null) {
24-
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?');
2570
}
2671

2772
//config
@@ -313,10 +358,6 @@ module.exports = function(grunt) {
313358
}
314359
});
315360

316-
if (!process.env.TRAVIS) {
317-
grunt.task.run('shell:install-node-dependencies');
318-
}
319-
320361
//alias tasks
321362
grunt.registerTask('test', 'Run unit, docs and e2e tests with Karma', ['eslint', 'package', 'test:unit', 'test:promises-aplus', 'tests:docs', 'test:protractor']);
322363
grunt.registerTask('test:jqlite', 'Run the unit tests with Karma' , ['tests:jqlite']);
@@ -338,3 +379,14 @@ module.exports = function(grunt) {
338379
grunt.registerTask('ci-checks', ['ddescribe-iit', 'merge-conflict', 'eslint']);
339380
grunt.registerTask('default', ['package']);
340381
};
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)