-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPackagedModuleManifestCheck.cs
More file actions
61 lines (54 loc) · 2.16 KB
/
Copy pathPackagedModuleManifestCheck.cs
File metadata and controls
61 lines (54 loc) · 2.16 KB
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
using SimpleModule.Cli.Infrastructure;
namespace SimpleModule.Cli.Commands.Doctor.Checks;
/// <summary>
/// Validates installed packaged modules: the manifest must be readable, at a
/// supported schemaVersion, and framework-compatible with this host.
/// </summary>
public sealed class PackagedModuleManifestCheck : IDoctorCheck
{
private const int SupportedSchemaVersion = 1;
public IEnumerable<CheckResult> Run(Infrastructure.SolutionContext solution)
{
var hostVersion = HostFrameworkVersionResolver.Resolve(solution.RootPath);
foreach (
var reference in PackageReferenceManipulator.GetPackageReferences(
solution.ApiCsprojPath,
solution.RootPath
)
)
{
// Framework/3rd-party packages have no manifest — only inspect ones
// that look like SimpleModule modules to avoid scanning everything.
var manifest = GlobalPackagesCache.TryReadManifest(reference.Id, reference.Version);
if (manifest is null)
{
continue;
}
var name = $"Package {reference.Id}";
if (manifest.SchemaVersion > SupportedSchemaVersion)
{
yield return new CheckResult(
name,
CheckStatus.Fail,
$"manifest schemaVersion {manifest.SchemaVersion} is newer than this tooling "
+ $"supports ({SupportedSchemaVersion}) — update the SimpleModule framework/CLI"
);
continue;
}
if (hostVersion is not null)
{
var compat = FrameworkCompatChecker.Check(manifest.FrameworkCompat, hostVersion);
if (!compat.Compatible)
{
yield return new CheckResult(name, CheckStatus.Fail, compat.Reason);
continue;
}
}
yield return new CheckResult(
name,
CheckStatus.Pass,
$"{manifest.DisplayName} {reference.Version} (manifest v{manifest.SchemaVersion})"
);
}
}
}