Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
12 changes: 8 additions & 4 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ export default defineConfig({
{
label: "Configure Biome",
link: "/guides/configure-biome",
badge: {
text: "updated",
variant: "note",
},
translations: {
es: "Configurar Biome",
fr: "Configurer Biome",
Expand Down Expand Up @@ -854,6 +850,14 @@ export default defineConfig({
ru: "Социальные значки",
},
},
{
label: "GritQL Plugin Recipes",
link: "/recipes/gritql-plugins",
badge: {
text: "new",
variant: "success",
},
},
],
},
{
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

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

4 changes: 4 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linkWorkspacePackages: tru
packages:
- "scripts"
- "./"
5 changes: 4 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"type": "module"
"type": "module",
"devDependencies": {
"@biomejs/wasm-nodejs": "2.4.6"
}
}
62 changes: 62 additions & 0 deletions scripts/test-gritql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Quick script to test GritQL queries against Biome's WASM.
*
* Update the `query`, `code`, and `lang` variables below, then run:
* node scripts/test-gritql.js
*/

import { MemoryFileSystem, Workspace } from "@biomejs/wasm-nodejs";

// ─── Edit these ────────────────────────────────────────────────────────

const lang = "js"; // "js" | "css" | "json"

const query = "`console.log($...)`";

const code = `
console.log("debug");
console.error("real error");
console.log("another debug");
`;

// ────────────────────────────────────────────────────────────────────────

const encoder = new TextEncoder();
const ext = lang === "json" ? "json" : lang === "css" ? "css" : "tsx";
const defaultLanguage =
lang === "json" ? "JSON" : lang === "css" ? "CSS" : "JavaScript";

const fs = new MemoryFileSystem();
const workspace = Workspace.withFileSystem(fs);
const { projectKey } = workspace.openProject({
openUninitialized: true,
path: "/",
});

const filename = `/test.${ext}`;
fs.insert(filename, encoder.encode(code));
workspace.openFile({
projectKey,
path: filename,
content: { type: "fromServer" },
persistNodeCache: true,
});

const { patternId } = workspace.parsePattern({
pattern: query,
defaultLanguage,
});

const results = workspace.searchPattern({
path: filename,
pattern: String(patternId),
projectKey,
});

workspace.dropPattern({ pattern: String(patternId) });

const matches = results.matches || [];
console.log(`${matches.length} match(es)`);
for (const [start, end] of matches) {
console.log(` [${start}, ${end}] ${JSON.stringify(code.slice(start, end))}`);
}
Loading
Loading