2024-09-13 05:43:13 +00:00
|
|
|
// deno-lint-ignore-file no-console
|
2024-01-25 09:36:46 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2024-03-25 04:03:01 +00:00
|
|
|
import { walk } from "../fs/walk.ts";
|
|
|
|
import { relative } from "../path/relative.ts";
|
|
|
|
import { dirname } from "../path/dirname.ts";
|
2024-01-25 09:36:46 +00:00
|
|
|
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;
|
|
|
|
|
2024-03-25 04:03:01 +00:00
|
|
|
for await (
|
|
|
|
const { path: modFilePath } of walk(ROOT, {
|
|
|
|
includeDirs: true,
|
|
|
|
exts: ["ts"],
|
|
|
|
match: [/mod\.ts$/],
|
|
|
|
maxDepth: 2,
|
|
|
|
})
|
|
|
|
) {
|
2024-01-25 09:36:46 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2024-03-25 04:03:01 +00:00
|
|
|
for await (
|
|
|
|
const { path: filePath } of walk(dirname(modFilePath), {
|
2024-03-26 01:31:22 +00:00
|
|
|
exts: [".ts"],
|
2024-03-25 04:03:01 +00:00
|
|
|
includeDirs: false,
|
|
|
|
maxDepth: 1,
|
|
|
|
skip: [
|
2024-09-11 10:38:13 +00:00
|
|
|
/unstable/,
|
2024-03-25 04:03:01 +00:00
|
|
|
/dotenv(\/|\\)load\.ts$/,
|
|
|
|
/front_matter(\/|\\)yaml\.ts$/,
|
|
|
|
/front_matter(\/|\\)json\.ts$/,
|
|
|
|
/front_matter(\/|\\)toml\.ts$/,
|
|
|
|
/front_matter(\/|\\)any\.ts$/,
|
2024-05-29 05:47:42 +00:00
|
|
|
/uuid(\/|\\)v1\.ts$/,
|
|
|
|
/uuid(\/|\\)v3\.ts$/,
|
|
|
|
/uuid(\/|\\)v4\.ts$/,
|
|
|
|
/uuid(\/|\\)v5\.ts$/,
|
2024-09-04 02:57:49 +00:00
|
|
|
/uuid(\/|\\)v7\.ts$/,
|
2024-03-25 04:03:01 +00:00
|
|
|
/yaml(\/|\\)schema\.ts$/,
|
|
|
|
/test\.ts$/,
|
|
|
|
/\.d\.ts$/,
|
|
|
|
/(\/|\\)_/,
|
|
|
|
/mod\.ts$/,
|
|
|
|
],
|
|
|
|
})
|
|
|
|
) {
|
|
|
|
const relativeSpecifier = relative(modFilePath, filePath).slice(1)
|
|
|
|
.replaceAll("\\", "/");
|
2024-01-25 09:36:46 +00:00
|
|
|
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);
|