Files
photo-live/packages/storage/test/load-env.ts
T
2026-09-17 20:25:18 +08:00

17 lines
705 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// packages/storage/test/load-env.ts —— 与 services/api/test/load-env.ts 同约定:
// Jest 侧唯一 env 来源是仓库根 .env。本包嵌套层级与 api 不同(packages/storage/test
// vs services/api/test),故向上查找 pnpm-workspace.yaml 定位仓库根,不硬编码层数。
import { existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { config } from 'dotenv';
let dir = __dirname;
while (!existsSync(join(dir, 'pnpm-workspace.yaml'))) {
const parent = dirname(dir);
if (parent === dir) {
throw new Error('load-env: 未找到 pnpm-workspace.yaml,无法定位仓库根(.env)');
}
dir = parent;
}
config({ path: join(dir, '.env') });