Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/replace-fast-glob-with-tinyglobby.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"leadtype": patch
---

Replace `fast-glob` with `tinyglobby` to shrink the dependency tree (16 transitive deps → 3) and reduce install footprint (~1.2 MB → ~240 KB). Globbing behavior and call-site options are unchanged.
6 changes: 3 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion evals/lib/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { spawn } from "node:child_process";
import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
import path from "node:path";
import { tool } from "ai";
import fg from "fast-glob";
import { glob as fg } from "tinyglobby";
import { z } from "zod";
import type { ToolCall } from "./transcript";

Expand Down Expand Up @@ -235,6 +235,9 @@ export function scopedTools(ctx: ToolCtx) {
absolute: false,
dot: false,
followSymbolicLinks: false,
// Agent supplies the pattern; keep fast-glob semantics so a
// bare directory name doesn't silently expand to `dir/**`.
expandDirectories: false,
});
return matches.join("\n");
},
Expand Down
2 changes: 1 addition & 1 deletion evals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"devDependencies": {
"ai": "^6.0.168",
"fast-glob": "3.3.3",
"tinyglobby": "0.2.16",
"vitest": "^2.1.8",
"zod": "^3.23.8"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/leadtype/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"dependencies": {
"@types/mdast": "4.0.4",
"decode-named-character-reference": "1.3.0",
"fast-glob": "3.3.3",
"gray-matter": "4.0.3",
"jiti": "^2.7.0",
"json5": "2.2.3",
Expand All @@ -102,6 +101,7 @@
"remark": "15.0.1",
"remark-gfm": "4.0.1",
"remark-mdx": "3.1.1",
"tinyglobby": "0.2.16",
"unified": "11.0.5",
"unist-builder": "4.0.0",
"unist-util-is": "6.0.1",
Expand Down
34 changes: 33 additions & 1 deletion packages/leadtype/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import fg from "fast-glob";
import { glob as fg } from "tinyglobby";
import { afterEach, describe, expect, it } from "vitest";
import { runCli } from "./cli";

Expand Down Expand Up @@ -524,6 +524,38 @@ describe("leadtype CLI", () => {
expect(error.filters.include).toEqual(["nope/**"]);
});

it("treats a bare directory in --include as matching no MDX files", async () => {
// tinyglobby expands bare directory names to `dir/**` by default; fast-glob
// didn't. With expandDirectories disabled at the call site, `--include build`
// should fail the same way `--include nope` does — not silently include
// every file under `docs/build/`.
const outDir = await createTempDir();
const capture = createCapture();

const code = await runCli(
[
"generate",
"--src",
repoRoot,
"--out",
outDir,
"--include",
"build",
"--format",
"json",
],
capture.io
);

expect(code).toBe(1);
const error = JSON.parse(capture.stderr) as {
error: string;
filters: { include: string[] };
};
expect(error.error).toContain("No MDX files matched");
expect(error.filters.include).toEqual(["build"]);
});

it("rejects invalid generate formats as usage errors", async () => {
const capture = createCapture();

Expand Down
7 changes: 6 additions & 1 deletion packages/leadtype/src/cli/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { existsSync } from "node:fs";
import { cp, mkdir, mkdtemp, readFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import fg from "fast-glob";
import matter from "gray-matter";
import { createJiti } from "jiti";
import { glob as fg } from "tinyglobby";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Set expandDirectories false for fast-glob parity

When users pass a static directory pattern through --include (for example --include guides), this import changes the behavior of the later fg(patterns, { onlyFiles: true, ... }) call: tinyglobby enables expandDirectories by default and its migration docs say to disable it when migrating from fast-glob, so the pattern now expands to files under that directory instead of matching no files as fast-glob did with onlyFiles. That makes filtered bundle/site generation include an entire directory for inputs that previously failed with “No MDX files matched,” so add expandDirectories: false at the migrated call sites that need fast-glob semantics.

Useful? React with 👍 / 👎.

import { convertAllMdx } from "../convert";
import {
logger,
Expand Down Expand Up @@ -436,6 +436,11 @@ async function createSourceMirror(
const files = await fg(patterns, {
absolute: false,
cwd: docsDir,
// tinyglobby expands bare directory names (`build` → `build/**`) by
// default; fast-glob did not. Disable it so `--include build` still
// reports "No MDX files matched" instead of silently slurping everything
// under `build/`.
expandDirectories: false,
ignore: filters.exclude,
onlyFiles: true,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/leadtype/src/convert/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
import { cpus } from "node:os";
import { basename, dirname, join, relative, resolve, sep } from "node:path";
import { promisify } from "node:util";
import fg from "fast-glob";
import matter from "gray-matter";
import { remark } from "remark";
import remarkGfm from "remark-gfm";
import remarkMdx from "remark-mdx";
import { glob as fg } from "tinyglobby";
import type { Pluggable, PluggableList } from "unified";
import {
deriveDocContext,
Expand Down
5 changes: 4 additions & 1 deletion packages/leadtype/src/lint/runner.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { existsSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { relative, resolve, sep } from "node:path";
import fg from "fast-glob";
import matter from "gray-matter";
import { remark } from "remark";
import remarkGfm from "remark-gfm";
import { glob as fg } from "tinyglobby";
import { visit } from "unist-util-visit";
import * as v from "valibot";
import { convertMdxToMarkdown } from "../convert";
Expand Down Expand Up @@ -97,6 +97,9 @@ async function glob(
onlyFiles: true,
ignore,
dot: false,
// Preserve fast-glob semantics: callers can pass user-supplied ignores,
// and bare directory entries should not auto-expand to `dir/**`.
expandDirectories: false,
});
}

Expand Down
Loading