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
Setup babel #214
Setup babel #214
Conversation
(about the build -> this is just coveralls complaining) |
var Mode = require('stat-mode'); | ||
var noop = function(){}; | ||
var path = require('path'); | ||
var rm = require('rimraf').sync; | ||
var fixture = path.resolve.bind(path, __dirname, 'fixtures'); | ||
|
||
var Metalsmith = require('..').Metalsmith; |
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.
Woah. Isn't this breaking backwards compatibility if we change the way Metalsmith is imported?
I discovered afterward that this was a bug from babel 6, and just foud this workaround: |
@Ajedi32 . |
"build": "make build" | ||
}, | ||
"engines": { | ||
"node": ">=4.0.0" |
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.
I think this change from your previous PR got mixed in by mistake...
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.
or maybe, I should test if it works on 0.10, and then add it.
No?
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, if you want to go ahead and add Node 0.10 to the Travis build, and if the tests pass we can make that the minimum Node version.
0.10 not working because of I consider that wouldn't be bad to drop this dependency. |
Yep. Looks like one of our dependency's dependencies uses generator functions. 😉 I actually do plan to replace Or alternately if doing that proves difficult, just change the minimum Node version to 0.12.0 (and either stop testing 0.10 in Travis, or add it as an allowed failure) and I'll restore 0.10 support as part of my refactoring. |
One more thing we probably want to consider before merging this PR is source maps for our test coverage reports. Right now Coveralls is showing this: https://coveralls.io/builds/4727897/source?filename=lib%2Findex.js We might be able to get this working by turning on source maps in Babel and upgrading to Istanbul 1.0.0-alpha.2, based on this comment: gotwarlost/istanbul#212 (comment) |
@-mkdir bin | ||
$(BABEL) bin-src/metalsmith > bin/metalsmith | ||
$(BABEL) bin-src/_metalsmith > bin/_metalsmith | ||
@chmod u+x bin/* |
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.
You might be able to tweak this to be a bit more elegant and more efficient on repeated builds. make
can be a surprisingly powerful tool in situations like this. Definitely not a big deal, but I'll look into it later today.
The async await will require some babel to be set up. Since we are gonna throw About coverage. |
Yeah, I'd normally be a bit nervous about using an This isn't something we have to worry about causing problems for Metalsmith's users if we use it. |
Alternately, we could try switching to a tool like isparta. |
It's more on the point, having to readadapt changes they made up to 1.0. about isparta dunno. never heard about it and there seems to be some major pending issues |
Yeah, fair enough. It would be kind of annoying if something broke while upgrading from the alpha to the stable release. On the other hand though, assuming we don't have to change anything while upgrading from 0.4.1 to 1.0.0-alpha.2, then any changes we have to make later while upgrading to the stable version of 1.0.0 after its release will be changes we'd have had to make anyway, right? The way I see it, we have basically four options here:
Assuming we can get source mapped test coverage working with Istanbul v1.0.0-alpha.2 and don't notice any major problems with it I personally feel like that's the best option. That's certainly up for debate though. If you have an alternate solution you want to pursue please let me know. |
Also, one other change I just realized this PR needs is an .npmignore file: https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package If we don't include that, npm won't include any of the transpiled destination files in the published package (since those folders are in .gitignore). |
And oh yeah, I almost forgot. For option 4, Lab is a possibility (#215) as it supports source maps for test coverage. It doesn't support promises though hapijs/lab#79, which could get kind of annoying once I start refactoring code to use ES6 features like async/await (which are basically just sugar over promises). |
I'll tend more on option 4 and lab, but might be biased. About async/await, start to look. |
@Ajedi32 what do you want we add to the |
@AdrieanKhisbe Yeah, I've read articles like that before. They definitely make good points, but so far I'm not really convinced. In this particular instance, that article seems to be arguing not only against async/await, but also generator functions, which we're already using. Additionally, the alternative it recommends, just using promises directly, is fully compatible with the use of async/await. (Since it's basically just sugar on top of using Promises.) So overall it's not something I think we need to worry about too much, since you can always just use async/await when you can and switch to Promises where you need them. It is definitely something I plan to keep in mind though in case I start running into similar problems to those mentioned in the article. And ah, I didn't realize we already had an |
Ah, in the second half of the article it looks like they're arguing generators are more powerful than async/await since they lets you define your own execution engine. Missed that part. I agree that is true, but on the flip side there's also some degree of complexity that goes along with that. In Metalsmith we've solved that problem by outsourcing our execution engine to the |
So to summarize the current changes needed to this PR, we need to:
|
@Ajedi32 It might be wise to switch to a https://github.com/ben-eb/postcss-color-yiq/blob/master/package.json#L11-L14 Sourcemap configuration with babel is pretty easy; I use this setup:
https://github.com/ben-eb/postcss-color-yiq/blob/master/.babelrc You can ignore sourcemaps when not in development by passing a different environment to babel; https://github.com/ben-eb/postcss-color-yiq/blob/master/package.json#L8 For testing I use AVA and nyc for all new projects, works great so far with coveralls. I wrote a little guide that might be of use: https://github.com/sindresorhus/ava/blob/master/docs/recipes/code-coverage.md Here's the same project on coveralls: https://coveralls.io/github/ben-eb/postcss-color-yiq Hope this helps! |
I do agree. Will do Thanks @ben-eb to the tips and pointers. will dig into this and apply in the week. :) |
@ben-eb Thanks, that's definitely helpful. My current thoughts on this:
Regarding what tool to use to generate source mapped coverage reports (for now anway; once again we can always switch later if we ultimately switch over to a different test framework), I still think using the istanbul alpha release is a good option, but I'd also accept a solution using Isparta seems to be a very popular choice at the moment. A little Googling for ES6 test coverage reveals tons of blog posts about solving this problem and most of the ones I've seen so far use isparta. (Example: https://onsen.io/blog/mocha-chaijs-unit-test-coverage-es6/ ) |
@ben-eb Use of
|
@Ajedi32 Unless I'm mistaken (I don't find a use for source maps most of the time) source maps are only necessary in the tests for istanbul to accurately map the covered lines of ES5 back to the original ES2015. So my setup will run Agreed that any consideration for another test runner should be considered a separate issue as it would be a big change. (Note that nyc is basically istanbul with sub-process support, however). |
I think source maps can be useful in development as they allow things like remapping stack traces to the source code, displaying source instead of transpiled code in debuggers and things like that. (I don't know how much of that functionality node has built-in, but it looks like there's a module for stack trace support at least.) That's why I suggested it might be useful to leave them in for development (and possibly in the published package too, though it's debatable whether end users would even bother to try debugging errors originating in transpiled Metalsmith code). |
@Ajedi32 Yeah, that's how I have it set up too; the babel environment defaults to |
@ben-eb Right, but I guess as long as you always manually rerun babel after |
I am a bit busy theses days. Just discovered https://github.com/normalize/mz with nzgb post: https://twitter.com/nzgb/status/693081182158790658 Might be a cool think to use this in refactor! (easily simplifying things!) (I'll come back reread in depth previous comment when I'll have more bandwith 😃 ) |
Yeah, switching to a Promise-based API for the Node core methods that we're using is definitely something that should happen once we switch to ES6. |
Promises are available in Node 4 stable, without the need of Babel. |
@RobLoach True, but as of right now we're still supporting Node 0.10. Using Babel would allow us to continue supporting Node 0.10 while also using promises. Additionally, the advantages of consuming a promise-based API are much more pronounced once you have the ability to use async/await, which isn't available in Node 4 without Babel. |
@Ajedi32 do we really really need the async await? |
@AdrieanKhisbe What costs are you referring to? You mean the overhead of Babel and difficulty of implementation? async/await isn't the only ES6 feature which would be made available by Babel FYI, there's a whole list of them here: https://kangax.github.io/compat-table/es6/ (Compare the Node 4.x column with the Babel column). async/await is just the feature I think we'd see the most benefit from. |
I I mean in tooling, maintenance issue, and other code related. Not a fan of but it's not my call :) |
Closing because in conflict, outdated |
Implement #207 \o/
(might even be working on node 0.10)