How does CoffeeScript support work in writing package?

The reason why I ask is that I wish to write packages in LiveScript (life changing for me). LiveScript dev (outside package) works great by simply adding those LiveScript transpiler package.

I’ve been researching for some days and seems no one does that before. It doesn’t work by simply adding

Npm.depends({
  "livescript": "1.4.0"
});

Meteor chain was broken by it.

Looking into the compiled packages written in CoffeeScript, they got wrapped well. What treatment has .coffee got by Meteor in the process of package compilation ?

Let me know if there’s any package example written in LiveScript. Thanks!

Sure enough, writing package in livescript and compile to .js is not too bad an option. Just curious how does coffeescript get it’s first-class citizen treatment.

m… guess I need to take a look at the source: :grin:
https://github.com/meteor/meteor/tree/devel/packages/coffeescript

1 Like

Also potentially useful to look at: https://github.com/Dessix/Meteor-LiveScript

That’s only the standard livescript transpiler wrapper. Same as using the Npm livescript dependency. It doesn’t do what the official coffeescript support do.

I don’t know what you mean, it compiles all the .ls files in the package to .js files. What does the coffeescript package offer what Meteor-LiveScript doesn’t?

The coffeescript package uses a build plugin to compile all .coffee files to javascript files. Check this line in package.js file and the plugin source. It first registers to handle some extensions and then compiles source files. It also creates sourcemaps and stuff. I wrote one for iced-coffee-script some days back.

Yes, I use Meteor-LiveScript daily for App dev. But that doesn’t work for writing packages…

e.g. the follow works as expected in package:

  api.use(['coffeescript'],['client']);
  ...
  api.addFiles('lib/my_script.coffee',['client']);

But Not

  api.use(['<I tried a few livescript compilers>'],['client']);
  ...
  api.addFiles('lib/my_script.ls',['client']);

No build error, but Meteor App is blank. Checking into browser console, it’ll complaint that basic Meteor objects such as UI not defined etc… Guess .ls compiled but without proper wrapping like coffee has, it breaks Meteor. (Again, I’m talking about package writing only…)

Did anyone actually write packages in .ls with success? I’d like to see a working example.

Sounds like an obvious solution, but did you include the meteor packages you are using from my_script.ls (usually mentioned right up the very top of the list of browser console errors) in that package’s package.js? Because if you have no other errors, it sounds like what you’re trying has already worked!

There’s no magic to how the coffeescript package works, and you can easily make your own BuildPlugin yourself. I made one that reads JSON files and makes them available on the client and/or server as local Mongo collections. HTML is also parsed in a similar way in meteor. At the end you just get a bunch of .js files, regardless whether the original source file was a .html, .coffee, .ls or collection.json