UNPKG

@tsed/config

Version:
30 lines (29 loc) 883 B
import { watch } from "node:fs"; import { join } from "node:path"; import dotenvExpand from "dotenv-expand"; import dotenv from "dotenv-flow"; import { globby } from "globby"; import { EnvsConfigSource } from "../envs/EnvsConfigSource.js"; export class DotEnvsConfigSource extends EnvsConfigSource { getAll() { dotenvExpand.expand(dotenv.config(this.options)); return super.getAll(); } async watch(onChange) { const files = await globby(join(this.options.path, ".env"), { dot: true, absolute: true }); const watchers = files.map((file) => { const watcher = watch(file, onChange); return () => { watcher.close(); }; }); return () => { watchers.map((close) => { return close(); }); }; } }