Skip to content
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

Load .env/.dev.vars file based on --env #2073

Merged
merged 2 commits into from
Nov 8, 2022
Merged

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented Oct 24, 2022

If --env <env> is specified, we'll now check .env.<env>/.dev.vars.<env> first. If they don't exist, we'll fallback to .env/.dev.vars.

--env is now a flag in every command, like --config.

Closes #1305.

@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2022

🦋 Changeset detected

Latest commit: ab8eda3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/3419511356/npm-package-wrangler-2073

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/2073/npm-package-wrangler-2073

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/3419511356/npm-package-wrangler-2073 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.developers.workers.dev/runs/3419511356/npm-package-cloudflare-pages-shared-2073

@codecov
Copy link

codecov bot commented Oct 24, 2022

Codecov Report

Merging #2073 (ab8eda3) into main (49b6a48) will increase coverage by 0.10%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2073      +/-   ##
==========================================
+ Coverage   73.41%   73.51%   +0.10%     
==========================================
  Files         139      139              
  Lines        8965     8999      +34     
  Branches     2327     2339      +12     
==========================================
+ Hits         6582     6616      +34     
  Misses       2383     2383              
Impacted Files Coverage Δ
packages/wrangler/src/pubsub/pubsub-commands.tsx 60.35% <ø> (ø)
packages/wrangler/src/config/index.ts 93.33% <100.00%> (+0.74%) ⬆️
packages/wrangler/src/d1/index.ts 80.00% <100.00%> (ø)
packages/wrangler/src/delete.ts 100.00% <100.00%> (ø)
packages/wrangler/src/deprecated/index.ts 83.78% <100.00%> (ø)
packages/wrangler/src/dev.tsx 87.73% <100.00%> (ø)
packages/wrangler/src/dev/dev-vars.ts 100.00% <100.00%> (ø)
packages/wrangler/src/dispatch-namespace.ts 100.00% <100.00%> (ø)
packages/wrangler/src/index.tsx 83.79% <100.00%> (+0.46%) ⬆️
packages/wrangler/src/init.ts 96.05% <100.00%> (ø)
... and 12 more

@GregBrimble
Copy link
Member

Have you considered .<env>.env instead? I imagine IDEs which do INI style formatting will expect the file to have a .env extension. (I haven't actually tested this)

@petebacondarwin
Copy link
Contributor

Have you considered .<env>.env instead? I imagine IDEs which do INI style formatting will expect the file to have a .env extension. (I haven't actually tested this)

I think that keeping the extension constant would be sensible.

@GregBrimble
Copy link
Member

Interesting that the new Turbopack uses .env.<xyz>: https://turbo.build/pack/docs/features/environment-variables#env-files

@mrbbot
Copy link
Contributor Author

mrbbot commented Oct 26, 2022

.env.<xyz> seems to be the standard, https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use, https://vitejs.dev/guide/env-and-mode.html#env-files, ...

Could always add support for both <xyz>.env and .env.<xyz>?

@GregBrimble
Copy link
Member

Nah, I think I was wrong in my comment. I just assumed people would want to keep the .env extension, but if everyone else is going with suffixes for environments, then let's just do the same.

@mrbbot mrbbot force-pushed the bcoll/env-env-dev-vars branch 3 times, most recently from 71a2260 to 9af3273 Compare November 8, 2022 12:32
Copy link
Member

@GregBrimble GregBrimble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hold off merging just a minute until we confirm if global --env is what we want to do

If `--env <env>` is specified, we'll now check `.env.<env>`/`.dev.vars.<env>`
first. If they don't exist, we'll fallback to `.env`/`.dev.vars`.

`--env` is now a flag in every command, like `--config`.

Closes #1305.
@mrbbot mrbbot merged commit 1987a79 into main Nov 8, 2022
@mrbbot mrbbot deleted the bcoll/env-env-dev-vars branch November 8, 2022 13:21
@github-actions github-actions bot mentioned this pull request Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: --env + .env/.dev.vars (environment support for build/runtime vars)
4 participants