r/javascript • • Dec 09 '16

Would you like Babel to support YAML configuration format? (Vote πŸ‘, πŸ‘Ž)

https://github.com/babel/babel/issues/4980
2 Upvotes

37 comments sorted by

18

u/rk06 Dec 09 '16

I prefer the .babelrc.js proposal which will work like eslint and webpack.

My reasoning : we already know js so why bother learning yaml?

1

u/gajus0 Dec 09 '16

I agree! (I apologise in advance for a silly allegory) However, I have a car too, but I don't use it to cross the street. Using a car to cross the street would most certainly involve more accidents, it would break and someone would need to maintain it. (This is cringe worthy allegory, I am so sorry.) The point is, that JavaScript configuration gives developer too much freedom. It will make the configuration hard to read. Various environmental variables (such as Node.js version, etc) will come into play into whether the config itself can be read without transpilation, etc.

In the mean time, YAML provides a finite set of tools that can be used to manipulate the configuration (anchoring, merge and sets). Therefore, complexity of the configuration is restricted to the use of these features. With JavaScript, you have the entire ES engine at your will to produce the configuration.

I am only worried about taking over a project that has .babelrc file that has 100 lines of code and imports 4 more dependencies to execute.

2

u/Retsam19 Dec 09 '16

You can do .babelrc.js without making it hard to read. You don't have to do anything dynamic, currently my .bablerc.js file looks like this:

module.exports = {
    //static JS Object
};

Mostly, I do it this way because like being able to omit quotes and use familiar comment syntax, without having to learn yet another markup language, and while leaving the door open for future dynamic stuff, if I find an appropriate reason for it.

1

u/gajus0 Dec 09 '16

Mostly, I do it this way because like being able to omit quotes and use familiar comment syntax, without having to learn yet another markup language, and while leaving the door open for future dynamic stuff, if I find an appropriate reason for it.

You can already do that using .babelrc. It is using JSON5 (https://babeljs.io/docs/usage/babelrc/). Basically, it is logic-less JavaScript object. The proposal is there specifically to enable logic in the configuration files.

1

u/Retsam19 Dec 09 '16

Huh. TIL.

... is there a way to tell my text editor that it's a JSON5 object? Because otherwise it complains if I don't use proper JSON syntax.

1

u/gajus0 Dec 09 '16

Whats your editor? Atom has it https://atom.io/packages/language-json5. Atom does not highlight invalid JSON. I am not familiar with other IDEs that much.

1

u/Retsam19 Dec 09 '16

I use Atom and it highlights invalid JSON for me, at least the text gets highlighted in red if I don't use quotes.

I'm pretty sure language-json5 only works on files that end in .json5, and I can't do that for .babelrc, I don't think. Or if not, I don't want it to assume that all my JSON files are JSON5.

1

u/gajus0 Dec 09 '16

Open .babelrc. Open console. Type "Grammar", select "JSON5".

1

u/Retsam19 Dec 09 '16

Thanks, I'll keep that in mind for hobby work, but I don't care to tell my entire team that they need to download a new plugin for their various editorsΒ (they don't all use Atom) and then configure the editors to parse the file right, when I could just leave it as a JS file and get all the same benefits anyway.

1

u/rk06 Dec 09 '16

FWIW, i understand your allegory. but I don't agree with its implications.

There are 2 main points:

  • The complexity problems assumes that your js developer is inexperienced. but, your project is based on javascript(why else would you use babel?). if your js developer is inexperienced, you should not be using babel in first place.

  • Your argument implies that yaml will stop developers from shooting their foot. No, it won't there is no such thing as fool proof, they are more likely to not dig deeper into yaml and make different mistakes

1

u/gajus0 Dec 09 '16

The complexity problems assumes that your js developer is inexperienced. but, your project is based on javascript(why else would you use babel?). if your js developer is inexperienced, you should not be using babel in first place.

No, thats not the implication I attempted to construct. The implication is that I can say with confidence what this configuration does:

env:
	development:
		plugins:
			- istanbul
			- transform-es2015-modules-commonjs
			- transform-export-default-name
	production:
		plugins:
			- transform-export-default-name

but I cannot tell with confidence what this does:

{
	plugins: [
		...(foo ? ['istanbul'] : []),
		"transform-es2015-modules-commonjs",
		"transform-export-default-name"
	]
}

What is foo? some variable that the developer constructed in the document.

Your argument implies that yaml will stop developers from shooting their foot. No, it won't there is no such thing as fool proof, they are more likely to not dig deeper into yaml and make different mistakes

Example?

My reasoning is that YAML is mostly static format. There simply isn't much that you can do with it beyond anchoring, merging and sets.

2

u/rk06 Dec 09 '16

your yaml config can be translated into js as

 {
       env: {
           development: {
               plugins: [
                   'istanbul',
                   'transform-es2015-modules-commonjs',
                   'transform-export-default-name',
               ]
           },
           production:{
               plugins:[
                   'transform-export-default-name',
               ]    
           },
 }

so, in the guise of static config, you actually want to alter the structure of config object? Not bad idea! but this matter is unrelated to yaml/js.

There simply isn't much that you can do with it beyond anchoring, merging and sets.

maybe you are right. maybe yaml is the silver bullet we are all searching for! But I don't believe so. Frankly I don't know even know what anchoring, merging and sets are, so arguing any further is useless.

My original point was that yaml config will increase one more thing to learn. While js is something we already know.

Is yaml a good format for config? I am sure it is. But should we use it for a js project when .js option is available? No.

1

u/r2d2_21 Dec 09 '16

Because we don't want config to be Turing-complete?

6

u/[deleted] Dec 09 '16

But it's amazing in webpack config to be able to use require statements and stuff.

-2

u/gajus0 Dec 09 '16 edited Dec 09 '16

Not sure if sarcasm, because the linked issues uses webpack as "when things go too far" (Note: I have nothing against webpack. I am an active contributor to the webpack ecosystem. I am simply referring to the example used in the issue being discussed.)

4

u/[deleted] Dec 09 '16

Nah. I genuinely enjoy using that.

2

u/rk06 Dec 09 '16

Huh?

1

u/r2d2_21 Dec 09 '16

Huh?

0

u/gajus0 Dec 09 '16

Restart the test.

Day 304. No progress.

3

u/[deleted] Dec 09 '16

Anything that accepts comments in it is better than plain old JSON. Even a .js file with module.exports = {} would be a life saver.

6

u/gajus0 Dec 09 '16

/u/BTPL Babel is using JSON5 format. You can use comments in .babelrc file.

1

u/[deleted] Dec 09 '16

Oh? Never tried it, thanks for letting me know!

3

u/[deleted] Dec 09 '16

Whatever. Anything is better than JSON for configuration. Comma issues make me throw a tantrum each time I want to edit a file.

13

u/GameFreak4321 Dec 09 '16

Can't be worse than YAML's tab issues

1

u/gajus0 Dec 09 '16

What issue are you referring to?

3

u/GameFreak4321 Dec 09 '16

YAML is indentation sensitive

2

u/gajus0 Dec 09 '16

By design...

1

u/[deleted] Dec 09 '16

Unless developers work in Vim with some half-arsed config I don't even see it as a problem. How would anyone mess up indentation in this day and age?

1

u/Dmitry_Olyenyov Dec 09 '16

Just by copy&pasting some snippet from internet.

2

u/oweiler Dec 09 '16

Why not use an editor which highlights this as an error?

1

u/Dmitry_Olyenyov Dec 09 '16

And I hate that I have to use a cson "what level I'm at" highlighter plugin for Atom every time I need to add new snippet.

1

u/jordonbiondo Dec 09 '16

js users know js, if they know yaml too and want to use it, then add a conversion step to your startup/build.

3

u/tswaters Dec 09 '16

Alternate proposal? Why not have all of them - make it like eslint.

  • It'll read from .eslintrc and warns you it's deprecated.

  • It'll read from .eslintrc.json and parse as JSON

  • It'll read from .eslintrc.yaml and parse as YAML

  • It'll read from .eslintrc.js and parse as javascript.

If you want to use yaml, use yaml. If you want to use javacsript, require things and have dynamic configuration, that'll work too.

1

u/nobrandheroes Dec 09 '16

I would like Babel to go a bit further and push some form of universal configuration. Like a config.yml file that has a babel key where babel`s configuration goes.

It could be something other projects also use. I don`t get why I have to have so many configuration files in a project.

5

u/gajus0 Dec 09 '16

2

u/nobrandheroes Dec 09 '16

Neat. This is completely new to me. Thanks.