-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: fully support 'extends' for configurations #4407
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work, thanks! I'm a little concerned that yargs/lib/apply-extends
isn't a public API. If it isn't, maybe we can vendor it (e.g., just copy/paste it into a function in lib/cli/options.js
). @bcoe can you comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test seems unit test rather than integration tests. So, test/node-unit/cli/
is better place where we put the test in. What do you think?
Yeah, I think that test should probably live in |
I would be happy to make this a public API, but as this PR stands today, it will be broken by the next major version of yargs, which moves to using an export map. I'd be happy to export this helper though. |
@bcoe If you want to add it to the export map, that'd work for us--we can change our code to use it when we upgrade. |
@mf-pherlihy Are you interested in doing further work on this? I'd like to merge the PR, but the test should probably move. If I don't hear back in a couple days, I'll merge this as-is and fix it after. |
@boneskull Yeah I can finish this up. Just to confirm: 1 . Move to |
|
ping @bcoe @mf-pherlihy |
Yes, my intention was that it's a blessed public helper now. The caveat is that we need to fix this. |
Just tried upgrading yargs and using the defined helpers. Unfortunately however, the latest version breaks a bunch of other tests. |
a957e8f
to
105d1aa
Compare
@mf-pherlihy [email protected] introduces ESM, and was a somewhat major shuffling around of code. I'd be interested in making sure we address any issues you're bumping into with tests. |
@bcoe I did upgrade yargs and yargs-parser with #4543. There have been changes in yargs' array handling with |
@juergba that's good to hear 👍 Sound like we perhaps just need to rebase this and give the helpers another try? |
I guess so, but I haven't taken a look at this PR though. But please go ahead @mf-pherlihy. |
@mf-pherlihy I rebased and tests are passing with yargs public helpers. |
I have to check to which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mf-pherlihy I did some testing and have found quite a few issues:
extends
does not work for relative paths- array typed options: values are not combined, the configuration of yargs-parser seems to be ignored by
applyExtends
. - boolean typed option: is buggy, eg
no-diff: true
gets overwritten by default value:diff: true
- package.json with field
mocha
: haven't tested yet, but ?
As an alternative without yargs public helper:
we just let options.parse()
do the job by passing additional configObjects. The order would be crucial.
configObjects: [{base RC-options}, {extends RC-options}, {base pkg options}, {extends pkg options}]
What do you think?
If we can cover all the issues with yargs-parser and still fix the root issue with extends then im all for it. |
@mf-pherlihy if any of this behavior would make sense in yargs/yargs-parser, happy to take patches. |
👋 Where are we at regarding this PR? |
Note: #4980 also touches this area. We should review them together in case one is a dup. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a reasonable start - and I like the test case!
I'm interested in what you think of this approach compared to #4980's. If possible, it'd be nice to avoid having to reach into lower-level helpers. But I'm not super familiar with yargs and would love to know if that's misguided here. 🙂
const configObject = config ? loadConfig(config) : {}; | ||
|
||
// Set _configPath for use by parse() | ||
configObject._configPath = config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Refactor] I'm not a big fan of setting "magic" properties that are only used by specific other places. They get hard to keep track of and can accidentally end up being exposed to users. Which is what's happening here: loadRc
is a @public
function and thus part of the public API. https://mochajs.org/api/module-lib_cli#.loadRc
I think the root need for this code change is that the config
value also needs to be available in parse()
, right? If so: how about extracting the contents of this if
into a private shared function, then utilizing that function in two places?
if (args.config !== false) {
return myNewFancyFunction(args).configObject;
}
(roughly that, but maybe with more clear naming?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Question] #4980 is also meant to fix extends
, and has less code. It looks like #4980 uses the higher-level yargs/yargs
-> yargs()
instead of this PR's yargs/helpers
-> applyExtends
. I think it's normally cleaner to use higher-level functions when possible. They tend to do more of the work for consumers - as seen in #4980. Is there an advantage to applyExtends
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 @mf-pherlihy was hoping to get your thoughts here. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Praise] Really clean test, nice 🙂
var loadOptions = require('../../lib/cli/options').loadOptions; | ||
|
||
describe('options', function() { | ||
it('Should support extended options', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Style] Nit: other tests in this repo generally lower-case the 's'. For consistency...
it('Should support extended options', function() { | |
it('should support extended options', function() { |
Marking as |
👋 ping @mf-pherlihy, do you still have time for this? |
Closing out as it's been a while since PR activity. If anybody wants to take this over, please do - and post a co-author attribution if you take code from this PR. Cheers! 🤎 |
Requirements
Description of the Change
There have been multiple issues reported where configurations do not actually support the
extends
property:#3916
#4057
I did some digging and found the root cause to be the
options.parse()
method. This method relies onyargs-parser
and NOTyargs
which does the actual configuration extending.It was a pretty straightforward fix. I imported the
yargs
function that extends the configuration objects and then applied it to all the arguments passed toparse()
.I added a test to support this case and verified the test fails when this fix is not applied.
Alternate Designs
There was already an existing PR open that modified external methods to do this, so I wanted to avoid that.
Why should this be in core?
It fixes a long standing bug.
Benefits
Configuration files can now be extended properly.
Possible Drawbacks
I dont see any?
Applicable issues