This PR introduces a new configuration option pattern. It allows users to define a custom naming convention for .env* files that dotenv-flow will read.
The default value for the pattern option is ".env[.node_env][.local]" which is fully backward-compatible with the current dotenv-flow's naming convention.
Description
options.pattern allows you to change the default .env* files' naming convention if you want to have a specific file naming structure for maintaining your environment variables' files.
Default Value
The default value ".env[.node_env][.local]" makes dotenv-flow look up and load the following files in order:
.env
.env.local
.env.${NODE_ENV}
.env.${NODE_ENV}.local
For example, when the proess.env.NODE_ENV (or options.node_env) is set to "development", dotenv-flow will be looking for and parsing (if found) the following files:
.env
.env.local
.env.development
.env.development.local
Custom Patterns
Here are a couple of examples of customizing the .env* files naming convention:
For example, if you set the pattern to ".env/[local/]env[.node_env]", dotenv-flow will look for these files instead:
.env/env
.env/local/env
.env/env.development
.env/local/env.development
… or if you set the pattern to ".env/[.node_env/].env[.node_env][.local]", the plugin will try to find and parse:
BREAKING CHANGE: .listFiles() (exposed internal API method) doesn't receive dirname anymore and returns a list of filenames without the full path (just the name of the file).
Summary
This PR introduces a new configuration option
pattern
. It allows users to define a custom naming convention for.env*
files that dotenv-flow will read.The default value for the
pattern
option is".env[.node_env][.local]"
which is fully backward-compatible with the current dotenv-flow's naming convention.Description
options.pattern
allows you to change the default.env*
files' naming convention if you want to have a specific file naming structure for maintaining your environment variables' files.Default Value
The default value
".env[.node_env][.local]"
makes dotenv-flow look up and load the following files in order:.env
.env.local
.env.${NODE_ENV}
.env.${NODE_ENV}.local
For example, when the
proess.env.NODE_ENV
(oroptions.node_env
) is set to"development"
, dotenv-flow will be looking for and parsing (if found) the following files:.env
.env.local
.env.development
.env.development.local
Custom Patterns
Here are a couple of examples of customizing the
.env*
files naming convention:For example, if you set the pattern to
".env/[local/]env[.node_env]"
, dotenv-flow will look for these files instead:.env/env
.env/local/env
.env/env.development
.env/local/env.development
… or if you set the pattern to
".env/[.node_env/].env[.node_env][.local]"
, the plugin will try to find and parse:.env/.env
.env/.env.local
.env/development/.env.development
.env/development/.env.development.local
› Please refer to
.listFiles([options])
to dive deeper.BREAKING CHANGE:
.listFiles()
(exposed internal API method) doesn't receivedirname
anymore and returns a list of filenames without the full path (just the name of the file).