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

Switch to uber/npm-shrinkwrap for npm-shrinkwrap.json generation

Instead of our homegrown grunt/shrinkwrap.js
Fixes #13483.
New npm-shrinkwrap.json is human-readable but still in a consistent/stable format.
Should aid debugging, produce better diffs, and be less prone to merge conflicts
This commit is contained in:
Chris Rebert 2014-06-19 10:47:55 -07:00
parent d37b0ffa5f
commit 3c4ba2a08c
8 changed files with 3607 additions and 53 deletions

View file

@ -17,10 +17,10 @@ module.exports = function (grunt) {
var fs = require('fs');
var path = require('path');
var npmShrinkwrap = require('npm-shrinkwrap');
var generateGlyphiconsData = require('./grunt/bs-glyphicons-data-generator.js');
var BsLessdocParser = require('./grunt/bs-lessdoc-parser.js');
var generateRawFiles = require('./grunt/bs-raw-files-generator.js');
var updateShrinkwrap = require('./grunt/shrinkwrap.js');
// Project configuration.
grunt.initConfig({
@ -387,9 +387,6 @@ module.exports = function (grunt) {
exec: {
npmUpdate: {
command: 'npm update'
},
npmShrinkWrap: {
command: 'npm shrinkwrap --dev'
}
}
});
@ -463,7 +460,19 @@ module.exports = function (grunt) {
generateRawFiles(grunt, 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); });
// Task for updating the cached npm packages used by the Travis build (which are controlled by test-infra/npm-shrinkwrap.json).
// This task should be run and the updated file should be committed whenever Bootstrap's dependencies change.
grunt.registerTask('update-shrinkwrap', ['exec:npmUpdate', '_update-shrinkwrap']);
grunt.registerTask('_update-shrinkwrap', function () {
var done = this.async();
npmShrinkwrap({ dev: true, dirname: __dirname }, function (err) {
if (err) {
grunt.fail.warn(err)
}
var dest = 'test-infra/npm-shrinkwrap.json';
fs.renameSync('npm-shrinkwrap.json', dest);
grunt.log.writeln('File ' + dest.cyan + ' updated.');
done();
});
});
};

View file

@ -1,41 +0,0 @@
/*!
* Bootstrap Grunt task for generating npm-shrinkwrap.canonical.json
* http://getbootstrap.com
* Copyright 2014 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
/*
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.
*/
'use strict';
var canonicallyJsonStringify = require('canonical-json');
var NON_CANONICAL_FILE = 'npm-shrinkwrap.json';
var DEST_FILE = 'test-infra/npm-shrinkwrap.canonical.json';
function cleanup(shrinkwrap) {
// Remove `resolved` property to avoid irrelevant changes
// See https://github.com/npm/npm/issues/3581
if (typeof shrinkwrap === 'string') {
return shrinkwrap;
}
delete shrinkwrap.resolved;
for (var key in shrinkwrap) {
shrinkwrap[key] = cleanup(shrinkwrap[key]);
}
return shrinkwrap;
}
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(cleanup(shrinkwrapData)));
grunt.log.writeln('File ' + DEST_FILE.cyan + ' updated.');
}
module.exports = updateShrinkwrap;

View file

@ -31,7 +31,6 @@
},
"devDependencies": {
"btoa": "~1.1.2",
"canonical-json": "~0.0.4",
"glob": "~4.0.2",
"grunt": "~0.4.5",
"grunt-autoprefixer": "~0.7.5",
@ -57,6 +56,7 @@
"grunt-sed": "~0.1.1",
"load-grunt-tasks": "~0.5.0",
"markdown": "~0.5.0",
"npm-shrinkwrap": "~3.1.3",
"time-grunt": "~0.3.2"
},
"engines": {

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 `npm-shrinkwrap.canonical.json` file.
For npm, the `node_modules` directory is cached based on our `npm-shrinkwrap.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).

View file

@ -1,6 +1,6 @@
{
"npm-modules": {
"key": "./npm-shrinkwrap.canonical.json",
"key": "./npm-shrinkwrap.json",
"cache": "../node_modules",
"generate": "./uncached-npm-install.sh"
},

File diff suppressed because one or more lines are too long

3587
test-infra/npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
#!/bin/bash
set -e
cd .. # /bootstrap/
cp test-infra/npm-shrinkwrap.canonical.json npm-shrinkwrap.json
cp test-infra/npm-shrinkwrap.json npm-shrinkwrap.json
npm install
rm npm-shrinkwrap.json