Skip to content

Commit

Permalink
fix: no infinite loop on windows requiring optional deps
Browse files Browse the repository at this point in the history
  • Loading branch information
durran authored Mar 24, 2021
1 parent 86bddf1 commit f2a4ff8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 43 deletions.
23 changes: 9 additions & 14 deletions lib/core/connection/utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const require_optional = require('require_optional');
const require_optional = require('optional-require')(require);

function debugOptions(debugFields, options) {
var finaloptions = {};
const finaloptions = {};
debugFields.forEach(function(n) {
finaloptions[n] = options[n];
});
Expand All @@ -12,16 +12,14 @@ function debugOptions(debugFields, options) {
}

function retrieveBSON() {
var BSON = require('bson');
const BSON = require('bson');
BSON.native = false;

try {
var optionalBSON = require_optional('bson-ext');
if (optionalBSON) {
optionalBSON.native = true;
return optionalBSON;
}
} catch (err) {} // eslint-disable-line
const optionalBSON = require_optional('bson-ext');
if (optionalBSON) {
optionalBSON.native = true;
return optionalBSON;
}

return BSON;
}
Expand All @@ -35,10 +33,7 @@ function noSnappyWarning() {

// Facilitate loading Snappy optionally
function retrieveSnappy() {
var snappy = null;
try {
snappy = require_optional('snappy');
} catch (error) {} // eslint-disable-line
let snappy = require_optional('snappy');
if (!snappy) {
snappy = {
compress: noSnappyWarning,
Expand Down
2 changes: 1 addition & 1 deletion lib/core/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

let BSON = require('bson');
const require_optional = require('require_optional');
const require_optional = require('optional-require')(require);
const EJSON = require('./utils').retrieveEJSON();

try {
Expand Down
7 changes: 2 additions & 5 deletions lib/core/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const os = require('os');
const crypto = require('crypto');
const requireOptional = require('require_optional');
const requireOptional = require('optional-require')(require);

/**
* Generate a UUIDv4
Expand Down Expand Up @@ -46,10 +46,7 @@ const noEJSONError = function() {

// Facilitate loading EJSON optionally
function retrieveEJSON() {
let EJSON = null;
try {
EJSON = requireOptional('mongodb-extjson');
} catch (error) {} // eslint-disable-line
let EJSON = requireOptional('mongodb-extjson');
if (!EJSON) {
EJSON = {
parse: noEJSONError,
Expand Down
22 changes: 7 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
"driver",
"official"
],
"peerOptionalDependencies": {
"kerberos": "^1.1.0",
"mongodb-client-encryption": "^1.0.0",
"mongodb-extjson": "^2.1.2",
"snappy": "^6.3.4",
"bson-ext": "^2.0.0"
},
"peerDependenciesMeta": {
"kerberos": {
"optional": true
Expand All @@ -47,7 +40,7 @@
"bl": "^2.2.1",
"bson": "^1.1.4",
"denque": "^1.4.1",
"require_optional": "^1.0.1",
"optional-require": "^1.0.2",
"safe-buffer": "^5.1.2"
},
"devDependencies": {
Expand Down

0 comments on commit f2a4ff8

Please sign in to comment.