Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 771bccc

Browse files
petebacondarwinIgorMinar
authored andcommitted
chore(clean-shrinkwrap): add a utility to clean up the shrinkwrap file
This is to deal with npm/npm#3581 See the previous commit for more info. Closes #6672
1 parent c794b96 commit 771bccc

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

npm-shrinkwrap.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"dgeni-packages": "^0.7.0",
5555
"gulp-jshint": "~1.4.2",
5656
"jshint-stylish": "~0.1.5",
57-
"node-html-encoder": "0.0.2"
57+
"node-html-encoder": "0.0.2",
58+
"sorted-object": "^1.0.0"
5859
},
5960
"licenses": [
6061
{

scripts/clean-shrinkwrap.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* this script is just a temporary solution to deal with the issue of npm outputting the npm
5+
* shrinkwrap file in an unstable manner.
6+
*
7+
* See: https://github.com/npm/npm/issues/3581
8+
*/
9+
10+
var _ = require('lodash');
11+
var sorted = require('sorted-object');
12+
var fs = require('fs');
13+
14+
15+
function cleanModule(module, name) {
16+
17+
// keep `from` and `resolve` properties for git dependencies, delete otherwise
18+
if (!(module.resolved && module.resolved.match(/^git:\/\//))) {
19+
delete module.from;
20+
delete module.resolved;
21+
}
22+
23+
if (name === 'chokidar') {
24+
if (module.version === '0.8.1') {
25+
delete module.dependencies;
26+
} else {
27+
throw new Error("Unfamiliar chokidar version (v" + module.version +
28+
") , please check status of https://github.com/paulmillr/chokidar/pull/106");
29+
}
30+
}
31+
32+
_.forEach(module.dependencies, function(mod, name) {
33+
cleanModule(mod, name);
34+
});
35+
}
36+
37+
38+
console.log('Reading npm-shrinkwrap.json');
39+
var shrinkwrap = require('./../npm-shrinkwrap.json');
40+
41+
console.log('Cleaning shrinkwrap object');
42+
cleanModule(shrinkwrap, shrinkwrap.name);
43+
44+
console.log('Writing cleaned npm-shrinkwrap.json');
45+
fs.writeFileSync('./npm-shrinkwrap.json', JSON.stringify(sorted(shrinkwrap), null, 2) + "\n");

0 commit comments

Comments
 (0)