From dd3587a8c1977a1453063f42bb0dc511e67487a4 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 13 Mar 2014 18:30:17 +0000 Subject: chore(clean-shrinkwrap): add a utility to clean up the shrinkwrap file This is to deal with https://github.com/npm/npm/issues/3581 See the previous commit for more info. Closes #6672 --- npm-shrinkwrap.json | 3 +++ package.json | 3 ++- scripts/clean-shrinkwrap.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100755 scripts/clean-shrinkwrap.js diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 2af6f725..a72db7c9 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -2713,6 +2713,9 @@ "shelljs": { "version": "0.2.6" }, + "sorted-object": { + "version": "1.0.0" + }, "winston": { "version": "0.7.2", "dependencies": { diff --git a/package.json b/package.json index 093c4d82..f7f3adc7 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,8 @@ "dgeni-packages": "^0.7.0", "gulp-jshint": "~1.4.2", "jshint-stylish": "~0.1.5", - "node-html-encoder": "0.0.2" + "node-html-encoder": "0.0.2", + "sorted-object": "^1.0.0" }, "licenses": [ { diff --git a/scripts/clean-shrinkwrap.js b/scripts/clean-shrinkwrap.js new file mode 100755 index 00000000..f3d6ebe5 --- /dev/null +++ b/scripts/clean-shrinkwrap.js @@ -0,0 +1,45 @@ +#!/usr/bin/env node + +/** + * this script is just a temporary solution to deal with the issue of npm outputting the npm + * shrinkwrap file in an unstable manner. + * + * See: https://github.com/npm/npm/issues/3581 + */ + +var _ = require('lodash'); +var sorted = require('sorted-object'); +var fs = require('fs'); + + +function cleanModule(module, name) { + + // keep `from` and `resolve` properties for git dependencies, delete otherwise + if (!(module.resolved && module.resolved.match(/^git:\/\//))) { + delete module.from; + delete module.resolved; + } + + if (name === 'chokidar') { + if (module.version === '0.8.1') { + delete module.dependencies; + } else { + throw new Error("Unfamiliar chokidar version (v" + module.version + + ") , please check status of https://github.com/paulmillr/chokidar/pull/106"); + } + } + + _.forEach(module.dependencies, function(mod, name) { + cleanModule(mod, name); + }); +} + + +console.log('Reading npm-shrinkwrap.json'); +var shrinkwrap = require('./../npm-shrinkwrap.json'); + +console.log('Cleaning shrinkwrap object'); +cleanModule(shrinkwrap, shrinkwrap.name); + +console.log('Writing cleaned npm-shrinkwrap.json'); +fs.writeFileSync('./npm-shrinkwrap.json', JSON.stringify(sorted(shrinkwrap), null, 2) + "\n"); -- cgit v1.2.3