Allow specifying environment variables in .ember-cli#7910
Allow specifying environment variables in .ember-cli#7910rwjblue merged 1 commit intoember-cli:masterfrom
Conversation
lib/experiments/index.js
Outdated
| primary: path.dirname(cliPath), | ||
| }); | ||
| const experimentsInDotCli = emberCli.get('experiments') || {}; | ||
| Object.assign(process.env, experimentsInDotCli); |
There was a problem hiding this comment.
Hmm, I'd prefer to do this where we do the rest of the yam stuff (around here). I also think that if we are "just" merging with process.env we shouldn't use experiments as the key in .ember-cli (we would use environment or something else)...
There was a problem hiding this comment.
That was my original intention as well but there was an issue with that.
We require models/project here which requires lib/experiments internally. Due to this, the experiments are set even before .ember-cli is loaded.
Placing the Project require below the getConfig also won't help as getConfig again uses lib/experiments internally.
I agree that the key name has to be changed to environment in .ember-cli.
c9c7f6d to
c8665ed
Compare
|
@rwjblue , I have made the suggested changes. Please take a look :) |
|
might be a silly idea but why not teach |
|
@twokul, I am not very convinced about having process.env as a fallback for the following reasons:
Apologies if I have misunderstood your comment :) |
is there something wrong with that? 😄 |
|
@twokul , maybe I am not understanding you here properly but the whole point of this PR was to enable people to put their ENV variables in
Consider an env variable let config = new Yam('ember-cli', {
primary: project_root
secondary: process.env // i believe this is what you are talking about
});
// config will be
{
MY_ENV_VARIABLE: 'some value' // taken from process.env
environment: {
MY_ENV_VARIABLE: 'some_value' // taken from .ember-cli
}
}We will now have to get the values present in the environment field, iterate over them and verify they are not present in One solution I see for this is to make Yam automatically treat values inside the |
|
@rwjblue would really appreciate if you take another look at this. |
rwjblue
left a comment
There was a problem hiding this comment.
I left some questions inline, and a couple small tweaks in the test but other than that this looks really good, thank you for working on it!
lib/cli/index.js
Outdated
| // * env variables passed directly should have more priority over .ember-cli. | ||
| // * process.env will have only string values. Therefore, check if the value | ||
| // in .ember-cli is truthy and then assign to process.env. | ||
| if (!process.env.hasOwnProperty(key) && value) { |
There was a problem hiding this comment.
I think I would do if (!(key in process.env)) {}, also why does value need to be truthy? I'm concerned about null and 0 as values, where a normal process.env.something = null would coerce to 'null'...
There was a problem hiding this comment.
That makes sense, thanks 👍
| '.ember-cli': JSON.stringify({ | ||
| environment: { | ||
| "MY_ENV_VARIABLE": "Yayy", | ||
| "SHOULDNT_BE_THERE": false, |
There was a problem hiding this comment.
Not sure about this one (see question above)
| }); | ||
| })); | ||
|
|
||
| after(co.wrap(function *() { |
There was a problem hiding this comment.
I think you want this to be afterEach
| describe('.ember-cli environment options', function() { | ||
| let sampleApp; | ||
|
|
||
| before(co.wrap(function *() { |
There was a problem hiding this comment.
Seems like it should be beforeEach
133953a to
8a7a329
Compare
8a7a329 to
d825561
Compare
|
@rwjblue , thanks for your time 😄 I have made the suggested changes. |
|
👏 |
|
Thank you @astronomersiva! |
|
Seems to work well here kellyselden/ember-cli-rollup-packager#30. Nice work! |
|
@kellyselden , thanks :) I also noticed that it is possible to have the |
|
Thank you so much for this ❤️ |
|
@astronomersiva there is a problem, if you import before this change: after this change: tested this feature in ember-cli v3.3 |
|
What is the recommended way to access these environment vars in Ember? Looks like I could use the |
|
@lougreenwood your config/environment.js runs during the build process (in node, not the browser) so it has access to environment variables. That’s the typical way to get an env car into your app at runtime. (That doesn’t have anything directly to do with this new feature for automatically setting env vars from the .ember-cli file.) |
|
I'm not sure I follow - are you saying that any values set in the new |
|
Yes. That (and only that) was the intended behavior of this feature. |
|
Nevermind, seems it was an obvious solution for my use case where
If anyone's interested in my use case (or maybe Google is...) I'm trying to define config env vars for my app which has access to process.env for local dev ( This new feature which allows me to define them in
My config definitions are now much cleaner and more robust as a result and also improves my Cordova build pipeline :) |


Addresses #7896.
Makes it possible to specify environment variables in
.ember-clilike