Skip to content

Commit cd37392

Browse files
committed
supportsNodeVM check that works in GOJA, node and ReactNative.
1 parent b05dc3e commit cd37392

File tree

9 files changed

+46
-46
lines changed

9 files changed

+46
-46
lines changed

dist/index-es.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,16 @@ function _possibleConstructorReturn(self, call) {
135135

136136
/* eslint-disable no-eval, jsdoc/check-types */
137137
// Todo: Reenable jsdoc/check-types once PR merged: https://github.com/gajus/eslint-plugin-jsdoc/pull/270
138-
var globalEval = eval; // eslint-disable-next-line import/no-commonjs
138+
var globalEval = eval; // Only Node.JS has a process variable that is of [[Class]] process
139+
140+
var supportsNodeVM = function supportsNodeVM() {
141+
try {
142+
return Object.prototype.toString.call(global.process) === '[object process]';
143+
} catch (e) {
144+
return false;
145+
}
146+
};
139147

140-
var supportsNodeVM = typeof module !== 'undefined' && Boolean(module.exports) && !(typeof navigator !== 'undefined' && navigator.product === 'ReactNative');
141148
var allowedResultTypes = ['value', 'path', 'pointer', 'parent', 'parentProperty', 'all'];
142149
var hasOwnProp = Object.prototype.hasOwnProperty;
143150
/**
@@ -171,7 +178,7 @@ var moveToAnotherArray = function moveToAnotherArray(source, target, conditionCb
171178
}
172179
};
173180

174-
var vm = supportsNodeVM ? require('vm') : {
181+
var vm = supportsNodeVM() ? require('vm') : {
175182
/**
176183
* @param {string} expr Expression to evaluate
177184
* @param {PlainObject} context Object whose items will be added to evaluation

dist/index-es.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-es.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-umd.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,16 @@
141141

142142
/* eslint-disable no-eval, jsdoc/check-types */
143143
// Todo: Reenable jsdoc/check-types once PR merged: https://github.com/gajus/eslint-plugin-jsdoc/pull/270
144-
var globalEval = eval; // eslint-disable-next-line import/no-commonjs
144+
var globalEval = eval; // Only Node.JS has a process variable that is of [[Class]] process
145+
146+
var supportsNodeVM = function supportsNodeVM() {
147+
try {
148+
return Object.prototype.toString.call(global.process) === '[object process]';
149+
} catch (e) {
150+
return false;
151+
}
152+
};
145153

146-
var supportsNodeVM = typeof module !== 'undefined' && Boolean(module.exports) && !(typeof navigator !== 'undefined' && navigator.product === 'ReactNative');
147154
var allowedResultTypes = ['value', 'path', 'pointer', 'parent', 'parentProperty', 'all'];
148155
var hasOwnProp = Object.prototype.hasOwnProperty;
149156
/**
@@ -177,7 +184,7 @@
177184
}
178185
};
179186

180-
var vm = supportsNodeVM ? require('vm') : {
187+
var vm = supportsNodeVM() ? require('vm') : {
181188
/**
182189
* @param {string} expr Expression to evaluate
183190
* @param {PlainObject} context Object whose items will be added to evaluation

dist/index-umd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-umd.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 12 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Stefan Goessner",
33
"name": "jsonpath-plus",
4-
"version": "0.20.1",
4+
"version": "0.20.2",
55
"main": "dist/index-umd.js",
66
"module": "dist/index-es.js",
77
"description": "A JS implementation of JSONPath with some additional operators",

src/jsonpath.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
// Todo: Reenable jsdoc/check-types once PR merged: https://github.com/gajus/eslint-plugin-jsdoc/pull/270
44
const globalEval = eval;
5-
// eslint-disable-next-line import/no-commonjs
6-
const supportsNodeVM = typeof module !== 'undefined' && Boolean(module.exports) &&
7-
!(typeof navigator !== 'undefined' && navigator.product === 'ReactNative');
5+
// Only Node.JS has a process variable that is of [[Class]] process
6+
const supportsNodeVM = function () {
7+
try {
8+
return Object.prototype.toString.call(global.process) === '[object process]';
9+
} catch (e) {
10+
return false;
11+
}
12+
};
813
const allowedResultTypes = ['value', 'path', 'pointer', 'parent', 'parentProperty', 'all'];
914
const {hasOwnProperty: hasOwnProp} = Object.prototype;
1015

@@ -36,7 +41,7 @@ const moveToAnotherArray = function (source, target, conditionCb) {
3641
}
3742
};
3843

39-
const vm = supportsNodeVM
44+
const vm = supportsNodeVM()
4045
? require('vm')
4146
: {
4247
/**

0 commit comments

Comments
 (0)