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
Better error messaging when preset options are given without a corresponding preset #4685
Conversation
3a964e6
to
7672129
Compare
You can use the PR template to ref #4677 (if this is the one you are talking about) |
Sorry, used hub and missed the template. Will fill it out! |
42c753d
to
2c0a21b
Compare
Current coverage is 88.83% (diff: 100%)@@ master #4685 diff @@
==========================================
Files 195 195
Lines 13794 13795 +1
Methods 1427 1427
Messages 0 0
Branches 3176 3176
==========================================
+ Hits 12254 12255 +1
Misses 1540 1540
Partials 0 0
|
92d41c3
to
b386e3a
Compare
|
||
if (removed[key]) { | ||
this.log.error(`Using removed Babel 5 option: ${alias}.${key} - ${removed[key].message}`, ReferenceError); | ||
} else if (opts.presets && Array.isArray(opts.presets)) { | ||
for (let i = 0; i < opts.presets.length; i++) { | ||
let preset = opts.presets[i]; |
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.
if you want you can do a for of
here: for (preset of opts.presets) {
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.
Happy to change if that's the preference :)
for (let i = 0; i < opts.presets.length; i++) { | ||
let preset = opts.presets[i]; | ||
if (typeof preset === "object" && preset !== null && !Array.isArray(preset)) { | ||
this.log.error(`Found configuration options ${JSON.stringify(opts)} without corresponding preset. ${presetConfigInfo}`); |
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.
Should we give an example here (it would be kinda long) or is the link fine?
{
"presets": [
["presetHere", { presetOptions: "here"}] // wrap preset/options in an array
]
}
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.
Seemed like a lot to log, which is why I put the link in. Can add that in if you think it's better though!
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.
Yeah we can go with the link too - dono what others think. I tend to like being verbose
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.
no blockers just comments
3c693aa
to
8fdfb5e
Compare
So i'm testing this myself in a new project and it doesn't look like it's correct? The tests are correct but it's not the same options I tried doing
and where you are doing |
Weird, I thought my tests covered that? Looking into it |
The tests I added don't actually fail now. They were definitely failing before, because I remember having to add a "real" fixture preset for one of them (was erroring that the non-existent preset didn't accept options). |
What I did was a |
Oh, I figured it out - |
Now that I have reliable tests, this test is failing (correctly) with my changes: https://github.com/babel/babel/blob/master/packages/babel-core/test/api.js#L191 It looks like objects are allowed sometimes - when is that? Is it only if it has the For example, one of the test errors is showing that this object is in the
Thanks for the guidance on this one! |
Is this maybe the resulting config created by presets? Hmmm...If so, this is trickier than I first thought, because what we actually get back here is the mutated config option rather than the original configuration written by the user. This might be the wrong place to throw this error then, since at this point we have no knowledge of what the original config was. |
I think the issue is that objects are allowed because that is what the preset ends up being (an object with certain keys like plugins/presets). You can totally define a preset inline as an object if you are using the api (not a babelrc which is just json) |
0830d57
to
9b05c74
Compare
After my investigation and our discussion, here's the simpler and more reliable solution of just giving more helpful information in the logged error. |
Cool thanks |
Checking for the presence of thepresets
array inmergeOptions
and then checking the elements in that array seems like the best way to do this to me. The other place I looked at putting this check was in resolvePresets, but that didn't seem as reliable as this (lots more cases to account for).Let me know if you had something else or a better solution in mind!Edit: See comment below