deno.land / std@0.157.0 / _tools / check_deprecation.ts

check_deprecation.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
// Copyright 2022-2022 the Deno authors. All rights reserved. MIT license.
import { VERSION } from "../version.ts";import * as semver from "../semver/mod.ts";import * as colors from "../fmt/colors.ts";import { doc } from "https://deno.land/x/deno_doc/mod.ts";
const EXTENSIONS = [".mjs", ".js", ".ts"];const EXCLUDED_PATHS = [ ".git", "node/", "dotenv/testdata", "fs/testdata", "http/testdata",];
console.warn( colors.yellow("Warning"), `ignore ${ colors.green(`"fs/exists.ts"`) } until issue is resolved: https://github.com/denoland/deno_std/issues/2594`,);EXCLUDED_PATHS.push("fs/exists.ts");
const ROOT = new URL("../", import.meta.url).pathname.slice(0, -1);
const FAIL_FAST = Deno.args.includes("--fail-fast");
const DEPRECATION_IN_FORMAT_REGEX = /^\(will be removed in (?<version>\d+\.\d+\.\d+)\)/;const DEPRECATION_AFTER_FORMAT_REGEX = /^\(will be removed after (?<version>\d+\.\d+\.\d+)\)/;
let shouldFail = false;
// add three minor version to current versionconst DEFAULT_DEPRECATED_VERSION = semver.inc( semver.inc( semver.inc( VERSION, "minor", )!, "minor", )!, "minor",);
const DEPRECATION_IN_FORMAT = `(will be removed in ${DEFAULT_DEPRECATED_VERSION})`;
async function walk(dir: string) { for (const x of Deno.readDirSync(dir)) { const filePath = `${dir}/${x.name}`;
if (x.isDirectory) { await walk(filePath); continue; }
const isExcluded = EXCLUDED_PATHS .map((x) => filePath.includes(x)) .some((x) => x); if ( isExcluded || !EXTENSIONS.map((x) => filePath.endsWith(x)).some((x) => x) ) { continue; }
// deno_doc only takes urls. const url = new URL(filePath, "file://"); const docs = await doc(url.href);
for (const d of docs) { const tags = d.jsDoc?.tags; if (tags) { for (const tag of tags) { switch (tag.kind) { case "deprecated": { const message = tag.doc; if (!message) { console.error( colors.red("Error"), `${ colors.bold("@deprecated") } tag must have a version: ${filePath}:${d.location.line}`, ); shouldFail = true; if (FAIL_FAST) Deno.exit(1); continue; } const { version: afterVersion } = DEPRECATION_AFTER_FORMAT_REGEX.exec(message)?.groups || {};
if (afterVersion) { if (semver.lt(afterVersion, VERSION)) { console.warn( colors.yellow("Warn"), `${ colors.bold("@deprecated") } tag is expired and export should be removed: ${filePath}:${d.location.line}`, ); } continue; }
const { version: inVersion } = DEPRECATION_IN_FORMAT_REGEX.exec(message)?.groups || {}; if (!inVersion) { console.error( colors.red("Error"), `${ colors.bold("@deprecated") } tag version is missing. Append '${DEPRECATION_IN_FORMAT}' after @deprecated tag: ${filePath}:${d.location.line}`, ); shouldFail = true; if (FAIL_FAST) Deno.exit(1); continue; }
if (!semver.gt(inVersion, VERSION)) { console.error( colors.red("Error"), `${ colors.bold("@deprecated") } tag is expired and export must be removed: ${filePath}:${d.location.line}`, ); if (FAIL_FAST) Deno.exit(1); shouldFail = true; continue; } } } } } } }}
await walk(ROOT);if (shouldFail) Deno.exit(1);
std

Version Info

Tagged at
a year ago