1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00

Merge pull request #12315 from twbs/use-shrinkwrap

Do npm caching based on npm-shrinkwrap.canonical.json
This commit is contained in:
Chris Rebert 2014-01-26 20:46:14 -08:00
commit 50ad304bb5
7 changed files with 53 additions and 14 deletions

View file

@ -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 file

@ -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,9 +61,6 @@ module.exports = function (grunt) {
},
assets: {
src: ['docs/assets/js/application.js', 'docs/assets/js/customizer.js']
},
docsGrunt: {
src: 'docs/grunt/*.js'
}
},
@ -70,8 +68,8 @@ module.exports = function (grunt) {
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 file

@ -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 file

@ -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).

File diff suppressed because one or more lines are too long

24
test-infra/shrinkwrap.js Normal file
View file

@ -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;

View file

@ -0,0 +1,4 @@
#!/bin/bash
cp test-infra/npm-shrinkwrap.canonical.json npm-shrinkwrap.json
npm install
rm npm-shrinkwrap.json