With tools like this, I love being able to modularize my client-side code using CommonJS modules and running JS test from the command line using tools like Vows and Buster.js. I also love being able to declare dependencies on npm modules. It's just as easy as testing and writing Ruby code with rubygems and rspec.
The only issue that still bothers me is that nearly every DOM querying/manipulating library out there assumes there's a global window or document object. This means I have to stub it out in any CLI tests I run and then make sure jquery or whatever is referencing a virtual window I create with jsdom instead of the global stub.
I have a few project using vows/npm/browserify for reference if anyone is interested.
A FF/Chrome/Safari plugin: https://github.com/brighterplanet/careplane
A simple SPI app: https://github.com/brighterplanet/hootroot1
here is the output comparison of onejs and browserify:
and here is a real world example of onejs;
The second thing is, onejs lets us use the core NodeJS library, too. It doesn't contain it by default but you can install the available modules by typing; "one install assert path util url"
Does anyone have any articles that can help me to fill the gaps?
1) "Hey, how can I use the same code on the server and the client?" Hard problem, but you can look at Meteor or Derby for people working hard to solve it. It's unrelated to this project though.
2) "Hey, I've been using npm and require and coffeescript to write some cool code, but I want to run the entire thing in the browser. How can I somehow "bake" this all down to a single JS file I can deliver to the client where everything just works? This is a pretty easy problem, and it's been solved by Stitch (my favourite), Hem, Browserify, and probably a few more. And now, OneJS. :)
If it helps to see an example, I'm working on an app with a really big complicated source code tree; it's split into lots of files, plus a bunch of libraries, some of which are "traditional" JS libraries like jQuery, and some of which are "modern" CommonJS modules installed by npm. I use Stitch to bundle the whole thing into a single application.js file which contains every bit of my client-side code (only). My HTML file only contains two script blocks.
app = require('app');
I'm using Stitch, but I believe OneJS is designed to do the same thing. I'm afraid I find the documentation on the project really hard to follow though, so I might be wrong. :)
And here are the differences of OneJS:
- it produces unobtrusive code
- it bundles any level of dependency properly
- it's not only for web browsers, but also all JS environments including Node itself
- it's a command-line tool that doesn't require you to code.
It doesn't contain the standard library of NodeJS by default but you can install the available modules like assert, path, url etc.. by doing:
$ onejs install assert