From 87df5a27cb34ada02f54dacf4299574f04038612 Mon Sep 17 00:00:00 2001 From: João Augusto Costa Branco Marado Torres Date: Sun, 6 Jul 2025 15:10:35 -0300 Subject: fix: env name conflict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Augusto Costa Branco Marado Torres --- src/components/BaseHead.astro | 2 +- src/components/Footer.astro | 2 +- src/env.d.ts | 2 +- src/lib/env.ts | 68 ------------------------------------------ src/lib/environment.ts | 68 ++++++++++++++++++++++++++++++++++++++++++ src/lib/pgp/trust.ts | 2 +- src/lib/pgp/verify.ts | 2 +- src/pages/.well-known/onion.ts | 2 +- src/pages/index.astro | 2 +- src/pages/rss.xml.ts | 2 +- 10 files changed, 76 insertions(+), 76 deletions(-) delete mode 100644 src/lib/env.ts create mode 100644 src/lib/environment.ts (limited to 'src') diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index 65e568c..885447c 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -1,5 +1,5 @@ --- -import { env } from "@lib/env"; +import { env } from "@lib/environment"; import "../styles/global.css"; import { ClientRouter } from "astro:transitions"; diff --git a/src/components/Footer.astro b/src/components/Footer.astro index c3dffca..3238c50 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -1,5 +1,5 @@ --- -import { env } from "@lib/env"; +import { env } from "@lib/environment"; const { PUBLIC_GIT_URL, diff --git a/src/env.d.ts b/src/env.d.ts index 588193b..9a4ed32 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -1,4 +1,4 @@ -import type { env } from "./lib/env.ts"; +import type { env } from "./lib/environment.ts"; type ImportMetaEnv = typeof env; diff --git a/src/lib/env.ts b/src/lib/env.ts deleted file mode 100644 index 679c76f..0000000 --- a/src/lib/env.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { createEnv } from "@t3-oss/env-core"; -import { z } from "astro:content"; - -export const env = createEnv({ - server: { - TRUSTED_KEYS_DIR: z.string().superRefine((val, ctx) => { - let url: URL; - const cwd = new URL(`file://${Deno.cwd()}/`); - try { - url = new URL(val, cwd); - } catch { - ctx.addIssue({ - code: "custom", - message: `${cwd}${val} doesn't exist`, - fatal: true, - }); - return; - } - - const { isDirectory } = Deno.statSync(url); - - if (isDirectory) return; - - ctx.addIssue({ - code: "custom", - message: `${url} it's not a directory`, - fatal: true, - }); - }).transform((val) => new URL(val, new URL(`file://${Deno.cwd()}/`))), - }, - - /** - * The prefix that client-side variables must have. This is enforced both at - * a type-level and at runtime. - */ - clientPrefix: "PUBLIC_", - client: { - PUBLIC_SITE_URL: z.string().url(), - PUBLIC_SITE_TITLE: z.string().trim().min(1), - PUBLIC_SITE_DESCRIPTION: z.string().trim().min(1), - PUBLIC_SITE_AUTHOR: z.string().trim().min(1), - PUBLIC_GIT_URL: z.string().url(), - PUBLIC_TOR_URL: z.string().url().optional(), - PUBLIC_GIT_TOR_URL: z.string().url().optional(), - PUBLIC_SIMPLE_X_ADDRESS: z.string().url().optional(), - }, - - /** - * What object holds the environment variables at runtime. This is usually - * `process.env` or `import.meta.env`. - */ - runtimeEnv: import.meta.env ?? Deno.env.toObject(), - - /** - * By default, this library will feed the environment variables directly to - * the Zod validator. - * - * This means that if you have an empty string for a value that is supposed - * to be a number (e.g. `PORT=` in a ".env" file), Zod will incorrectly flag - * it as a type mismatch violation. Additionally, if you have an empty string - * for a value that is supposed to be a string with a default value (e.g. - * `DOMAIN=` in an ".env" file), the default value will never be applied. - * - * In order to solve these issues, we recommend that all new projects - * explicitly specify this option as true. - */ - emptyStringAsUndefined: true, -}); diff --git a/src/lib/environment.ts b/src/lib/environment.ts new file mode 100644 index 0000000..679c76f --- /dev/null +++ b/src/lib/environment.ts @@ -0,0 +1,68 @@ +import { createEnv } from "@t3-oss/env-core"; +import { z } from "astro:content"; + +export const env = createEnv({ + server: { + TRUSTED_KEYS_DIR: z.string().superRefine((val, ctx) => { + let url: URL; + const cwd = new URL(`file://${Deno.cwd()}/`); + try { + url = new URL(val, cwd); + } catch { + ctx.addIssue({ + code: "custom", + message: `${cwd}${val} doesn't exist`, + fatal: true, + }); + return; + } + + const { isDirectory } = Deno.statSync(url); + + if (isDirectory) return; + + ctx.addIssue({ + code: "custom", + message: `${url} it's not a directory`, + fatal: true, + }); + }).transform((val) => new URL(val, new URL(`file://${Deno.cwd()}/`))), + }, + + /** + * The prefix that client-side variables must have. This is enforced both at + * a type-level and at runtime. + */ + clientPrefix: "PUBLIC_", + client: { + PUBLIC_SITE_URL: z.string().url(), + PUBLIC_SITE_TITLE: z.string().trim().min(1), + PUBLIC_SITE_DESCRIPTION: z.string().trim().min(1), + PUBLIC_SITE_AUTHOR: z.string().trim().min(1), + PUBLIC_GIT_URL: z.string().url(), + PUBLIC_TOR_URL: z.string().url().optional(), + PUBLIC_GIT_TOR_URL: z.string().url().optional(), + PUBLIC_SIMPLE_X_ADDRESS: z.string().url().optional(), + }, + + /** + * What object holds the environment variables at runtime. This is usually + * `process.env` or `import.meta.env`. + */ + runtimeEnv: import.meta.env ?? Deno.env.toObject(), + + /** + * By default, this library will feed the environment variables directly to + * the Zod validator. + * + * This means that if you have an empty string for a value that is supposed + * to be a number (e.g. `PORT=` in a ".env" file), Zod will incorrectly flag + * it as a type mismatch violation. Additionally, if you have an empty string + * for a value that is supposed to be a string with a default value (e.g. + * `DOMAIN=` in an ".env" file), the default value will never be applied. + * + * In order to solve these issues, we recommend that all new projects + * explicitly specify this option as true. + */ + emptyStringAsUndefined: true, +}); diff --git a/src/lib/pgp/trust.ts b/src/lib/pgp/trust.ts index 34d454b..a79a2b6 100644 --- a/src/lib/pgp/trust.ts +++ b/src/lib/pgp/trust.ts @@ -2,7 +2,7 @@ import type { Key } from "npm:openpgp@^6.1.1"; import { createKeysFromDir } from "./create.ts"; import type { AsyncYieldType } from "../../utils/iterator.ts"; import { equal, getCall } from "../../utils/anonymous.ts"; -import { env } from "../env.ts"; +import { env } from "../environment.ts"; let trusted: | Iterable>> diff --git a/src/lib/pgp/verify.ts b/src/lib/pgp/verify.ts index f37c0bb..026b6df 100644 --- a/src/lib/pgp/verify.ts +++ b/src/lib/pgp/verify.ts @@ -23,7 +23,7 @@ import { Packet, Signature } from "./sign.ts"; import type { Commit } from "../git/types.ts"; import { findMapAsync, type MaybeIterable } from "../../utils/iterator.ts"; import { getUserIDsFromKey } from "./user.ts"; -import { env } from "../env.ts"; +import { env } from "../environment.ts"; type DataURL = [URL, URL?]; type Corrupted = [false] | [true, Error]; diff --git a/src/pages/.well-known/onion.ts b/src/pages/.well-known/onion.ts index 552b5eb..5b1bc8c 100644 --- a/src/pages/.well-known/onion.ts +++ b/src/pages/.well-known/onion.ts @@ -1,5 +1,5 @@ import type { APIRoute } from "astro"; -import { env } from "../../lib/env.ts"; +import { env } from "../../lib/environment.ts"; const { PUBLIC_TOR_URL } = env; export const GET: APIRoute = (): Response => { diff --git a/src/pages/index.astro b/src/pages/index.astro index 7e506bd..1c80a76 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -8,7 +8,7 @@ import { isOriginal, sortLastUpdated, } from "@lib/collection/helpers"; -import { env } from "@lib/env"; +import { env } from "@lib/environment"; const { PUBLIC_SITE_TITLE } = env; diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index c07f3bd..85aa079 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -3,7 +3,7 @@ import { getCollection } from "astro:content"; import type { APIContext, APIRoute } from "astro"; import { Blog } from "../lib/collection/schemas.ts"; import { getFirstAuthorEmail } from "../lib/collection/helpers.ts"; -import { env } from "../lib/env.ts"; +import { env } from "../lib/environment.ts"; const { PUBLIC_SITE_TITLE, PUBLIC_SITE_DESCRIPTION, PUBLIC_SITE_URL } = env; -- cgit v1.2.3