From fa217ce0f2183fccb17ae0a1ed7db06e105f0aad Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Mon, 12 Jan 2026 00:43:59 +0800 Subject: [PATCH] feat: add justfile --- justfile | 9 +++++++++ libraries/deno-commons-mod.ts | 27 +++++++++++++++++---------- libraries/deno-teencrypt-mod.ts | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 justfile diff --git a/justfile b/justfile new file mode 100644 index 0000000..e7e8a77 --- /dev/null +++ b/justfile @@ -0,0 +1,9 @@ +alias tl:=test-libraries + +_: + @just --list + +# test all libraries +test-libraries: + deno test --allow-all libraries/* + diff --git a/libraries/deno-commons-mod.ts b/libraries/deno-commons-mod.ts index 0f89035..7cf1ed0 100644 --- a/libraries/deno-commons-mod.ts +++ b/libraries/deno-commons-mod.ts @@ -42,25 +42,21 @@ export function isOn(val: string | undefined | null): boolean { lowerVal === "true"; } -export async function getEnv(key: string): Promise { +export function getEnv(envKey: string): string | null { const homeDir = getHomeDir(); - if ((homeDir !== null) && key) { - const envValue = await readFileToString( - `${homeDir}/.config/envs/${key}`, + if ((homeDir !== null) && envKey) { + const envValue = readFileToStringSync( + `${homeDir}/.config/envs/${envKey}`, ); if (envValue !== null) { return envValue.trim(); } } - return Deno.env.get(key) || null; + return Deno.env.get(envKey) || null; } export function isEnvOn(envKey: string): boolean { - return isOn(Deno.env.get(envKey)); -} - -export async function isEnvOnAsync(envKey: string): Promise { - return isOn(await getEnv(envKey)); + return isOn(getEnv(envKey)); } export function formatHumanTime(timeMillis: number): string { @@ -311,6 +307,17 @@ export async function readFileToString( } } +export function readFileToStringSync(filename: string): string | null { + try { + return Deno.readTextFileSync(resolveFilename(filename)); + } catch (e) { + if (e instanceof Error && e.name == "NotFound") { + return null; + } + throw e; + } +} + export async function writeStringToFile( filename: string, data: string | null, diff --git a/libraries/deno-teencrypt-mod.ts b/libraries/deno-teencrypt-mod.ts index d4d2da4..5b5ed97 100644 --- a/libraries/deno-teencrypt-mod.ts +++ b/libraries/deno-teencrypt-mod.ts @@ -3,7 +3,7 @@ import { encodeBase64Url, getHomeDirOrDie, hexStringToUint8Array, -} from "https://global.hatter.ink/script/get/@8/deno-commons-mod.ts"; +} from "https://global.hatter.ink/script/get/@9/deno-commons-mod.ts"; import {getRandomValues} from "node:crypto"; import {assertEquals} from "jsr:@std/assert";