Opinion: Compile package on install?


#1

I’ve followed several “CoffeeScript vs JavaScript” threads on this forum, partly because I was interested in performance. I’m still not entirely sure if deploying packages as JavaScript will speed up Atom’s load-time, but I’m under the impression there’s a very little gain.

Anyway, as amazing as ES6 is, I still prefer CoffeeScript for its legibility (Ruby habits die hard!) I know Visual Studio Code extensions are often compiled at install-time, so I was thinking about doing the same for Atom packages.

Here’s my approach:

// package.json
"devDependencies": {
    "coffee-script": "^1.11.0"
},
"scripts": {
    "postinstall": "./node_modules/coffee-script/bin/coffee -o lib/ -c src/*.coffee"
}

Any thoughts on this? Has anybody tried something similar? Is this an production-ready approach?

And ultimately – is it worth it? :wink:


#2

Atom automatically compiles CoffeeScript files into JS when they are require(...)d. You don’t have to add devDependencies or scripts to use CoffeeScript in Atom (unless I’m not understanding your question correctly).

CoffeeScript compiles into (more or less optimized) JavaScript and you can develop a package without having to worry about setting up the CoffeeScript compiler, so I really think it comes down to personal preference.

About Atom’s load time: CoffeeScript does not affect the startup time because Atom only compiles/recompiles CoffeeScript when it loads a package for the first time (or you remove the compile-cache folder manually).

About performance: The performance differences between CoffeeScript and JS are so small that your coding skills have a much bigger impact on performance. [citation needed]

Of course that’s just my opinion :grin:


#3

Yes, I was aware of that, but I wondered if it makes sense do this once on install time. As I’ve already mentioned, the only reason I gave this some thought is Visual Studio Code.


#4

Ah okay, so basically you want to compile all coffeescript files when you do apm install (or click “Install” in settings-view) and not when the package is loaded for the first time ?
If this is the case then you’d have to move coffee-script to dependencies or your script won’t work in production (apm install calls npm install --production). This seems like a waste of disk space just because you want to move a couple ms from load time to install time (which you wouldn’t even notice when installing a package through settings-view).


#5

True, this is probably more interesting for TypeScript, LiveScript, BuckleScript et al. For now, I’ll leave my packages as they are. Thanks!


#6

Just for the record: this is what the prepublish can (and should) be used for. Atom automatically transpiles CoffeeScript and –if I’m not mistaken– TypeScript. Any unsupported language can be transpiled using prepublish.

From the npm Documentation:

The advantage of doing these things at prepublish time is that they can be done once, in a single place, thus reducing complexity and variability. Additionally, this means that:

You can depend on coffee-script as a devDependency, and thus your users don’t need to have it installed.
You don’t need to include minifiers in your package, reducing the size for your users.

Example:

"devDependencies": {
    "livescript": "^1.5.0"
},
"scripts": {
    "prepublish": "node ./node_modules/livescript/bin/lsc --o lib/ -c src/*.ls"
}