Skip to content

Merge oldest parent first #1404

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

Closed
wants to merge 4 commits into from

Conversation

willemneal
Copy link
Contributor

@willemneal willemneal commented Jul 21, 2020

This adds more tests and changes the order of merges so that cli > target > options > parent.target ...

Now adding expected.json, which will be checked if --showConfig is passed to the test runner.

Changed addDefaults to return a new options object instead of editing the passed one.

Willem Wyndham added 2 commits July 21, 2020 11:58
This adds more tests and changes the order of merges so that cli > target > options > parent.target ...
cli/asc.js Outdated
@@ -298,43 +317,33 @@ exports.main = function main(argv, options, callback) {
return p;
});
}
args = optionsUtil.merge(exports.options, args, asconfig.options);
args = optionsUtil.merge(exports.options, asconfig.options, args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong order. The asconfig options need to be overridden by cli args.

The options.merge function puts the parent as the third parameter, preferring the second argument.

Did I miss something or mis-implement this algorithm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Just added more tests and sure enough it ignores the CLI args. The issue was that the defaults for the args was being set before the config properties were being added. So if you treat args as the current config it will prioritize the defaults. I just changed it to not add the defaults right away so we can get just the args passed and things seem to work.

This way the "default" args aren't ever in the current config when merging.
@dcodeIO
Copy link
Member

dcodeIO commented Jul 21, 2020

The fixes to util/options look fine, but I'm wondering if most of the state keeping in cli/asc can be avoided. For instance, the intended order for the merge algorithm (preferring current over parent) was to start with parsed CLI args, and then subsequently merge the next set of options taking precedence over what's still to merge, i.e.

current = parse(..., false)
while (asConfig = getNextAsconfig()) {
  if (asConfig.target) {
    current = merge(current, asConfig.target)
  }
  current = merge(current, asConfig.options)
}
current = addDefaults(current)
// use current

Can you elaborate why this isn't working, i.e. needs temporary cliArgs, an array of configs etc.?

Kept cliArgs since args's defaults are needed.
@willemneal
Copy link
Contributor Author

We need to split up the CLI args because the defaults in args are needed, e.g. args.target, args.config. I took your advice and removed the configs array and returned to @jtenner's original design.

@dcodeIO dcodeIO mentioned this pull request Jul 22, 2020
1 task
const opts = optionsUtil.parse(argv, exports.options);
let args = opts.options;
const opts = optionsUtil.parse(argv, exports.options, false);
let args = optionsUtil.addDefaults(exports.options, opts.options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is happening too early, and is instead intended to be performed as the last step once CLI args and asconfigs have been fully processed. For that, we just need to apply the defaults for target and config early, independently of populating their values. Can either hardcode these or pull them from the config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed addDefaults so that it returns a new object. This way opts.options is untouched. Then at the end of the config it is merged back into args. It was the only way I found that fixed the issues your having in #1406.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I suspect that the underlying issue is that the relative path transform is applied to imported file names, in turn stripping the . from ./a, resulting in the packages test trying to find a, which resolves differently. While the changes in ordering here apparently prevent this, somehow, that doesn't look like a proper fix.

@willemneal willemneal closed this Jul 23, 2020
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

Successfully merging this pull request may close these issues.

3 participants