Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix: access process through _global so that WebPack does not acci…
Browse files Browse the repository at this point in the history
…dently browserify (#786)
  • Loading branch information
mhevery authored May 19, 2017
1 parent 89f990a commit 1919b36
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@ export function patchPrototype(prototype: any, fnNames: string[]) {
export const isWebWorker: boolean =
(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope);

// Make sure to access `process` through `_global` so that WebPack does not accidently browserify
// this code.
export const isNode: boolean =
(!('nw' in _global) && typeof process !== 'undefined' &&
{}.toString.call(process) === '[object process]');
(!('nw' in _global) && typeof _global.process !== 'undefined' &&
{}.toString.call(_global.process) === '[object process]');

export const isBrowser: boolean =
!isNode && !isWebWorker && !!(typeof window !== 'undefined' && (window as any)['HTMLElement']);

// we are in electron of nw, so we are both browser and nodejs
export const isMix: boolean = typeof process !== 'undefined' &&
{}.toString.call(process) === '[object process]' && !isWebWorker &&
// Make sure to access `process` through `_global` so that WebPack does not accidently browserify
// this code.
export const isMix: boolean = typeof _global.process !== 'undefined' &&
{}.toString.call(_global.process) === '[object process]' && !isWebWorker &&
!!(typeof window !== 'undefined' && (window as any)['HTMLElement']);

export function patchProperty(obj: any, prop: string, prototype?: any) {
Expand Down

0 comments on commit 1919b36

Please sign in to comment.