gleam-lang / packages

📦 Search for Gleam packages
https://packages.gleam.run/
Apache License 2.0
69 stars 13 forks source link

Add support for loading environment variables from `.env` file #13

Closed maxdeviant closed 1 year ago

maxdeviant commented 1 year ago

This PR adds support for loading environment variables from a .env file to improve local DX.

This is using my new Gleam package, glenvy for loading the file.

Motivation

When I first started hacking on packages I ran into some rather unhelpful error messages when trying to run gleam run server or gleam run sync:

exception error: #{function => <<"server">>,gleam_error => assert,line => 62,
                   message => <<"Assertion pattern match failed">>,
                   module => <<"packages">>,
                   value => {error,nil}}
  in function  packages:server/0 (/Users/maxdeviant/projects/gleam-packages/build/dev/erlang/packages/_gleam_artefacts/packages.erl, line 51)⏎ 

I eventually figured out that this was due to an assertion failing due to missing environment variables.

I've been using a local justfile (for just) while working on packages as a way to source the environment variables from my .env file:

set dotenv-load

test:
    gleam test

run:
    gleam run server

sync:
    gleam run sync

Of course, I figured it would be better if we could just support .env files out of the box 🙂

maxdeviant commented 1 year ago

Also, I totally understand if you'd rather not pull in such a green 🌱 dependency into this project.

lpil commented 1 year ago

Closing due to inactivity, please feel free to reopen