diff --git a/package-lock.json b/package-lock.json index 717235a..c08aafa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "just-extend": "6.2.0", "just-safe-set": "4.2.1", "mdast-util-to-string": "4.0.0", + "outvariant": "1.4.2", "patch-package": "8.0.0", "prettier": "3.2.4", "prettier-plugin-astro": "0.13.0", @@ -8012,6 +8013,11 @@ "node": ">=0.10.0" } }, + "node_modules/outvariant": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/outvariant/-/outvariant-1.4.2.tgz", + "integrity": "sha512-Ou3dJ6bA/UJ5GVHxah4LnqDwZRwAmWxrG3wtrHrbGnP4RnLCtA64A4F+ae7Y8ww660JaddSoArUR5HjipWSHAQ==" + }, "node_modules/p-limit": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-5.0.0.tgz", diff --git a/package.json b/package.json index e6cd8c3..3582164 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "just-extend": "6.2.0", "just-safe-set": "4.2.1", "mdast-util-to-string": "4.0.0", + "outvariant": "1.4.2", "patch-package": "8.0.0", "prettier": "3.2.4", "prettier-plugin-astro": "0.13.0", diff --git a/src/pages/404.astro b/src/pages/404.astro index 3ef5a8f..87e5fc5 100644 --- a/src/pages/404.astro +++ b/src/pages/404.astro @@ -1,12 +1,12 @@ --- +import { invariant } from 'outvariant'; import PageHeader from '../components/PageHeader.astro'; import Layout from '../layouts/Layout.astro'; -import invariant from '../lib/tiny-invariant'; const title = 'ページが存在しません'; const searchURL = new URL('https://www.google.com/search'); -invariant(Astro.site); +invariant(Astro.site, 'Invariant failed'); searchURL.searchParams.set('q', `site:${Astro.site.host}`); --- diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro index 0e48495..66f9b69 100644 --- a/src/pages/[...slug].astro +++ b/src/pages/[...slug].astro @@ -1,9 +1,9 @@ --- import { getCollection } from 'astro:content'; +import { invariant } from 'outvariant'; import PageHeader from '../components/PageHeader.astro'; import Layout from '../layouts/Layout.astro'; import { renderDateToHtml } from '../lib/render-date-to-html'; -import invariant from '../lib/tiny-invariant'; export async function getStaticPaths() { return (await getCollection('blog')).map((entry) => ({ @@ -20,6 +20,7 @@ const { Content, remarkPluginFrontmatter } = await entry.render(); invariant( typeof remarkPluginFrontmatter.description === 'string' || typeof remarkPluginFrontmatter.description === 'undefined', + 'Invariant failed', ); --- diff --git a/src/pages/posts-feed.xml.ts b/src/pages/posts-feed.xml.ts index 9c1cce5..c0995ae 100644 --- a/src/pages/posts-feed.xml.ts +++ b/src/pages/posts-feed.xml.ts @@ -1,15 +1,15 @@ import rss from '@astrojs/rss'; import type { APIContext } from 'astro'; import { getCollection } from 'astro:content'; +import { invariant } from 'outvariant'; import { SITE_TITLE, SITE_DESCRIPTION } from '../consts'; -import invariant from '../lib/tiny-invariant'; export async function GET(context: APIContext) { const blogEntries = (await getCollection('blog')) .toSorted((a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf()) .toReversed(); - invariant(context.site); + invariant(context.site, 'Invariant failed'); return rss({ title: SITE_TITLE, @@ -22,6 +22,7 @@ export async function GET(context: APIContext) { invariant( typeof remarkPluginFrontmatter.description === 'string' || typeof remarkPluginFrontmatter.description === 'undefined', + 'Invariant failed', ); return {