CommonJS implementation for Photoshop

I used some boilerplate code for a CommonJS implementation and fitted it for extendscript. It conforms to CommonJS/Modules 1.0 & 1.1.

To use, include or eval/evalFile require.jsx. This will add a require function to the global namespace. After this, you can simply:


var api = require('path/to/api');
api.foo();

When writing modules, each module will have access to a few variables:

[ul]
[li]exports - Object to add your api to
[/li][li]module - Object representing the current module on the require object.
[/li][li]module.exports is the same as exports (CommonJS/Modules 1.0 and 1.1)
[/li][li]require - The global require object
[/li][/ul]

So just add your api to the exports var or module.exports and that’s it. You can call require inside your modules. See the tests for some examples.

You can also add paths to search to require.path or set an environment var, PHOTOSHOP_PATH, to search for modules.

Tests are included and the current version passes all but 1: implicitly bound members

I’ve also included a JSON(crockfords) module and underscore.

Please let me know if you find any bugs or issues while using it.