Skip to content

Commit

Permalink
fix(env): don't assume process is defined
Browse files Browse the repository at this point in the history
Most environments (webpack, browserify) by default define `process` as a shim for it.

However, some environements don't supply it, so we should always guard against it not being defined

fixes #691

(should be tested in a real angular app first)
  • Loading branch information
Haroenv committed May 5, 2018
1 parent e2d625b commit 367300a
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/AlgoliaSearchCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var store = require('./store.js');
// proxies limit)
var MAX_API_KEY_LENGTH = 500;
var RESET_APP_DATA_TIMER =
process.env.RESET_APP_DATA_TIMER && parseInt(process.env.RESET_APP_DATA_TIMER, 10) ||
(process && process.env.RESET_APP_DATA_TIMER && parseInt(process.env.RESET_APP_DATA_TIMER, 10)) ||
60 * 2 * 1000; // after 2 minutes reset to first host

/*
Expand Down
2 changes: 1 addition & 1 deletion src/browser/builds/algoliasearch.angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var places = require('../../places.js');
// expose original algoliasearch fn in window
window.algoliasearch = require('./algoliasearch');

if (process.env.NODE_ENV === 'debug') {
if (process && process.env.NODE_ENV === 'debug') {
require('debug').enable('algoliasearch*');
}

Expand Down
2 changes: 1 addition & 1 deletion src/browser/builds/algoliasearch.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var places = require('../../places.js');
// expose original algoliasearch fn in window
window.algoliasearch = require('./algoliasearch');

if (process.env.NODE_ENV === 'debug') {
if (process && process.env.NODE_ENV === 'debug') {
require('debug').enable('algoliasearch*');
}

Expand Down
2 changes: 1 addition & 1 deletion src/browser/createAlgoliasearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
var places = require('../places.js');
uaSuffix = uaSuffix || '';

if (process.env.NODE_ENV === 'debug') {
if (process && process.env.NODE_ENV === 'debug') {
require('debug').enable('algoliasearch*');
}

Expand Down
2 changes: 1 addition & 1 deletion src/browser/migration-layer/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This script will be browserified and prepended to the normal build
// directly in window, not wrapped in any module definition
// To avoid cases where we are loaded with /latest/ along with
migrationLayer(process.env.ALGOLIA_BUILDNAME);
migrationLayer(process && process.env.ALGOLIA_BUILDNAME);

// Now onto the V2 related code:
// If the client is using /latest/$BUILDNAME.min.js, load V2 of the library
Expand Down

0 comments on commit 367300a

Please sign in to comment.