Permalink
Browse files

Merge pull request #12315 from twbs/use-shrinkwrap

Do npm caching based on npm-shrinkwrap.canonical.json
  • Loading branch information...
cvrebert committed Jan 27, 2014
2 parents 16fd8cd + 5a3f1a9 commit 50ad304bb52b344828352e888b6f8ddc042ba176
Showing with 53 additions and 14 deletions.
  1. +2 −2 .travis.yml
  2. +19 −11 Gruntfile.js
  3. +2 −0 package.json
  4. +1 −1 test-infra/README.md
  5. +1 −0 test-infra/npm-shrinkwrap.canonical.json
  6. +24 −0 test-infra/shrinkwrap.js
  7. +4 −0 test-infra/uncached-npm-install.sh
View
@@ -7,10 +7,10 @@ before_install:
- if [ "$TWBS_TEST" = validate-html ]; then echo "ruby=$(basename $(rvm gemdir)) jekyll=$JEKYLL_VERSION" > pseudo_Gemfile.lock; fi
install:
- time npm install -g grunt-cli
- - time ./test-infra/s3_cache.py download 'node.js packages' package.json ./node_modules || time npm install
+ - time ./test-infra/s3_cache.py download 'npm packages' test-infra/npm-shrinkwrap.canonical.json ./node_modules || time ./test-infra/uncached-npm-install.sh
- if [ "$TWBS_TEST" = validate-html ]; then time ./test-infra/s3_cache.py download rubygems pseudo_Gemfile.lock $(rvm gemdir) || gem install -N jekyll -v $JEKYLL_VERSION; fi
after_script:
- - if [ "$TWBS_TEST" = core ]; then time ./test-infra/s3_cache.py upload 'node.js packages' package.json ./node_modules; fi
+ - if [ "$TWBS_TEST" = core ]; then time ./test-infra/s3_cache.py upload 'npm packages' test-infra/npm-shrinkwrap.canonical.json ./node_modules; fi
- if [ "$TWBS_TEST" = validate-html ]; then time ./test-infra/s3_cache.py upload rubygems pseudo_Gemfile.lock $(rvm gemdir); fi
env:
global:
View
@@ -21,6 +21,7 @@ module.exports = function (grunt) {
var generateGlyphiconsData = require('./docs/grunt/bs-glyphicons-data-generator.js');
var BsLessdocParser = require('./docs/grunt/bs-lessdoc-parser.js');
var generateRawFilesJs = require('./docs/grunt/bs-raw-files-generator.js');
+ var updateShrinkwrap = require('./test-infra/shrinkwrap.js');
// Project configuration.
grunt.initConfig({
@@ -49,8 +50,8 @@ module.exports = function (grunt) {
options: {
jshintrc: 'js/.jshintrc'
},
- gruntfile: {
- src: 'Gruntfile.js'
+ grunt: {
+ src: ['Gruntfile.js', 'docs/grunt/*.js', 'test-infra/shrinkwrap.js']
},
src: {
src: 'js/*.js'
@@ -60,18 +61,15 @@ module.exports = function (grunt) {
},
assets: {
src: ['docs/assets/js/application.js', 'docs/assets/js/customizer.js']
- },
- docsGrunt: {
- src: 'docs/grunt/*.js'
}
},
jscs: {
options: {
config: 'js/.jscs.json',
},
- gruntfile: {
- src: 'Gruntfile.js'
+ grunt: {
+ src: ['Gruntfile.js', 'docs/grunt/*.js', 'test-infra/shrinkwrap.js']
},
src: {
src: 'js/*.js'
@@ -81,9 +79,6 @@ module.exports = function (grunt) {
},
assets: {
src: ['docs/assets/js/application.js', 'docs/assets/js/customizer.js']
- },
- docsGrunt: {
- src: 'docs/grunt/*.js'
}
},
@@ -349,6 +344,15 @@ module.exports = function (grunt) {
browsers: grunt.file.readYAML('test-infra/sauce_browsers.yml')
}
}
+ },
+
+ exec: {
+ npmUpdate: {
+ command: 'npm update'
+ },
+ npmShrinkWrap: {
+ command: 'npm shrinkwrap --dev'
+ }
}
});
@@ -398,7 +402,7 @@ module.exports = function (grunt) {
grunt.registerTask('dist', ['clean', 'dist-css', 'copy:fonts', 'dist-docs', 'dist-js']);
// Default task.
- grunt.registerTask('default', ['test', 'dist', 'build-glyphicons-data', 'build-customizer']);
+ grunt.registerTask('default', ['test', 'dist', 'build-glyphicons-data', 'build-customizer', 'update-shrinkwrap']);
// Version numbering task.
// grunt change-version-number --oldver=A.B.C --newver=X.Y.Z
@@ -414,4 +418,8 @@ module.exports = function (grunt) {
var banner = grunt.template.process('<%= banner %>');
generateRawFilesJs(banner);
});
+
+ // Task for updating the npm packages used by the Travis build.
+ grunt.registerTask('update-shrinkwrap', ['exec:npmUpdate', 'exec:npmShrinkWrap', '_update-shrinkwrap']);
+ grunt.registerTask('_update-shrinkwrap', function () { updateShrinkwrap.call(this, grunt); });
};
View
@@ -27,6 +27,7 @@
"devDependencies": {
"browserstack-runner": "~0.0.15",
"btoa": "~1.1.1",
+ "canonical-json": "~0.0.3",
"grunt": "~0.4.2",
"grunt-banner": "~0.2.0",
"grunt-contrib-clean": "~0.5.0",
@@ -42,6 +43,7 @@
"grunt-contrib-uglify": "~0.3.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-csscomb": "~2.0.1",
+ "grunt-exec": "0.4.3",
"grunt-html-validation": "~0.1.13",
"grunt-jekyll": "~0.4.1",
"grunt-jscs-checker": "~0.3.0",
View
@@ -15,7 +15,7 @@ Similar to git, `s3_cache.py` makes the assumption that [SHA-256 will effectivel
### For Bootstrap specifically
`s3_cache.py` is used to cache the npm packages that our Grunt tasks depend on and the RubyGems that Jekyll depends on. (Jekyll is needed to compile our docs to HTML so that we can run them thru an HTML5 validator.)
-For npm, the `node_modules` directory is cached based on our `package.json` file.
+For npm, the `node_modules` directory is cached based on our `npm-shrinkwrap.canonical.json` file.
For RubyGems, the `gemdir` of the current RVM-selected Ruby is cached based on the `pseudo_Gemfile.lock` file generated by our Travis build script.
`pseudo_Gemfile.lock` contains the versions of Ruby and Jekyll that we're using (read our `.travis.yml` for details).

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,24 @@
+/* jshint node: true */
+
+/*
+This Grunt task updates the npm-shrinkwrap.canonical.json file that's used as the key for Bootstrap's npm packages cache.
+This task should be run and the updated file should be committed whenever Bootstrap's dependencies change.
+*/
+
+var canonicallyJsonStringify = require('canonical-json');
+var NON_CANONICAL_FILE = 'npm-shrinkwrap.json';
+var DEST_FILE = 'test-infra/npm-shrinkwrap.canonical.json';
+
+
+function updateShrinkwrap(grunt) {
+ // Assumption: Non-canonical shrinkwrap already generated by prerequisite Grunt task
+ var shrinkwrapData = grunt.file.readJSON(NON_CANONICAL_FILE);
+ grunt.log.writeln('Deleting ' + NON_CANONICAL_FILE.cyan + '...');
+ grunt.file.delete(NON_CANONICAL_FILE);
+ // Output as Canonical JSON in correct location
+ grunt.file.write(DEST_FILE, canonicallyJsonStringify(shrinkwrapData));
+ grunt.log.writeln('File ' + DEST_FILE.cyan + ' updated.');
+}
+
+
+module.exports = updateShrinkwrap;
@@ -0,0 +1,4 @@
+#!/bin/bash
+cp test-infra/npm-shrinkwrap.canonical.json npm-shrinkwrap.json
+npm install
+rm npm-shrinkwrap.json

0 comments on commit 50ad304

Please sign in to comment.