Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make node detection a bit more forgiving #1445

Merged
merged 3 commits into from Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions index.d.ts
Expand Up @@ -1951,15 +1951,18 @@ export namespace util {
public length(): number;
}

/** Whether running within node or not. */
let isNode: boolean;

/** Global object reference. */
let global: object;

/** An immuable empty array. */
const emptyArray: any[];

/** An immutable empty object. */
const emptyObject: object;

/** Whether running within node or not. */
const isNode: boolean;

/**
* Tests if the specified value is an integer.
* @param value Value to test
Expand Down
27 changes: 17 additions & 10 deletions src/util/minimal.js
Expand Up @@ -25,8 +25,23 @@ util.pool = require("@protobufjs/pool");
// utility to work with the low and high bits of a 64 bit value
util.LongBits = require("./longbits");

// global object reference
util.global = typeof global !== "undefined" && Object.prototype.toString.call(global) === "[object global]" && global
/**
* Whether running within node or not.
* @memberof util
* @type {boolean}
*/
util.isNode = Boolean(typeof global !== "undefined"
&& global
&& global.process
&& global.process.versions
&& global.process.versions.node);

/**
* Global object reference.
* @memberof util
* @type {Object}
*/
util.global = util.isNode && global
|| typeof window !== "undefined" && window
|| typeof self !== "undefined" && self
|| this; // eslint-disable-line no-invalid-this
Expand All @@ -46,14 +61,6 @@ util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */
*/
util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes

/**
* Whether running within node or not.
* @memberof util
* @type {boolean}
* @const
*/
util.isNode = Boolean(util.global.process && util.global.process.versions && util.global.process.versions.node);

/**
* Tests if the specified value is an integer.
* @function
Expand Down