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

Doesn't support object destructuring or accessing process.env object #58

Open
timwis opened this issue Jul 7, 2017 · 2 comments
Open

Comments

@timwis
Copy link
Contributor

timwis commented Jul 7, 2017

It took me about 2 hours of debugging to release this, but when you think about how envify works, it makes sense. I was using object destructuring to cut down on some boilerplate, which works fine in node:

const {
  VAR_A,
  VAR_B,
  VAR_C
} = process.env

And none of them were being set. So I added a console.log(process.env) beneath it, which output {}, and that made me think envify wasn't being executed at all. Of course it's because envify is parsing the file looking for process.env.SOMETHINGHERE literally.

It would be nice if object destructuring were supported, though I can understand why it would be challenging, and accessing process.env would almost always be a mistake (except for debugging). Perhaps the solution here is just to make this more clear in the readme, that this module doesn't actually provide a process.env object; it basically just does string replacing?

@yoshuawuyts
Copy link
Collaborator

it basically just does string replacing

Yep, it's literally a find-and-replace. Such is the nature of most transforms haha. Agree that if it isn't clear we should update the docs. PR welcome!

@3den
Copy link

3den commented Feb 7, 2019

@yoshuawuyts currently the find and replace works if you pass a single var const {VAR_A} = process.env but not if you pass many, I understand that this is because you use a find and replace for /\bprocess\.env\b/ but there is a way that we can make so it support both.

Babel transpiler converts this:

const {A1, B2} = process.env;

To:

var _process$env = process.env,
   A1 = _process$env.A1,
   B2 = _process$env.B2

So if we make the regex a bit more generic we can make it match both cases,
e.g. /\b_?process[\.$]env\b/.

I can send a PR for that if you are ok with this.

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

3 participants