-
Notifications
You must be signed in to change notification settings - Fork 0
/
yarn.js
121 lines (100 loc) · 4.11 KB
/
yarn.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var chalk = require('chalk');
var clear = require('clear');
var CLI = require('clui');
var figlet = require('figlet');
var parseArgs = require('minimist');
var Spinner = CLI.Spinner;
var path = require('path');
var axios = require('axios');
var file = require('./file.js');
var delay = require('./delay.js');
var EventEmitter = require('events');
var events = require('./events.js');
var registry = require('./registry.js');
var yarn = require("./node_modules/yarn/lib/lockfile/wrapper");
function yarnMatch(object, packageName) {
for (var key in object) {
if (key.match(new RegExp( packageName + '@'))) {
return key;
}
}
return null;
}
function testYarn(eventEmitter, options) {
var dir = process.cwd();
yarn.default.fromDirectory(dir).then((lockfile) => {
if (!lockfile.cache) {
throw "yarn.lock could not be found or loaded";
}
var packageJson = file.readJsonFile('package.json');
let npmPackages = [];
npmPackages = Object.keys(lockfile.cache).map(function(key){
return {'name' : key.split('@')[0], 'info' : lockfile.cache[key]};
});
let packages = [];
let infos = [];
var infosSpinner = new Spinner('Getting Packages Info', ['⣾','⣽','⣻','⢿','⡿','⣟','⣯','⣷']);
infosSpinner.start();
for (let dependency of npmPackages) {
dependencyName = dependency.name;
infos.push(axios.get('http://registry.npmjs.org/' + dependencyName));
}
let projectDelay = {'major':0, 'minor':0, 'patch':0, 'abandoned':0, 'unstable':0};
axios.all(infos).then(function (results) {
for (let result of results) {
var packageInfos = result.data;
packages[packageInfos.name] = packageInfos;
}
}).then(function(){
infosSpinner.stop();
for (let dependency of npmPackages) {
var name = dependency.name;
var range = null;
if (options['respect-require']) {
range = packageJson.dependencies[name];
}
var lastDependencyVersion = packages[name]['dist-tags'].latest;
var deprecate = packages[name]['versions'][dependency.info.version].deprecated;
if ( deprecate ) {
projectDelay.abandoned++;
eventEmitter.emit('abandoned', [name, deprecate]);
}
if (!delay.isStable(dependency.info.version)) {
projectDelay.unstable++;
eventEmitter.emit('unstable', [name, dependency.info.version]);
}
if (delay.isStable(dependency.info.version)) {
var versionCompare = delay.compareVersions(lastDependencyVersion, dependency.info.version);
switch (versionCompare) {
case null:
eventEmitter.emit('nodelay', name);
break;
default:
if (versionCompare.major) {
eventEmitter.emit('major', [name, versionCompare.major]);
projectDelay.major++;
break;
}
if (versionCompare.minor) {
eventEmitter.emit('minor', [name, versionCompare.minor]);
projectDelay.minor++;
break;
}
if (versionCompare.patch) {
eventEmitter.emit('patch', [name, versionCompare.patch]);
projectDelay.patch++;
break;
}
}
}
}
delay.projectDelay(projectDelay, 'Yarn');
});
}).catch((err) => {
throw err;
});
}
module.exports = {
yarnMatch: yarnMatch,
testYarn: testYarn
};