


























@@ -0,0 +1,68 @@
1+#!/usr/bin/env node
2+import { readdirSync, readFileSync } from "node:fs";
3+import path from "node:path";
4+5+const repoRoot = path.resolve(import.meta.dirname, "..");
6+const telegramRoot = path.join(repoRoot, "extensions/telegram");
7+const importSpecifierPatterns = [
8+/\bimport\s+(?:type\s+)?[\s\S]*?\bfrom\s*["']([^"']+)["']/gu,
9+/\bexport\s+(?:type\s+)?[\s\S]*?\bfrom\s*["']([^"']+)["']/gu,
10+/\bimport\s*["']([^"']+)["']/gu,
11+/\bimport\s*\(\s*["']([^"']+)["']\s*\)/gu,
12+/\brequire\s*\(\s*["']([^"']+)["']\s*\)/gu,
13+];
14+15+function isForbiddenTelegramTypeSpecifier(specifier) {
16+return specifier === "@grammyjs/types" || specifier.startsWith("@grammyjs/types/");
17+}
18+19+function lineNumberForOffset(source, offset) {
20+return source.slice(0, offset).split(/\r?\n/u).length;
21+}
22+23+function collectTypeScriptFiles(root) {
24+const files = [];
25+for (const entry of readdirSync(root, { withFileTypes: true })) {
26+if (entry.name === "dist" || entry.name === "node_modules") {
27+continue;
28+}
29+const entryPath = path.join(root, entry.name);
30+if (entry.isDirectory()) {
31+files.push(...collectTypeScriptFiles(entryPath));
32+continue;
33+}
34+if (entry.isFile() && entry.name.endsWith(".ts")) {
35+files.push(entryPath);
36+}
37+}
38+return files;
39+}
40+41+const violations = [];
42+for (const filePath of collectTypeScriptFiles(telegramRoot)) {
43+const source = readFileSync(filePath, "utf8");
44+for (const pattern of importSpecifierPatterns) {
45+for (const match of source.matchAll(pattern)) {
46+const specifier = match[1];
47+if (specifier && isForbiddenTelegramTypeSpecifier(specifier)) {
48+violations.push(
49+`${path.relative(repoRoot, filePath)}:${lineNumberForOffset(source, match.index ?? 0)}`,
50+);
51+}
52+}
53+}
54+}
55+56+if (violations.length > 0) {
57+console.error(
58+[
59+"Telegram source must import Telegram Bot API types from grammy/types, not @grammyjs/types.",
60+"This keeps grammY Context and message/update helper types on the same dependency copy.",
61+"",
62+ ...violations,
63+].join("\n"),
64+);
65+process.exit(1);
66+}
67+68+console.log("No Telegram direct @grammyjs/types imports found.");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。