-
Notifications
You must be signed in to change notification settings - Fork 97
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
Implements #23, report which config files were loaded #33
base: master
Are you sure you want to change the base?
Conversation
can you describe your situation? what did you need the file locations for? |
Two reasons really - the first is it's a nice sanity check to tell people where their config is coming from on application startup (for example if over the course of trying out an application, they drop config files all over the place then get confused as to why their latest change doesn't appear to be picked up), and also because the app I'm writing lets people update their config file programatically - for that it's helpful to know where the config files are loaded from. |
interesting! this is a good point actually! okay I think there is enough need to justify this feature, but what is the best way to implement it? so should the config files be a list? maybe they should be named? rc can only load config from 5 places, named file (--config or ${appname}_config), local file (./.{appname}rc, ../.{appname}rc, etc) user file ( it feels a little ugly to expose _rcFiles with a _ in front, is there another way we could do this? also asking @mikermcneil since he has contributed a lot to rc. |
My gut feeling is that exposing the fact that location one missed, locations two, three and four hit and location five missed is exposing too much of the internals. As a consumer of the module, I just want to know where the config file(s) were loaded from but I'd rather leave anything else up to rc and not have to worry about it. A list also retains the order of precedence with very little effort. The Whatever it's called, it should definitely not be an enumerable property, in case it the config object gets JSONified at any point (served to a web browser or whatever). |
Good point. Hmm... What if there was another method with the same function signature that returned an array of "source metadata" in order of preference? Eg
|
Err "preference" should be "precedence" (sorry, on my phone) |
so it'd be something like |
@mikermcneil attaching the function to rc's exports is good, because then it can't collide with the retried options. I would prefer a horse name, instead of a bactrian name... what about |
I like horses :p |
Isn't this already covered by |
I've also run a situation similar to #23 where it would be useful to report which configuration files were actually loaded by rc, so have added support for a
_rcfiles
property to be added to the returned configuration object which contains the list of files, along with tests and a section documenting it in the readme.It works by passing an array into the json util method - when it parses a json/ini file, it adds the name of the file to the list. The list is then added to the configuration object as a non-enumerable property.
I hope this is helpful, please let me know if you have any comments.