Skip to content
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

Port CoffeeScript to ES6 #35

Merged
merged 22 commits into from
Aug 26, 2016
Merged

Port CoffeeScript to ES6 #35

merged 22 commits into from
Aug 26, 2016

Conversation

devongovett
Copy link
Member

I started this project over 3 years ago now, as a part of PDFKit which was written in CoffeeScript. At the time, CoffeeScript provided a nice syntax on top of JavaScript, especially with it's class syntax and other features. It served my projects well, but it's time to move on. CoffeeScript hasn't received major updates in quite some time now, and won't be getting a lot of the nice features in ES6. ES6 borrowed many of it's features from CoffeeScript, so why not just move to ES6?

There are several reasons to move, but the biggest for me is encouraging outside contribution. Simply, more people know and are willing to contribute to projects written in JavaScript than CoffeeScript. Also, as I mentioned before, ES6 has many of CoffeeScript's good parts, infused with some other cool stuff. I've been working on other projects with it, and really enjoy it.

I used decaffinate to do the initial port, and then cleaned up the result by hand. Decaffinate isn't perfect, but it was a HUGE help in doing this, so thanks to @eventualbuddha for that project.

Still working on cleaning up some stuff, but tests are passing which is a good sign.

@bramstein
Copy link

How much work is left for this to be merged in? Anything I can help out with?

@jwerre
Copy link

jwerre commented Jun 29, 2016

I'm also happy to help with this.

@devongovett
Copy link
Member Author

I mostly want to review all of the converted files and clean up any formatting things left behind by decaffinate. Sorry I've been slow on this, super busy lately. Will get on it soon.

@jahewson
Copy link

jahewson commented Jun 29, 2016

Hi Devon, I have a few thoughts on some small structural changes to the upcoming ES6 code so that it plays nice with webpack. I also have some TypeScript annotations if you're interested.

@devongovett
Copy link
Member Author

@jahewson feel free to share your thoughts about webpack. Have a link to the typescript annotations?

@Pomax
Copy link
Contributor

Pomax commented Jun 30, 2016

As is the constant case in JS, new bundlers keep popping up - if this is still in the "trying to make it work" stages, it might be worth having a quick look to see if rollup gets the job done.

@eventualbuddha
Copy link

As one of the maintainers of rollup and creator of decaffeinate, I support that 😉

@jahewson
Copy link

jahewson commented Jul 10, 2016

I've now published my TypeScript definitions to jahewson/fontkit-types. The definition includes a few todo comments where the underlying API makes things tricky - worth looking into.

As far as webpack goes, one hurdle has been that the dependency on fs isn't needed in the browser but results in webpack pulling in the sizeable brfs dependency.

Another issue is that the different modules which make up fontkit have interdependencies which cause the entirety of fontkit to be bundled, no matter how few features are used. For example, I don't need subsetting but because each Font exposes a createSubset function, and imports the relevant XXXSubset module, webpack thinks that I need that module too. One solution to this would be to construct a Subset from a Font, rather than having a Font construct a Subset.

Likewise because I don't need to save files, I don't need the encoding parts of restructure, which get pulled in by webpack too.

Probably the biggest issue is that I can't ship support for only certain font formats, I don't need DFont, WOFF, or WOFF2, but because they all get registered, they all get bundled. I think the registering API really needs to be made explicit.

Overall, adding a bit more import boilerplate would really make things more modular.

@devongovett
Copy link
Member Author

You can require('fontkit/base') to load it without any font formats enabled, then manually register the formats you want with e.g.fontkit.registerFormat(require('fontkit/src/TTFFont'));.

As for other stuff, rollup might be able to help here with its tree shaking features...

@jahewson
Copy link

jahewson commented Jul 11, 2016

I use a mix of ES5 and ES6 code, so Rollup isn't an option for me. I have everything working with webpack - it's just that the config is a hand-coded pile of hacks. Requiring fontkit/base is cool though, that's exactly what I had in mind.

@devongovett devongovett changed the title [WIP] Port CoffeeScript to ES6 Port CoffeeScript to ES6 Aug 26, 2016
@devongovett devongovett merged commit 95ab7c7 into master Aug 26, 2016
@devongovett devongovett deleted the es6 branch August 26, 2016 15:44
@devongovett
Copy link
Member Author

Merged! Published to npm in v1.4.0.

Updated the build process a bit. Now using Babel 6, and Rollup before publishing to npm. Still including the ES6 source in the package though, for custom builds.

@teoxoy
Copy link

teoxoy commented Nov 16, 2019

@jahewson are the typescript definitions still available somewhere?

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.

7 participants