The env-loader package is our custom solution for ingesting environment variables from multiple sources using the commander
package.
It collects variables from:
- the CMS environment's defined feature flags
- which CMS enviroment determined via
NEXT_PUBLIC_BASE_DRUPAL_URL
env var
- appropriate
.env
file inenvs/
based on theAPP_ENV
env var
- (defaults to
.env.local
)
- CLI options included with the command
After collecting (and overwriting values as needed based on the order above), all env vars are set and the command runs. Keep in mind the ordering. If the same environment variable is set in both the CMS feature flags and in the .env file, the value in the .env file will be chosen.
For a full list of CLI options available, see cli-options.tsx
If you need to pass a CLI flag to an underlying command, you can use --
to separate options. Any flags after the --
will be directed to the underlying process instead of our env-loader logic.
For example, yarn test
runs the Jest tests. Running yarn test -- -u
will pass the -u
flag to the underlying jest command being run with yarn test
(equivalent to running jest -u
).
Running yarn test -u
will not pass to the underlying jest command and will have no effect, as -u
is not a defined CLI option for env-loader
.