question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[pre-pull request] --mode switch

See original GitHub issue

I didn’t know where to put this and I didn’t want to submit a pull request for unfinished / possibly unwanted additions.

BUT

I forked and added a --mode switch that gets parsed during the ‘getDotenvFilenames’ Fn that should make your module treat .env files the same as vue-cli. (this was more convenient for my team)

Basically if the switch exists it looks for .env.{mode} or .env.{mode}.local files instead of NODE_ENV files, though it will still default to using NODE_ENV as the mode.

function getDotenvFilenames(cwd) {
  const { NODE_ENV = 'development' } = process.env;

  let modeI = process.argv.indexOf("--mode")
  let mode = (modeI != -1 && process.argv.length > modeI + 1) ?
    process.argv[modeI + 1] :
    NODE_ENV

  return [
    NODE_ENV && `${cwd}/.env.${mode}.local`,
    NODE_ENV && `${cwd}/.env.${mode}`,
    NODE_ENV !== 'test' && `${cwd}/.env.local`,
    `${cwd}/.env`
  ].filter(filename => filename && fs.existsSync(filename));
}

If this seems like an addition that would fit I’ll write up some actual testing cases before submitting a pull request.

(if you look in my fork you will also notice that I changed NODE_ENV to default to ‘development’, I don’t plan on including this in a possible pull request.)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
solaris765commented, Dec 12, 2018

Oh I see. That might be a handy override, and no command line switch needed. I think that’s a much better option then my original proposed change.

1reaction
solaris765commented, Dec 12, 2018

Ah. That makes sense. And thanks for the tip on Cammander.js, I hadn’t seen that.

The main reason I decided to keep NODE_ENV and mode separate was because in our use case NODE_ENV is used inside the program to differentiate production vs development or whatever.

And .env files seemed like a good option to start storing those sorts of configurations in a central more manageable location. Though I see now it may have been better to use one or the other and not get stuck between both like I have.

Thank you very much for the input and your work on this tool!

Really it helped a lot!

(edit: spelling)

Read more comments on GitHub >

github_iconTop Results From Across the Web

pre-pull hook? - Google Groups
The pre-pull hook we would write would do something like this: It would dump the ... (or "porcelain-level", as Git devs would call...
Read more >
Pre-Pull Data for Recipes with Data Sync - Salesforce Help
Use data sync to pull data to CRM Analytics on a regular schedule. By scheduling sync from Salesforce and remote systems ahead of...
Read more >
Is there any git hook for pull? - Stack Overflow
Say I just pulled 2 new file, if you change the whole folder's ownership, it's costs more time and server resources(cpu usage, memory...
Read more >
Pre-Pull Request: D3D11 Initial testing - Torque3D
Once you get the game fired up, ensure you can switch to the D3D11 ... is when you are in Windowed Mode (Maximize)...
Read more >
Introduction to New Relic CodeStream
Select some code and then click the add comment button. ... Get feedback on work-in-progress with pre-Pull Request code review.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found