deno.land / x / trex@v1.13.1 / handlers / handler_check.ts

handler_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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/** * Copyright (c) Crew Dev. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */
import { bold, cyan, green, red, yellow } from "fmt/colors.ts";import { getImportMap } from "../handlers/handle_files.ts";import { CommandNotFound } from "../utils/logs.ts";import type { importMap } from "../utils/types.ts";import { flags, keyWords } from "../utils/info.ts";
interface ToUpdate { pkg: string; latest: string; current: string | undefined; isVersioned: boolean; name: string; std: boolean; x: boolean;}
/** * check if exist an update for a /std/ or /x/ lib on deno.land */export async function checkDepsUpdates(): Promise<void> { const map: importMap = (await getImportMap<importMap>())!; const Args = Deno.args;
if (Args[1]) { CommandNotFound({ commands: [keyWords.check], flags: [...flags.fix, ...flags.help], }); }
const toUpdate: ToUpdate[] = [];
for (const key in map?.imports) { const pkg = map.imports[key];
if (isDenoLand(pkg)) { const { pathname } = toURL(pkg);
if (pathname.startsWith("/std")) { const [, version, name] = pathname.split("/"); const moduleVersion = version.replace("std@", "")?.trim();
const latest = (await stdLatest())!;
if (latest !== moduleVersion) { toUpdate.push({ pkg, latest, current: moduleVersion, isVersioned: moduleVersion !== "std", name, std: true, x: false, }); } } else if (pathname.startsWith("/x/")) { const [, , module] = pathname.split("/"); const [name, version] = module.split("@");
const latest = (await getAllVersion(name))?.trim(); const current = version?.trim();
if (latest !== current) { toUpdate.push({ pkg, latest, current, isVersioned: !!current, name, std: false, x: true, }); } } } }
if (toUpdate.length === 0) { console.log(green("\nall dependencies are up to date.")); }
for (const { isVersioned, name, pkg, latest, current, std, x } of toUpdate) { if (std) { console.log(cyan(`this is a ${bold(yellow("deno.land/std"))} package:`)); }
if (x) { console.log(cyan(`this is a ${bold(yellow("deno.land/x"))} package:`)); }
if (!isVersioned) { console.log( green( `\n${yellow(`warning:`)} the package ${ yellow( `"${name}"`, ) } is a unversioned url => ${yellow(`(${pkg})`)}\n`, ), );
console.log(green(`The latest version is ${cyan(`${latest}`)}\n`)); console.log( green(`${yellow("[quick fix]")}: trex i -m ${name}@${latest}`), );
console.log(red(`------------------------------------------------`)); } else { console.log( green( `\nThe package ${yellow(`"${name}"`)} is outdate: current = ${ cyan( `${current};`, ) } latest = ${cyan(`${latest};`)}\n`, ), );
console.log( green(`${yellow("[quick fix]")}: trex i -m ${name}@${latest}`), ); console.log(red(`------------------------------------------------`)); } }}
export async function stdLatest() { const response = await fetch( "https://raw.githubusercontent.com/denoland/dotland/main/versions.json", ); const { std = [] } = await response.json();
return (std as string[])?.at(0)?.trim();}
const toURL = (url: string) => new URL(url);
const version = (module: string) => `https://cdn.deno.land/${module}/meta/versions.json`;
export async function xLatest(name: string) { const response = await fetch(version(name));
const data = (await response.json()) as { latest: string; versions: string[]; };
return data.latest;}
async function getAllVersion(module: string): Promise<string> { const response = await fetch(version(module)); const { latest } = await response.json();
return latest as string;}
function isDenoLand(url: string) { const { hostname } = toURL(url);
return hostname === "deno.land";}
trex

Version Info

Tagged at
9 months ago