-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (74 loc) · 2.98 KB
/
index.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
import userPackages from "npm-user-packages";
import { Listr } from "listr2";
import pacote from "pacote";
const getVersions = async (moduleName) => {
const result = await pacote.packument(moduleName, {
includeDeprecated: true,
});
return Object.values(result.versions);
};
export default async () => new Listr([
{
title: "Get packages for user",
task: async (context, task) => {
task.title = `Get packages for user ${context.username}`;
const packages = await userPackages(context.username);
context.packages = packages; // eslint-disable-line require-atomic-updates
},
},
{
title: 'Get versions of packages',
task: (context, task) => task.newListr(context.packages.map((package_) => ({
title: package_.name,
task: (taskContext, packageTask) => packageTask.newListr([
{
title: `Get versions for ${package_.name}`,
task: async () => {
context.info[package_.name] = {
hasUndeprecated: false,
versions: await getVersions(package_.name),
};
},
},
{
title: `Get deprecation messages for ${package_.name}`,
task: () => {
for(const version of context.info[package_.name].versions) {
if(version.deprecated) {
if(!context.info[package_.name].deprecations) {
context.info[package_.name].deprecations = {};
}
context.info[package_.name].deprecations[version.version] = version.deprecated;
}
else {
context.info[package_.name].hasUndeprecated = true;
}
}
},
},
{
title: `Collect deprecations for ${package_.name}`,
task: () => {
if(!context.info[package_.name].hasUndeprecated && !context.verbose) {
context.info[package_.name] = {
_allDeprecated: true,
};
}
else if(context.info[package_.name].deprecations) {
context.info[package_.name] = context.info[package_.name].deprecations;
}
else {
delete context.info[package_.name];
}
},
},
], {
showSubtasks: false,
concurrent: false,
}),
})), {
concurrent: true,
clearOutput: true,
}),
},
]);