-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
project.lock.json.js
62 lines (47 loc) · 1.96 KB
/
project.lock.json.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var fs = require('fs');
var safeBufferRead = require('./safeBufferRead');
var path = require('path');
module.exports.list = function(dir, settings){
if (!fs.existsSync(path.join(dir,'project.lock.json'))){
return null;
}
var jsonString = safeBufferRead(fs.readFileSync(path.join(dir,'project.lock.json')));
var json = JSON.parse(jsonString);
var packageDictionary = {};
// put all packages in the dictionary
Object.keys(json.targets).forEach(target => {
Object.keys(json.targets[target]).forEach(dep => {
if (!settings.showSystem && dep.indexOf('System.') === 0) return;
var depParts = dep.split('/');
var id = depParts[0];
var version = depParts[1];
if (!packageDictionary[id]) {
packageDictionary[id] = {
id : id,
version: version,
targetFramework : target,
label : id + " " + (settings.hideVersion ? "" : (version || '').green),
nodes:[]
}
}
});
});
// build the hierarchy
Object.keys(json.targets).forEach(target => {
Object.keys(json.targets[target]).forEach(dep => {
if (!settings.showSystem && dep.indexOf('System.') === 0) return;
var depParts = dep.split('/');
var id = depParts[0];
var dependency = json.targets[target][dep];
var pkg = packageDictionary[id];
Object.keys(dependency.dependencies || []).forEach(dependantId => {
if (packageDictionary[dependantId] && pkg.nodes.filter(x => x.id === dependantId).length === 0){
var resolvedDep = packageDictionary[dependantId];
pkg.nodes.push(resolvedDep);
resolvedDep.used = true;
}
});
});
});
return Object.keys(packageDictionary).map(key => packageDictionary[key]);
}