Skip to content

Commit c573fd0

Browse files
committed
feat(showcase): verifier checks @/snippets and @/components import paths
1 parent c485ec8 commit c573fd0

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

showcase/scripts/verify-shell-docs.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { runBuildCheck } from "./verify-shell-docs.js";
33
import { checkInlineDemoRefs } from "./verify-shell-docs.js";
44
import { checkSnippetRegions } from "./verify-shell-docs.js";
55
import { checkInternalLinks } from "./verify-shell-docs.js";
6+
import { checkImportPaths } from "./verify-shell-docs.js";
67

78
describe("runBuildCheck", () => {
89
it("returns a result with name, status, and messages", () => {
@@ -137,3 +138,30 @@ describe("checkInternalLinks", () => {
137138
expect(result.status).toBe("pass");
138139
});
139140
});
141+
142+
describe("checkImportPaths", () => {
143+
it("fails when an @/snippets/... path does not exist", () => {
144+
const pages = [
145+
{
146+
path: "a.mdx",
147+
body: 'import X from "@/snippets/does-not-exist.mdx";',
148+
},
149+
];
150+
const existsOnDisk = (_p: string) => false;
151+
const result = checkImportPaths({ pages, existsOnDisk });
152+
expect(result.status).toBe("fail");
153+
expect(result.messages.join(" ")).toContain("@/snippets/does-not-exist.mdx");
154+
});
155+
156+
it("passes when all paths resolve", () => {
157+
const pages = [
158+
{
159+
path: "a.mdx",
160+
body: 'import X from "@/snippets/exists.mdx";',
161+
},
162+
];
163+
const existsOnDisk = (_p: string) => true;
164+
const result = checkImportPaths({ pages, existsOnDisk });
165+
expect(result.status).toBe("pass");
166+
});
167+
});

showcase/scripts/verify-shell-docs.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,27 @@ export function checkInternalLinks(input: {
167167
messages: failures,
168168
};
169169
}
170+
171+
const ALIAS_IMPORT_RE =
172+
/^\s*import\s+[^"';]+from\s+["'](@\/[^"']+)["']\s*;?\s*$/gm;
173+
174+
export function checkImportPaths(input: {
175+
pages: PageInput[];
176+
existsOnDisk: (importPath: string) => boolean;
177+
}): CheckResult {
178+
const failures: string[] = [];
179+
for (const page of input.pages) {
180+
ALIAS_IMPORT_RE.lastIndex = 0;
181+
let m: RegExpExecArray | null;
182+
while ((m = ALIAS_IMPORT_RE.exec(page.body)) !== null) {
183+
if (!input.existsOnDisk(m[1])) {
184+
failures.push(`${page.path}: unresolved import "${m[1]}"`);
185+
}
186+
}
187+
}
188+
return {
189+
name: "import-paths",
190+
status: failures.length === 0 ? "pass" : "fail",
191+
messages: failures,
192+
};
193+
}

0 commit comments

Comments
 (0)