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

Plugin overwrites original functions #47

Open
ctorgalson opened this issue Feb 22, 2022 · 1 comment
Open

Plugin overwrites original functions #47

ctorgalson opened this issue Feb 22, 2022 · 1 comment

Comments

@ctorgalson
Copy link

ctorgalson commented Feb 22, 2022

Thanks for this plugin, it fills a big gap in Netlify's tooling.

It is very possible that I've missed something important, so I apologise if I'm reporting an issue that can be addressed by configuration!

Can you let me know if it sounds like I've misconfigured the plugin based on what I say below? If it seems like something that should be fixed, I'm happy to work on a patch/PR .


The basic problem we've seen is that the plugin doesn't rewrites the function in place. This causes three problems, one trivial, and two serious

  1. it rewrites the functions with different babel settings than the project's own settings (this is the trivial one 😃),
  2. it removes the process.env.VARIABLE from the original file, so the function is not transformed on subsequent builds (this is more serious),
  3. it writes the actual values into the functions (this is the most serious one),

Obviously (2) and (3) are what the plugin is for, but writing potentially sensitive env var values into the originals causes problems:

  • it becomes easy to accidentally commit a sensitive environment variable value (like an API key, etc) to the repository,
  • it becomes easy to commit a prod or development variable to the repository, introducing bugs (like using a development API key on production or vice-versa).

I'm not deeply familiar with Netlify's build process, but it seems like it might work to do something like this:

  • retain the plugin's existing defaults so it's default behaviour doesn't change,
  • provide an input directory parameter for the plugin to read functions from,
  • continue to use the functions directory specified in netlify.toml to write functions to,

This way, it would be possible to create functions in a directory like e.g. functions, and output them (on Netlify build events) to a git-ignored directory like e.g. functions_replaced. This git-ignored directory would be the functions directory in netlify.toml.

@danielthedifficult
Copy link

Hello @bencao, and thanks for the great plugin.

I'm having this issue as well - when running netlify build on my local machine, this plugin will update/rewrite my local function source code, instead of inlining the variables into the built (.zipped) function code. I wonder if this can be fixed?

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

No branches or pull requests

2 participants