From 251105fae264ae3b89a2046e351c818203e2d472 Mon Sep 17 00:00:00 2001 From: 3rd-Eden Date: Wed, 4 Jun 2014 20:10:55 +0200 Subject: [PATCH] [minor] Added an extra compiler so it can be used in Primus 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. --- source.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 source.js diff --git a/source.js b/source.js new file mode 100644 index 0000000..4500ed3 --- /dev/null +++ b/source.js @@ -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;