globber
By Ifiok Jr. at
Earlier this week I published my first rust crate; package_json_schema
.
Today I've followed up by publishing a small package for filtering files via globs.
I named it globber
.
Surprisingly, I found learning about Deno tooling far more interesting that working on the published project.
The rust
ecosystem has led the way, showing what great tooling can look like. For example, in rust
you can run tests against comments and markdown files. This is currently missing from the JavaScript ecosystem and is something I've envied for a while.
Today, however, I discovered that Deno has a wonderful utility for verifying that all code examples are valid.
deno test --doc readme.md
This is great!
It parses all JavaScript and TypeScript snippets in the readme.md
file and runs them. If any fail, the test fails. It even provides accurate source maps pointing out exactly where the failures happened.
Genius, and almost perfect.
In order to perfect the process of discovering relevant files I wrote a small script. This script uses the globber
module to search for relevant .md
and .ts
files to test.
// scripts/deno_test.ts
import { globber } from "https://deno.land/x/globber@0.1.0/mod.ts";
const cwd = new URL("../", import.meta.url).pathname;
// Store the relevant file paths
const files: string[] = [];
const iterator = globber({
cwd,
// Only search for markdown and typescript files
extensions: [".ts", ".md"],
exclude: ["**/fixtures/", "**/tests/", "**/scripts/"],
excludeDirectories: true,
});
for await (const file of iterator) {
files.push(file.relative);
}
await Deno
.run({
cmd: ["deno", "test", "--doc", "--check", `--allow-read=${cwd}`, ...files],
cwd,
}).status();
The command can be run like so:
deno run -A scripts/deno_test.ts
I've added this command to the deno.jsonc
tasks.
deno task test:docs
When the command was first run it immediately highlighted several bugs in the documentation. I've fixed them and will be adding this flow to all future continuous integration pipelines.
Little surprises like this make me love 💖 Deno even more.