|
|
@@ -4,6 +4,25 @@ |
|
|
|
* @param filename An optional file name to use instead of `.env`. |
|
|
|
*/ |
|
|
|
export default async function minimal_dotenv(filename = ".env"): Promise<void> { |
|
|
|
// Request permission to read the .env file. |
|
|
|
const readPermission = await Deno.permissions.request({ |
|
|
|
name: "read", |
|
|
|
path: filename, |
|
|
|
}); |
|
|
|
if (readPermission.state !== "granted") { |
|
|
|
throw new Error( |
|
|
|
"Read permission not granted (use --allow-read to skip the prompt)", |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// Request permission to access the environment. |
|
|
|
const envPermission = await Deno.permissions.request({ name: "env" }); |
|
|
|
if (envPermission.state !== "granted") { |
|
|
|
throw new Error( |
|
|
|
"Environment permission not granted (use --allow-env to skip the prompt)", |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// Read and decode the .env file. |
|
|
|
const decoder = new TextDecoder("utf8"); |
|
|
|
const contents = decoder.decode(await Deno.readFile(filename)); |
|
|
|