-
Notifications
You must be signed in to change notification settings - Fork 3
/
doctor.ts
80 lines (75 loc) · 2.16 KB
/
doctor.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { getProtocolInterface, Protocol } from "./deps.ts";
import { isNewSemverRelease } from "./utilities.ts";
type RuntimeVersion = {
name: string;
current: string;
} & RuntimeDetails;
type RuntimeDetails = {
message?: string;
error?: {
message: string;
};
};
const getHostedDenoRuntimeVersion = async (
protocol: Protocol,
): Promise<RuntimeDetails> => {
try {
const metadataURL = "https://api.slack.com/slackcli/metadata.json";
const response = await fetch(metadataURL);
if (!response.ok || response.status !== 200) {
protocol.warn("Failed to collect upstream CLI metadata:");
protocol.warn(response);
return {};
}
const metadata = await response.json();
const version = metadata?.["deno-runtime"]?.releases[0]?.version;
if (!version) {
const details = JSON.stringify(metadata, null, " ");
protocol.warn(
"Failed to find the minimum Deno version in the upstream CLI metadata response:",
);
protocol.warn(details);
return {};
}
const message = Deno.version.deno !== version
? `Applications deployed to Slack use Deno version ${version}`
: undefined;
if (isNewSemverRelease(Deno.version.deno, version)) {
return {
message,
error: { message: "The installed runtime version is not supported" },
};
}
return { message };
} catch (err) {
protocol.warn("Failed to collect or process upstream CLI metadata:");
protocol.warn(err);
return {};
}
};
export const getRuntimeVersions = async (protocol: Protocol): Promise<{
versions: RuntimeVersion[];
}> => {
const hostedDenoRuntimeVersion = await getHostedDenoRuntimeVersion(protocol);
const versions = [
{
"name": "deno",
"current": Deno.version.deno,
...hostedDenoRuntimeVersion,
},
{
"name": "typescript",
"current": Deno.version.typescript,
},
{
"name": "v8",
"current": Deno.version.v8,
},
];
return { versions };
};
if (import.meta.main) {
const protocol = getProtocolInterface(Deno.args);
const prunedDoctor = await getRuntimeVersions(protocol);
protocol.respond(JSON.stringify(prunedDoctor));
}