Skip to content

Commit f81f462

Browse files
committedNov 2, 2022
fix: make nodeMajorVersion calculation lazy so that it works in a browser environment
1 parent 4608748 commit f81f462

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed
 

‎lib/cursor/AggregationCursor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const utils = require('../../lib/utils');
3939
function AggregationCursor(agg) {
4040
const streamOpts = { objectMode: true };
4141
// for node < 12 we will emit 'close' event after 'end'
42-
if (utils.nodeMajorVersion >= 12) {
42+
if (utils.nodeMajorVersion() >= 12) {
4343
// set autoDestroy=true because on node 12 it's by default false
4444
// gh-10902 need autoDestroy to destroy correctly and emit 'close' event for node >= 12
4545
streamOpts.autoDestroy = true;
@@ -95,7 +95,7 @@ AggregationCursor.prototype._read = function() {
9595
return _this.emit('error', error);
9696
}
9797
// for node >= 12 the autoDestroy will emit the 'close' event
98-
if (utils.nodeMajorVersion < 12) {
98+
if (utils.nodeMajorVersion() < 12) {
9999
_this.on('end', () => _this.emit('close'));
100100
}
101101
});

‎lib/cursor/QueryCursor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const utils = require('../../lib/utils');
3737
function QueryCursor(query, options) {
3838
const streamOpts = { objectMode: true };
3939
// for node < 12 we will emit 'close' event after 'end'
40-
if (utils.nodeMajorVersion >= 12) {
40+
if (utils.nodeMajorVersion() >= 12) {
4141
// set autoDestroy=true because on node 12 it's by default false
4242
// gh-10902 need autoDestroy to destroy correctly and emit 'close' event for node >= 12
4343
streamOpts.autoDestroy = true;
@@ -104,7 +104,7 @@ QueryCursor.prototype._read = function() {
104104
return _this.emit('error', error);
105105
}
106106
// for node >= 12 the autoDestroy will emit the 'close' event
107-
if (utils.nodeMajorVersion < 12) {
107+
if (utils.nodeMajorVersion() < 12) {
108108
_this.on('end', () => _this.emit('close'));
109109
}
110110
});

‎lib/utils.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -936,4 +936,6 @@ exports.errorToPOJO = function errorToPOJO(error) {
936936
return ret;
937937
};
938938

939-
exports.nodeMajorVersion = parseInt(process.versions.node.split('.')[0], 10);
939+
exports.nodeMajorVersion = function nodeMajorVersion() {
940+
return parseInt(process.versions.node.split('.')[0], 10);
941+
};

0 commit comments

Comments
 (0)
Please sign in to comment.