-
Notifications
You must be signed in to change notification settings - Fork 365
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
feat: inject environment variables from .env files into edge functions locally #5620
Conversation
📊 Benchmark resultsComparing with f30d409 Package size: 302 MB(no change)
|
* @param {Record<string, { sources: string[], value: string}>} env | ||
* @return {void} | ||
*/ | ||
export const injectEnvVariables = (env) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this function to only inject variables into process.env
and split out all the dotenv stuff into the function above.
@@ -96,7 +96,8 @@ const dev = async (options, command) => { | |||
log(`${NETLIFYDEVLOG} Injecting environment variable values for ${chalk.yellow('all scopes')}`) | |||
} | |||
|
|||
await injectEnvVariables({ devConfig, env, site }) | |||
env = await addDotEnvVariables({ devConfig, env, site }) | |||
injectEnvVariables(env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addDotEnvVariables
now mutates env
here and adds the variables from the dot-env files to it, so that later one we can use them in edge-functions. Previously dotenv variables were only added to process.env
directly.
@@ -1,4 +1,4 @@ | |||
// Handlers are meant to be async outside tests | |||
const { platform } = require('os') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out what this comment means or where it applies to :D
@danez - I'm not sure what part of this PR you want me to review. I took a look through and couldn't identify any changes that will impact what's shown in the cli docs at https://deploy-preview-5620--cli.netlify.app/ Could you point me to the part of this PR that needs my review? I do see that docs.netlify.com documents some limitations around this behavior that will need to be updated/removed (on the Environment variables and functions page and the Edge Functions limits page)- I can open a PR to get the ball rolling on those changes. |
Sorry, i didn't mean to ask for a review. I just wanted to let you know that this is something that is changing which we might want to document :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Left a couple of comments but nothing blocking.
3494edb
to
252a386
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Summary
This allows any environment variables that are coming from dot-env files (
.env
) to be accessed in edge functions.Similar to what is described here: https://docs.netlify.com/configure-builds/environment-variables/#build-locally
For us to review and ship your PR efficiently, please perform the following steps:
passes our tests.
A picture of a cute animal (not mandatory, but encouraged)