Skip to content

Commit

Permalink
Prevent lodash from adding itself to global scope
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekn committed Feb 23, 2016
1 parent ac877f5 commit 8b65f19
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
6 changes: 5 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ gulp.task('build:browser', ['lint:src'], function() {
.pipe(plugins.insert.prepend(fs.readFileSync('./node_modules/event-source-polyfill/eventsource.js')))
.pipe(plugins.rename('stellar-sdk.js'))
.pipe(gulp.dest('dist'))
.pipe(plugins.uglify())
.pipe(plugins.uglify({
output: {
ascii_only: true
}
}))
.pipe(plugins.rename('stellar-sdk.min.js'))
.pipe(gulp.dest('dist'));
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"eventsource": "^0.1.6",
"jsdoc": "jsdoc3/jsdoc#master",
"lodash": "^4.0.1",
"stellar-base": "^0.5.3",
"stellar-base": "^0.5.4",
"superagent": "^1.1.0",
"toml": "^2.3.0"
}
Expand Down
3 changes: 3 additions & 0 deletions src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ module.exports = require("./index");
module.exports.axios = require("axios");
module.exports.bluebird = require("bluebird");
module.exports.StellarBase = require("stellar-base");

/*globals _*/
_.noConflict();
4 changes: 2 additions & 2 deletions src/call_builder.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {NotFoundError, NetworkError, BadRequestError} from "./errors";
import forEach from 'lodash/forEach';

let URI = require("urijs");
let URITemplate = require("urijs").URITemplate;

let axios = require("axios");
var EventSource = (typeof window === 'undefined') ? require('eventsource') : window.EventSource;
let toBluebird = require("bluebird").resolve;
let _ = require('lodash');

/**
* Creates a new {@link CallBuilder} pointed to server defined by serverUrl.
Expand Down Expand Up @@ -97,7 +97,7 @@ export class CallBuilder {
if (!json._links) {
return json;
}
_.forEach(json._links, (n, key) => {json[key] = this._requestFnForLink(n);});
forEach(json._links, (n, key) => {json[key] = this._requestFnForLink(n);});
return json;
}

Expand Down
3 changes: 2 additions & 1 deletion src/federation_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import axios from 'axios';
import URI from 'urijs';
import Promise from 'bluebird';
import toml from 'toml';
import {isString, pick} from "lodash";
import isString from "lodash/isString";
import pick from "lodash/pick";
import {Account} from 'stellar-base';

export class FederationServer {
Expand Down
3 changes: 1 addition & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {PaymentCallBuilder} from "./payment_call_builder";
import {EffectCallBuilder} from "./effect_call_builder";
import {FriendbotBuilder} from "./friendbot_builder";
import {xdr, Account} from "stellar-base";

import {isString} from "lodash";
import isString from "lodash/isString";

let axios = require("axios");
let toBluebird = require("bluebird").resolve;
Expand Down
7 changes: 7 additions & 0 deletions test/unit/browser_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe('Browser version tests', function() {
it("lodash is not exported globally", function () {
if (typeof window !== "undefined") {
expect(_).to.be.undefined;
}
});
});

0 comments on commit 8b65f19

Please sign in to comment.