deno.land / std@0.224.0 / _tools / check_mod_exports.ts

check_mod_exports.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
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { walk } from "../fs/walk.ts";import { relative } from "../path/relative.ts";import { dirname } from "../path/dirname.ts";import * as colors from "../fmt/colors.ts";import ts from "npm:typescript";
const ROOT = new URL("../", import.meta.url);const FAIL_FAST = Deno.args.includes("--fail-fast");
let shouldFail = false;
for await ( const { path: modFilePath } of walk(ROOT, { includeDirs: true, exts: ["ts"], match: [/mod\.ts$/], maxDepth: 2, })) { const source = await Deno.readTextFile(modFilePath); const sourceFile = ts.createSourceFile( modFilePath, source, ts.ScriptTarget.Latest, ); const exportSpecifiers = new Set(); sourceFile.forEachChild((node) => { if (!ts.isExportDeclaration(node)) return; if (!node.moduleSpecifier) return; if (!ts.isStringLiteral(node.moduleSpecifier)) return; exportSpecifiers.add(node.moduleSpecifier.text); });
for await ( const { path: filePath } of walk(dirname(modFilePath), { exts: [".ts"], includeDirs: false, maxDepth: 1, skip: [ /dotenv(\/|\\)load\.ts$/, /front_matter(\/|\\)yaml\.ts$/, /front_matter(\/|\\)json\.ts$/, /front_matter(\/|\\)toml\.ts$/, /front_matter(\/|\\)any\.ts$/, /yaml(\/|\\)schema\.ts$/, /test\.ts$/, /\.d\.ts$/, /(\/|\\)_/, /mod\.ts$/, ], }) ) { const relativeSpecifier = relative(modFilePath, filePath).slice(1) .replaceAll("\\", "/"); if (!exportSpecifiers.has(relativeSpecifier)) { console.warn( `${ colors.yellow("Warn") } ${modFilePath} does not export '${relativeSpecifier}'.`, ); shouldFail = true; if (FAIL_FAST) Deno.exit(1); } }}
if (shouldFail) Deno.exit(1);
std

Version Info

Tagged at
3 weeks ago