@@ -4,26 +4,28 @@ var read = require('fs').readFileSync
4
4
, path = require ( 'path' ) ;
5
5
6
6
//
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.
9
8
//
10
- var _ = read ( require . resolve ( 'underscore' ) , 'utf-8' ) . slice ( 0 , - 7 ) + 'root);' ;
9
+ module . exports = [
10
+ ';var EJSON = (function () {' ,
11
+ '"use strict";' ,
11
12
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 = {};' ,
16
19
17
- //
18
- // Remove the require statement for underscore and replace it with the full
19
- // source of the library .
20
- //
21
- EJSON = EJSON . replace ( / v a r \s \_ \s = \s r e q u i r e \( \" u n d e r s c o r e \" \) ; / , [
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' ) ,
25
28
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