-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
check.ts
64 lines (53 loc) Β· 2.28 KB
/
check.ts
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
import {BaseCommand} from '@yarnpkg/cli';
import {Configuration, formatUtils, hashUtils, httpUtils, MessageName, StreamReport} from '@yarnpkg/core';
import {Command, Option, Usage} from 'clipanion';
// eslint-disable-next-line arca/no-default-export
export default class PluginCheckCommand extends BaseCommand {
static paths = [
[`plugin`, `check`],
];
static usage: Usage = Command.Usage({
category: `Plugin-related commands`,
description: `find all third-party plugins that differ from their own spec`,
details: `
Check only the plugins from https.
If this command detects any plugin differences in the CI environment, it will throw an error.
`,
examples: [[
`find all third-party plugins that differ from their own spec`,
`$0 plugin check`,
]],
});
json = Option.Boolean(`--json`, false, {
description: `Format the output as an NDJSON stream`,
});
async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const rcFiles = await Configuration.findRcFiles(this.context.cwd);
const report = await StreamReport.start({
configuration,
json: this.json,
stdout: this.context.stdout,
}, async report => {
for (const rcFile of rcFiles) {
if (!rcFile.data?.plugins) continue;
for (const plugin of rcFile.data.plugins) {
if (!plugin.checksum)
continue;
if (!plugin.spec.match(/^https?:/))
continue;
const newBuffer = await httpUtils.get(plugin.spec, {configuration});
const newChecksum = hashUtils.makeHash(newBuffer);
if (plugin.checksum === newChecksum)
continue;
const prettyPath = formatUtils.pretty(configuration, plugin.path, formatUtils.Type.PATH) ;
const prettySpec = formatUtils.pretty(configuration, plugin.spec, formatUtils.Type.URL) ;
const prettyMessage = `${prettyPath} is different from the file provided by ${prettySpec}`;
report.reportJson({...plugin, newChecksum});
report.reportError(MessageName.UNNAMED, prettyMessage);
}
}
});
return report.exitCode();
}
}