Skip to content

Commit

Permalink
[minor] Added an extra compiler so it can be used in Primus
Browse files Browse the repository at this point in the history
There's no way around this as it needs underscore to be resolved from the modules
directory. Now you can just simply require(ejson/source) and get the source as
string.
  • Loading branch information
3rd-Eden committed Jun 4, 2014
1 parent f7381ae commit 251105f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var read = require('fs').readFileSync
, path = require('path');

//
// Create a browser stable version of underscore so it can be included in the
// source of the EJSON library.
//
var _ = read(require.resolve('underscore'), 'utf-8').slice(0, -7) + 'root);';

//
// Remove the module.exports of the EJSON library which has been browserified.
//
var EJSON = read(path.join(__dirname, 'index.js'), 'utf-8').slice(16);

//
// Remove the require statement for underscore and replace it with the full
// source of the library.
//
EJSON = EJSON.replace(/var\s\_\s=\srequire\(\"underscore\"\);/, [
_,
'var _ = "undefined" !== typeof exports ? exports._ : root._;'
].join(''));

//
// Force a global variable and expose the string.
//
module.exports = ';var EJSON = '+ EJSON;

0 comments on commit 251105f

Please sign in to comment.