1// Repository tools reuse the shipped package's dotenv parsing and loading so2// both sides of the repo read `.env` identically. Only the named-subset3// helpers below are repo-tool-specific.4import { environmentNames, parseDotenv } from "../package/tooling/environment.ts";56export { loadEnvironment, parseDotenv } from "../package/tooling/environment.ts";78export function mergeEnvironment(9 fileEnvironment: Readonly<Record<string, string>>,10 processLookup: (name: string) => string | undefined,11): Record<string, string> {12 return mergeNamedEnvironment(environmentNames, fileEnvironment, processLookup);13}1415export function mergeNamedEnvironment(16 names: readonly string[],17 fileEnvironment: Readonly<Record<string, string>>,18 processLookup: (name: string) => string | undefined,19): Record<string, string> {20 return Object.fromEntries(21 names.map((name) => [name, processLookup(name) ?? fileEnvironment[name] ?? ""]),22 );23}2425export async function loadNamedEnvironment(26 names: readonly string[],27 path = ".env",28 processLookup: (name: string) => string | undefined = (name) => Deno.env.get(name),29): Promise<Record<string, string>> {30 let fileEnvironment: Record<string, string> = {};31 try {32 fileEnvironment = parseDotenv(await Deno.readTextFile(path));33 } catch (error) {34 if (!(error instanceof Deno.errors.NotFound)) throw error;35 }36 return mergeNamedEnvironment(names, fileEnvironment, processLookup);37}