-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implements .env file support #5531
Conversation
Will this allow to use any variables from .env in .yarnrc.yml? For example: injectEnvironmentFiles:
- .env
npmScopes:
myScope:
npmAlwaysAuth: true
npmAuthToken: "${NPM_TOKEN:-}" #From .env
npmRegistryServer: "https://customgitlab/api/v4/packages/npm" |
I forgot to add a test case covering it but I think it should. |
Worth to mention that injectEnvironmentFiles: [] # <-- works
injectEnvironmentFiles: null # <-- Internal Error: ENOENT: no such file or directory, open '/home/sebastien/github/nextjs-monorepo-example/null' |
Added some concerns here: #5544 (comment) Myself I'd recommend to make it 'opt-in'. It will create issues with few projects (ie nextjs...) |
May I ask which version will be this released? |
It will be in v4, you can use one of the release candidates if you want. yarn set version canary |
I was trying it out, thanks. Its worth noting that if you specify a env file that does not exist, you get an error, which means the use-case of .env.user that is git ignored is bad dx (the user needs to create an empty env file in order to run yarn install) |
It doesn't error if you suffix the path with a question mark (ie |
Perfect, thanks - that works. I just discovered it also errors when I run the command to setup my editor
which must be a bug? (edit - easy to work around by adding ?) |
For anyone having trouble with using env variable substitution in |
What's the problem this PR addresses?
A common need is to provide environment values into the environment via
.env
files. There's been a couple of issues and attempts at implementation already, which all were decently upvoted. I myself could have used it once or twice 😄Props to @jj811208 for his implementation in #4835 - I wanted to make the configuration a little more generic (allowing to have multiple environment files, and to possibly disable it altogether), but it was a appreciated start.
Fixes #4718
Closes #4835 (Supercedes it)
How did you fix it?
A new setting,
injectEnvironmentFiles
, lets you define files that Yarn will load and inject into all scripts. It only affects subprocesses - Yarn itself still usesprocess.env
for its checks, so you can't for example setYARN_*
values and expect them to be applied to the current process (use the yarnrc file for that instead).The
injectEnvironmentFiles
setting has a few properties:.env
?
- in that case, Yarn won't throw if the file doesn't existThe idea with this last property is to allow for simple user configuration (imagine, with the example below, that the project also has a gitignore with
.env.*
):Checklist