Skip to content

Commit c9bffc7

Browse files
committed
[minor] Don't use silly require hacks, just read the whole shit again.
1 parent 251105f commit c9bffc7

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

source.js

+21-19
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@ var read = require('fs').readFileSync
44
, path = require('path');
55

66
//
7-
// Create a browser stable version of underscore so it can be included in the
8-
// source of the EJSON library.
7+
// Expose a custom build which only uses globals instead of browserify.
98
//
10-
var _ = read(require.resolve('underscore'), 'utf-8').slice(0, -7) + 'root);';
9+
module.exports = [
10+
';var EJSON = (function () {',
11+
'"use strict";',
1112

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);
13+
//
14+
// EJSON and meteor has a horrible habit of introducing pointless globals
15+
// a.k.a. writing bad code in general. These variable declarations ensure that
16+
// we don't have horrible global leaks in our own code.
17+
//
18+
'var EJSON, EJSONTest, i, base64Encode, base64Decode, root = {};',
1619

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(''));
20+
//
21+
// Add the required dependencies and include them as full source so we can
22+
// re-use this code for Node.js as well as on the client.
23+
//
24+
read(require.resolve('underscore'), 'utf-8').slice(0, -7) + 'root);',
25+
'var _ = "undefined" !== typeof exports ? exports._ : root._;',
26+
read(path.join(__dirname, './vendor/ejson.js'), 'utf-8'),
27+
read(path.join(__dirname, './vendor/base64.js'), 'utf-8'),
2528

26-
//
27-
// Force a global variable and expose the string.
28-
//
29-
module.exports = ';var EJSON = '+ EJSON;
29+
' return EJSON;',
30+
'}).call(this);'
31+
].join('\n');

0 commit comments

Comments
 (0)