chore(npm): clean up clean-shrinkwrap script

This commit is contained in:
Joao Dias 2016-10-29 18:40:44 +02:00 committed by vsavkin
parent e0ad413a8e
commit 0936ceeab4
1 changed files with 11 additions and 10 deletions

View File

@ -14,29 +14,30 @@
* See: https://github.com/npm/npm/issues/3581
*/
var _ = require('lodash');
var sorted = require('sorted-object');
var fs = require('fs');
var path = require('path');
const fs = require('fs');
const path = require('path');
function cleanModule(moduleRecord, name) {
function cleanModule(moduleRecord) {
// keep `resolve` properties for git dependencies, delete otherwise
delete moduleRecord.from;
if (!(moduleRecord.resolved && moduleRecord.resolved.match(/^git(\+[a-z]+)?:\/\//))) {
delete moduleRecord.resolved;
}
_.forEach(moduleRecord.dependencies, function(mod, name) { cleanModule(mod, name); });
if (moduleRecord.dependencies) {
Object.keys(moduleRecord.dependencies)
.forEach((name) => cleanModule(moduleRecord.dependencies[name]));
}
}
// console.log('Reading npm-shrinkwrap.json');
var shrinkwrap = require('../../npm-shrinkwrap.json');
const shrinkwrap = require('../../npm-shrinkwrap.json');
// console.log('Cleaning shrinkwrap object');
cleanModule(shrinkwrap, shrinkwrap.name);
cleanModule(shrinkwrap);
var cleanShrinkwrapPath = path.join(__dirname, '..', '..', 'npm-shrinkwrap.clean.json');
const cleanShrinkwrapPath = path.join(__dirname, '..', '..', 'npm-shrinkwrap.clean.json');
console.log('writing npm-shrinkwrap.clean.json');
fs.writeFileSync(cleanShrinkwrapPath, JSON.stringify(sorted(shrinkwrap), null, 2) + '\n');
fs.writeFileSync(cleanShrinkwrapPath, JSON.stringify(shrinkwrap, null, 2) + '\n');