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

refactcor(dotenv): prepare for noUncheckedIndexedAccess #4261

Merged
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
16 changes: 8 additions & 8 deletions dotenv/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export function loadSync(

if (defaultsPath) {
const confDefaults = parseFileSync(defaultsPath);
for (const key in confDefaults) {
for (const [key, value] of Object.entries(confDefaults)) {
if (!(key in conf)) {
conf[key] = confDefaults[key];
conf[key] = value;
}
}
}
Expand All @@ -89,9 +89,9 @@ export function loadSync(
}

if (_export) {
for (const key in conf) {
for (const [key, value] of Object.entries(conf)) {
if (Deno.env.get(key) !== undefined) continue;
Deno.env.set(key, conf[key]);
Deno.env.set(key, value);
}
}

Expand Down Expand Up @@ -283,9 +283,9 @@ export async function load(

if (defaultsPath) {
const confDefaults = await parseFile(defaultsPath);
for (const key in confDefaults) {
for (const [key, value] of Object.entries(confDefaults)) {
if (!(key in conf)) {
conf[key] = confDefaults[key];
conf[key] = value;
}
}
}
Expand All @@ -296,9 +296,9 @@ export async function load(
}

if (_export) {
for (const key in conf) {
for (const [key, value] of Object.entries(conf)) {
if (Deno.env.get(key) !== undefined) continue;
Deno.env.set(key, conf[key]);
Deno.env.set(key, value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions dotenv/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function expandCharacters(str: string): string {

return str.replace(
/\\([nrt])/g,
($1: keyof CharactersMap): string => charactersMap[$1],
($1: keyof CharactersMap): string => charactersMap[$1] || "",
);
}

Expand Down Expand Up @@ -89,7 +89,7 @@ export function parse(rawDotenv: string): Record<string, string> {
//https://github.com/motdotla/dotenv-expand/blob/ed5fea5bf517a09fd743ce2c63150e88c8a5f6d1/lib/main.js#L23
const variablesMap = { ...env };
keysForExpandCheck.forEach((key) => {
env[key] = expand(env[key], variablesMap);
env[key] = expand(env[key]!, variablesMap);
});

return env;
Expand Down
2 changes: 1 addition & 1 deletion dotenv/parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Deno.test("parse()", () => {
);

assertEquals(
JSON.parse(load.JSON).foo,
JSON.parse(load.JSON || JSON.stringify({})).foo,
"bar",
"inner quotes are maintained",
);
Expand Down
Loading