Skip to content
This repository was archived by the owner on Feb 14, 2026. It is now read-only.

Commit c96072e

Browse files
fix: extract .mdx files from GitHub tarballs
The tarball extraction and local path validation only matched .md files, causing repos with .mdx content (e.g. Astro docs) to download 0 files. v0.6.4 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9737156 commit c96072e

4 files changed

Lines changed: 37 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dynamik-dev/refdocs",
3-
"version": "0.6.3",
3+
"version": "0.6.4",
44
"type": "module",
55
"description": "Local CLI tool that indexes markdown documentation and exposes fast fuzzy search with intelligent chunking",
66
"main": "dist/index.js",

src/add.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function addLocalPath(
142142
}
143143

144144
if (!hasMarkdownFiles(absolutePath)) {
145-
throw new Error(`No .md files found in ${inputPath}`);
145+
throw new Error(`No .md/.mdx files found in ${inputPath}`);
146146
}
147147

148148
const localPath = relative(configDir, absolutePath);
@@ -189,7 +189,7 @@ export function removePath(
189189
function hasMarkdownFiles(dir: string): boolean {
190190
const entries = readdirSync(dir, { withFileTypes: true });
191191
for (const entry of entries) {
192-
if (entry.isFile() && entry.name.endsWith(".md")) return true;
192+
if (entry.isFile() && (entry.name.endsWith(".md") || entry.name.endsWith(".mdx"))) return true;
193193
if (entry.isDirectory()) {
194194
if (hasMarkdownFiles(join(dir, entry.name))) return true;
195195
}
@@ -210,7 +210,7 @@ export async function extractMarkdownFiles(
210210
const chunks: Buffer[] = [];
211211
stream.on("data", (chunk: Buffer) => chunks.push(chunk));
212212
stream.on("end", () => {
213-
if (header.type === "file" && header.name.endsWith(".md")) {
213+
if (header.type === "file" && (header.name.endsWith(".md") || header.name.endsWith(".mdx"))) {
214214
const relativePath = stripTarPrefix(header.name);
215215

216216
if (subpath && !relativePath.startsWith(subpath + "/") && relativePath !== subpath) {

tests/add.test.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { extractMarkdownFiles, updateSources, addLocalPath, removePath, isPathCo
66
import type { RefdocsConfig } from "../src/types.js";
77

88
const FIXTURE_PATH = join(import.meta.dirname, "fixtures", "test-repo.tar.gz");
9+
const MDX_FIXTURE_PATH = join(import.meta.dirname, "fixtures", "test-repo-mdx.tar.gz");
910

1011
describe("extractMarkdownFiles", () => {
1112
let tmpDir: string;
@@ -70,6 +71,27 @@ describe("extractMarkdownFiles", () => {
7071
const count = await extractMarkdownFiles(tarball, "nonexistent", join(tmpDir, "out"));
7172
expect(count).toBe(0);
7273
});
74+
75+
it("extracts .mdx files alongside .md files", async () => {
76+
const mdxTarball = readFileSync(MDX_FIXTURE_PATH);
77+
const count = await extractMarkdownFiles(mdxTarball, "", join(tmpDir, "out"));
78+
expect(count).toBe(3);
79+
80+
expect(existsSync(join(tmpDir, "out", "docs", "guide.md"))).toBe(true);
81+
expect(existsSync(join(tmpDir, "out", "docs", "component.mdx"))).toBe(true);
82+
expect(existsSync(join(tmpDir, "out", "docs", "page.mdx"))).toBe(true);
83+
expect(existsSync(join(tmpDir, "out", "package.json"))).toBe(false);
84+
});
85+
86+
it("filters .mdx files by subpath", async () => {
87+
const mdxTarball = readFileSync(MDX_FIXTURE_PATH);
88+
const count = await extractMarkdownFiles(mdxTarball, "docs", join(tmpDir, "out"));
89+
expect(count).toBe(3);
90+
91+
expect(existsSync(join(tmpDir, "out", "guide.md"))).toBe(true);
92+
expect(existsSync(join(tmpDir, "out", "component.mdx"))).toBe(true);
93+
expect(existsSync(join(tmpDir, "out", "page.mdx"))).toBe(true);
94+
});
7395
});
7496

7597
vi.mock("../src/github.js", async (importOriginal) => {
@@ -261,12 +283,21 @@ describe("addLocalPath", () => {
261283
expect(() => addLocalPath("nope", tmpDir, baseConfig)).toThrow("Directory not found: nope");
262284
});
263285

264-
it("throws if directory has no .md files", () => {
286+
it("throws if directory has no .md/.mdx files", () => {
265287
const emptyDir = join(tmpDir, "empty");
266288
mkdirSync(emptyDir, { recursive: true });
267289
writeFileSync(join(emptyDir, "data.json"), "{}");
268290

269-
expect(() => addLocalPath("empty", tmpDir, baseConfig)).toThrow("No .md files found");
291+
expect(() => addLocalPath("empty", tmpDir, baseConfig)).toThrow("No .md/.mdx files found");
292+
});
293+
294+
it("accepts a directory with only .mdx files", () => {
295+
const mdxDir = join(tmpDir, "mdx-docs");
296+
mkdirSync(mdxDir, { recursive: true });
297+
writeFileSync(join(mdxDir, "page.mdx"), "# MDX Page");
298+
299+
const result = addLocalPath("mdx-docs", tmpDir, baseConfig);
300+
expect(result.localPath).toBe("mdx-docs");
270301
});
271302

272303
it("finds .md files in subdirectories", () => {
309 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)