Skip to content

Commit 251105f

Browse files
committed
[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.
1 parent f7381ae commit 251105f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

source.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
var read = require('fs').readFileSync
4+
, path = require('path');
5+
6+
//
7+
// Create a browser stable version of underscore so it can be included in the
8+
// source of the EJSON library.
9+
//
10+
var _ = read(require.resolve('underscore'), 'utf-8').slice(0, -7) + 'root);';
11+
12+
//
13+
// Remove the module.exports of the EJSON library which has been browserified.
14+
//
15+
var EJSON = read(path.join(__dirname, 'index.js'), 'utf-8').slice(16);
16+
17+
//
18+
// Remove the require statement for underscore and replace it with the full
19+
// source of the library.
20+
//
21+
EJSON = EJSON.replace(/var\s\_\s=\srequire\(\"underscore\"\);/, [
22+
_,
23+
'var _ = "undefined" !== typeof exports ? exports._ : root._;'
24+
].join(''));
25+
26+
//
27+
// Force a global variable and expose the string.
28+
//
29+
module.exports = ';var EJSON = '+ EJSON;

0 commit comments

Comments
 (0)