From 0c4485bf9d9c96b3352ac1f79c795507de7d280a Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Sat, 9 Mar 2024 13:52:38 -0600 Subject: [PATCH 1/3] chore: bump biome --- biome.json | 5 ++--- deno.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/biome.json b/biome.json index da969039..b1fb69b3 100644 --- a/biome.json +++ b/biome.json @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/1.5.0/schema.json", + "$schema": "https://biomejs.dev/schemas/1.6.0/schema.json", "organizeImports": { "enabled": true }, @@ -14,8 +14,7 @@ "all": true, "nursery": { "all": true, - "useImportRestrictions": "off", - "useFilenamingConvention": "off" + "useImportRestrictions": "off" }, "style": { "noImplicitBoolean": "off", diff --git a/deno.json b/deno.json index 90b32226..2166fde2 100644 --- a/deno.json +++ b/deno.json @@ -17,7 +17,7 @@ "esm:add": "deno task esm add", "esm:update": "deno task esm update", "esm:remove": "deno task esm remove", - "biome": "deno run -A npm:@biomejs/biome@1.5.3", + "biome": "deno run -A npm:@biomejs/biome@1.6.0", "biome:ci": "deno task biome ci . --error-on-warnings", "biome:check": "deno task biome check . --error-on-warnings", "compile:mdx": "deno run -A tool/compile-mdx.ts", From 341b9d80a26da49e6a02ab08122ae73b2cf3e30a Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Sat, 9 Mar 2024 17:32:54 -0600 Subject: [PATCH 2/3] chore: fix lints --- biome.json | 5 ++++- tool/compile-mdx.ts | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/biome.json b/biome.json index b1fb69b3..668a9fc6 100644 --- a/biome.json +++ b/biome.json @@ -14,7 +14,10 @@ "all": true, "nursery": { "all": true, - "useImportRestrictions": "off" + "useImportRestrictions": "off", + "useJsxKeyInIterable": "off", + "useSortedClasses": "off", + "noConsole": "off" }, "style": { "noImplicitBoolean": "off", diff --git a/tool/compile-mdx.ts b/tool/compile-mdx.ts index 6c282835..e457dcb2 100644 --- a/tool/compile-mdx.ts +++ b/tool/compile-mdx.ts @@ -73,7 +73,6 @@ async function run(): Promise { * @remarks * This is an async generator because it's recursive. */ -// biome-ignore lint/nursery/useAwait: for-await isn't caught correctly. async function* getSolutions( basePath: string, currentPath: string = basePath, @@ -134,7 +133,6 @@ function lint(files: VFile[]): void { * @param initialFiles A list of virtual MDX files for compilation. * @returns A list of virtual JS files. */ -// biome-ignore lint/nursery/useAwait: for-await isn't caught correctly. async function* compileSolutions( initialFiles: AsyncIterable, ): AsyncGenerator { From 4a480b8bde9feaeada60b57f93f6ae5f045134f0 Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:17:01 -0600 Subject: [PATCH 3/3] perf: use await return Modern JS engines properly optimize `return await` (despite the spec). This means that `return await` actually leads to one fewer microtask. Additionally, it makes for better stack traces. --- src/routes/solutions/[category]/[[slug]].tsx | 4 ++-- src/routes/solutions/[category]/index.tsx | 10 +++++----- tool/compile-mdx.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/routes/solutions/[category]/[[slug]].tsx b/src/routes/solutions/[category]/[[slug]].tsx index e5d56934..9e2e7ba8 100644 --- a/src/routes/solutions/[category]/[[slug]].tsx +++ b/src/routes/solutions/[category]/[[slug]].tsx @@ -32,7 +32,7 @@ export const handler: Handlers = { try { const { category, slug } = ctx.params; if (category === undefined) { - return ctx.renderNotFound(); + return await ctx.renderNotFound(); } const base = join(contentDir, category); @@ -41,7 +41,7 @@ export const handler: Handlers = { const file: MdxFile = await import(filepath); - return ctx.render({ page: file }); + return await ctx.render({ page: file }); } catch (e) { console.error(e); diff --git a/src/routes/solutions/[category]/index.tsx b/src/routes/solutions/[category]/index.tsx index 05d9ff8c..f106b0b7 100644 --- a/src/routes/solutions/[category]/index.tsx +++ b/src/routes/solutions/[category]/index.tsx @@ -33,14 +33,14 @@ const categoryProps = z.object({ * The server handler for the solution page. */ export const handler: Handlers = { - GET( + async GET( _req: Request, ctx: FreshContextHelper, - ): Response | Promise { + ): Promise { try { const { category } = ctx.params; if (category === undefined || !isKey(categoryMetadata, category)) { - return ctx.renderNotFound(); + return await ctx.renderNotFound(); } let data: CategoryData[] = []; @@ -62,7 +62,7 @@ export const handler: Handlers = { } } - return ctx.render({ + return await ctx.render({ pages: categoryPropsPages.parse(data), title: categoryMetadata[category].title, description: categoryMetadata[category].description, @@ -70,7 +70,7 @@ export const handler: Handlers = { } catch (e) { console.error(e); - return ctx.renderNotFound(); + return await ctx.renderNotFound(); } }, }; diff --git a/tool/compile-mdx.ts b/tool/compile-mdx.ts index e457dcb2..bea21edc 100644 --- a/tool/compile-mdx.ts +++ b/tool/compile-mdx.ts @@ -200,8 +200,8 @@ async function writeSolutions(solutions: VFile[]): Promise { * @param solution A file to write. * @returns A promise resolving when the file's written. */ -function writeSolution(solution: VFile): Promise { - return Deno.writeTextFile( +async function writeSolution(solution: VFile): Promise { + return await Deno.writeTextFile( join(contentDir, solution.path), solution.toString(), );