forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean-shrinkwrap.js
executable file
·43 lines (34 loc) · 1.27 KB
/
clean-shrinkwrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* 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
*/
const fs = require('fs');
const path = require('path');
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;
}
if (moduleRecord.dependencies) {
Object.keys(moduleRecord.dependencies)
.forEach((name) => cleanModule(moduleRecord.dependencies[name]));
}
}
// console.log('Reading npm-shrinkwrap.json');
const shrinkwrap = require('../../npm-shrinkwrap.json');
// console.log('Cleaning shrinkwrap object');
cleanModule(shrinkwrap);
const cleanShrinkwrapPath = path.join(__dirname, '..', '..', 'npm-shrinkwrap.clean.json');
console.log('writing npm-shrinkwrap.clean.json');
fs.writeFileSync(cleanShrinkwrapPath, JSON.stringify(shrinkwrap, null, 2) + '\n');