Conversation
8dcdf0c to
5a5dd78
Compare
Codecov Report
@@ Coverage Diff @@
## 7.0 #4892 +/- ##
=========================================
+ Coverage 85.27% 85.4% +0.12%
=========================================
Files 203 203
Lines 9531 9532 +1
Branches 2690 2702 +12
=========================================
+ Hits 8128 8141 +13
+ Misses 915 904 -11
+ Partials 488 487 -1
Continue to review full report at Codecov.
|
d267574 to
31e3d5f
Compare
| throw err; | ||
| if (path.extname(loc) === ".js") { | ||
| try { | ||
| options = require(loc); |
There was a problem hiding this comment.
Might be worth checking for a .default prop on the returned object. Someone could be using babel-register and have export default {} for .babelrc.js
There was a problem hiding this comment.
Hadn't considered that - thanks. Updated!
|
Thinking about this more, I'm personally a bit hesitant to support dynamic config. We've discussed in the past having a babel init command that can generate a config for you. I think it would be huge if you could use the same tooling to allow editing your existing configuration (adding new plugins, configuring preset options, etc). If we allow dynamic configuration, we won't be able to programmatically modify the config, and then serialize it back to disk. |
|
@DrewML Do you think it would be harmful to simply not support JS configs with that new feature? I ask because I feel like those who prefer dynamic JS configs would most likely not be interested in a CLI tool that manages it for you anyway. We already do have the Didn't know about the discussion about a |
|
@DrewML why not just call |
@ORESoftware That doesn't solve the use-case I am referencing. That would verify that the value returned from evaluating the file is serializable. If someone has a JS configuration, we can't make modifications to the parsed value, and then blow away their JS and replace it with JSON. |
|
@DrewML yeah but when would you overwrite the user provided config, and write it back to the filesystem? Probably never, right? Or are you? Their of course are projects that do this, but it doesn't get written back to the developer's source code. I do see it as a slightly risky move. |
It is an idea relating to a bigger discussion we've had regarding how to make editing the |
|
@DrewML this one is easy. Have both .babelrc and .babelrc.js. The latter is optional, the former required. The latter requires/imports the former and can override things. Babel edits the former. might be kind of annoying to implement though, and there might be some gotchas in there. In general, I like dynamic config and using .js instead of .json, that's just my preference. I like Webpacks use of .js config and suman also will use .js config. |
|
I don't think it's the greatest solution to require anyone that wants to write their config in JS maintain 2 separate files for configuration. I'm much prefer @kaicataldo's solution of just not having any tooling like that support custom |
|
@DrewML sure, I don't have anything at stake in this particular convo, just adding my 2 cents. I am more interested in the issue regarding dynamically specifying the exact path to .babelrc |
|
Cool! No worries. |
@kaicataldo You do make a good point. It's also, in no way, set in stone that we'd be implementing CLI editing of existing config. Just an idea I had floated at one point. |
|
@DrewML so you put an idea above something that would already work? |
|
@ForsakenHarmony Nothing has been put above anything. This is a discussion. |
|
Might have misunderstood something
On Thu, 15 Dec 2016, 18:08 Andrew Levine, ***@***.***> wrote:
@ForsakenHarmony <https://github.com/ForsakenHarmony> Nothing has been
put above anything. This is a discussion.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4892 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AIb6dCxsfMkWy21zWc9L8a-dE9rSy36Vks5rIXQrgaJpZM4K7UEv>
.
--
Sincerely, Tim Ullmann
|
|
Personally I would leave If both files are present, it might be best to just warn the user, or it could be an optional feature that passes the contents of |
|
@hzoo @loganfsmyth @danez @Kovensky @existentialism Anyone else have any opinions on this? |
|
Not sure if this should be posted in this PR or on the corresponding issues, so i'm just dropping it here. At first, one might say most users will still use .babelrc vs .babelrc.js files to configure their compilation and that only advanced ones will benefit from it. That said, it also allows for cleaner ways to configure the compilation, for example NODE_ENV based specific options. All can benefit from that. Supporting the .js format will also allow for more creativity in the babel community (I have in mind it would allow the end-user to extend a plugin exporting a babel .js configuration via its main). Regarding the loading, IMO the .js file should have the higher priority, and if it loaded, the resolution should stop. That way experienced user could also leverage the const generated = JSON.parse(require('fs').readFileSync('./.babelrc'));
module.exports = Object.assign(generated, {
// dynamic stuff
});With that in mind I don't see how a tool enabling the user to generate JSON5 .babelrc files will create backward compatibility issues, while it benefits all the users. |
|
Any other thoughts on what we want to do about this? |
|
I don't have a strong opinion on this but I would prefer an API in Babel to allow to run it with a given configuration object. This would allow user to implement whatever configuration they want (#4980). I aggree with @DrewML, users will have more flexebility but will also be a lot more error prone. I think #4970 (Specifying a different file (different filename, same file type) for config other than .babelrc) could solve this and why not #5039 (Add support for DOTFILES_PATH environment variable). To be clear, I think dynamic configuration should be done using Babel's API. |
|
@hzoo Looks like you thumbed the original comment at the top, but what are your thoughts? I'm still pretty new to the project - so I might be missing something here - but supporting different file types in ESLint has been pretty unproblematic. |
|
I think JS based config files are extremely useful and also quite common e.g. ESLint, Webpack, and PostCSS all support JS config files. In my experience it is quite common to change the value of some config option based on an environment variable, or to want to share some common value between different config files e.g. between babel and webpack. Would love to see this land. |
| assert.deepEqual(chain, expected); | ||
| }); | ||
|
|
||
| it("js-json-config - should use .babelrc if both are present", function () { |
There was a problem hiding this comment.
Ok I think we should be erroring if there's both a .babelrc and a .babelrc.js since there doesn't need to be both at the same level
There was a problem hiding this comment.
That does feel like better behavior than defaulting to one (currently .babelrc)
|
Nice work on this one!! 🎉 |
|
Appreciate all the input on this one ❤️ |
|
Hooray! 🎉 |
|
Would you be so kind as to backport this to 6.x? Otherwise what is the ETA on 7.x stable release? This feature would help me preserve my sanity when dealing with a particular preset 😄 |
| this.errorMultipleConfigs(arr.pop(), config); | ||
| } | ||
|
|
||
| arr.push(config); |
There was a problem hiding this comment.
Looking into #5543 (comment), it looks like there is a regression here. This should be
if (configAdded) arr.push(config);
otherwise it will always stop at the first package.json it encounters, even if it doesn't contain a "babel" key. While I actually like that behavior, we should probably do it on purpose instead of on accident :P Would you be up for PRing a fix, or should I?
There was a problem hiding this comment.
I'm happy to make a PR - thanks for the heads up!
|
has this been released? I'm finding that the babel compiler doesnt notice my |
|
you'll need to use 7.0 (alpha), or wait |
|
@MrLoh I ended up being forced to sidestep babelrc by directly configuring babel via babel-loader and using the |
|
Possible workaround (works for me): {
"presets": [
"./.babelrc.js"
]
}Just create the Afterwards you can just remove |
|
This is awesome! Any reason I shouldn't suggest to people that they do this? |
|
Not really, I probably would of suggested it earlier really 😄 , pretty funny though |
|
In some cases there may be problems with caching when changing the contents of But that's only when changing the config, no other problems. |
Took a stab at adding support for .babelrc.js configuration files. Backfilled a test for when .babelrc contains malformed JSON. Let me know what you think!