Skip to content

Instantly share code, notes, and snippets.

@rjoydip-zz
Last active June 4, 2020 13:40
Show Gist options
  • Save rjoydip-zz/6e934463d8e304792f1fc81241183610 to your computer and use it in GitHub Desktop.
Save rjoydip-zz/6e934463d8e304792f1fc81241183610 to your computer and use it in GitHub Desktop.
Issue on statSync while importing
function hasEnv(): boolean {
try {
return Deno.statSync(".env").isFile;
} catch (_) {
return false;
}
}
async function createEnv(): Promise<void> {
const dockerenv = await Deno.open(".env", {
write: true,
create: true,
});
await Deno.writeAll(dockerenv, new TextEncoder().encode(""));
Deno.close(dockerenv.rid);
}
async function removeEnv(): Promise<void> {
await Deno.remove(".env");
}
console.log(hasEnv());
await createEnv();
console.log(hasEnv());
await removeEnv();
console.log(hasEnv());
import { hasEnv, createEnv, removeEnv } from "./import.ts";
console.log(hasEnv());
await createEnv();
console.log(hasEnv());
await removeEnv();
console.log(hasEnv());
export function hasEnv(): boolean {
try {
return Deno.statSync(".dockerenv").isFile;
} catch (_) {
return false;
}
}
export async function createEnv(): Promise<void> {
const dockerenv = await Deno.open(".env", {
write: true,
create: true,
});
await Deno.writeAll(dockerenv, new TextEncoder().encode(""));
Deno.close(dockerenv.rid);
}
export async function removeEnv(): Promise<void> {
await Deno.remove(".env");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment