Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2.5 #5

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/bun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: antongolub/action-setup-bun@v1.12.8
- uses: actions/checkout@v4
- uses: antongolub/action-setup-bun@v1.13.1
with:
bun-version: v1.x # Uses latest bun 1
- run: bun x jsr add @cross/test @std/assert @cross/runtime @cross/deepmerge # Installs dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
node-version: [18.x, 21.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: npx jsr add @cross/test @std/assert @cross/deepmerge @cross/runtime
- run: "echo '{ \"type\": \"module\" }' > package.json" # Needed for tsx to work
- run: npx --yes tsx --test tests/*.test.ts
5 changes: 2 additions & 3 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"name": "@cross/env",
"version": "0.2.4",
"version": "0.2.5",
"exports": "./mod.ts",

"tasks": {
"test": "cd tests && deno test --allow-env --allow-read",
"publish": "deno publish --config jsr.jsonc",
"publish-dry": "deno publish --dry-run --config jsr.jsonc"
"publish-dry": "deno publish --dry-run"
},
"lock": false,
"fmt": {
Expand Down
14 changes: 9 additions & 5 deletions lib/filehandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { readFile } from "node:fs/promises";
*
* @param {Runtimes} currentRuntime - The current runtime environment.
* @param {EnvOptions} options - setup options.
* @param {boolean} failSilentlyOnError - supress errors and warnings while reading file.
* @returns {Record<string, string>} A object of parsed environment variables.
* @throws {UnsupportedEnvironmentError} If the runtime is unsupported and the 'throwErrors' flag is set.
* @throws {FileReadError} If there's an error reading the .env file and the 'throwErrors' flag is set.
*/
export async function loadEnvFile(
currentRuntime: string,
options: EnvOptions,
failSilentlyOnError: boolean,
): Promise<Record<string, string>> {
const filePath = options.dotEnv?.path ? options.dotEnv.path : ".env";
let fileContent = "";
Expand All @@ -38,11 +40,13 @@ export async function loadEnvFile(
break;
}
} catch (err) {
if (options.throwErrors) {
throw new FileReadError(err.message);
}
if (options.logWarnings) {
console.warn(err.message);
if (!failSilentlyOnError) {
if (options.throwErrors) {
throw new FileReadError(err.message);
}
if (options.logWarnings) {
console.warn(err.message);
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ export async function setupEnv(options?: EnvOptions) {
throwErrors = mergedOptions.throwErrors!;
logWarnings = mergedOptions.logWarnings!;

if (mergedOptions.dotEnv) {
if (mergedOptions.dotEnv?.enabled) {
const failSilentlyOnError = options.dotEnv?.enabled ? false : true;
const currentRuntime = getCurrentRuntime();
const envVars = await loadEnvFile(currentRuntime, mergedOptions);
const envVars = await loadEnvFile(currentRuntime, mergedOptions, failSilentlyOnError);

switch (currentRuntime) {
case "deno":
Expand Down
Loading