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(NODE-3199): unable to bundle driver due to uncaught require #2903

Merged
merged 2 commits into from
Jul 20, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/core/auth/mongodb_aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const url = require('url');

let aws4;
try {
// Ensure you always wrap an optional require in the try block NODE-3199
aws4 = require('aws4');
} catch (e) {
// don't do anything;
Expand Down
1 change: 1 addition & 0 deletions lib/core/auth/scram.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Binary = BSON.Binary;

let saslprep;
try {
// Ensure you always wrap an optional require in the try block NODE-3199
saslprep = require('saslprep');
} catch (e) {
// don't do anything;
Expand Down
1 change: 1 addition & 0 deletions lib/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const require_optional = require('optional-require')(require);
const EJSON = require('./utils').retrieveEJSON();

try {
// Ensure you always wrap an optional require in the try block NODE-3199
// Attempt to grab the native BSON parser
const BSONNative = require_optional('bson-ext');
// If we got the native parser, use it instead of the
Expand Down
1 change: 1 addition & 0 deletions lib/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function retrieveKerberos() {
let kerberos;

try {
// Ensure you always wrap an optional require in the try block NODE-3199
kerberos = requireOptional('kerberos');
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
Expand Down
11 changes: 8 additions & 3 deletions lib/encrypter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@ const MongoClient = require('./mongo_client');
const BSON = require('./core/connection/utils').retrieveBSON();
const MongoError = require('./core/error').MongoError;

let mongodbClientEncryption = undefined;
try {
require.resolve('mongodb-client-encryption');
// Ensure you always wrap an optional require in the try block NODE-3199
mongodbClientEncryption = require('mongodb-client-encryption');
} catch (err) {
throw new MongoError(
'Auto-encryption requested, but the module is not installed. ' +
'Please add `mongodb-client-encryption` as a dependency of your project'
);
}

const mongodbClientEncryption = require('mongodb-client-encryption');
if (typeof mongodbClientEncryption.extension !== 'function') {
if (
mongodbClientEncryption === undefined ||
typeof mongodbClientEncryption.extension !== 'function'
) {
throw new MongoError(
'loaded version of `mongodb-client-encryption` does not have property `extension`. ' +
'Please make sure you are loading the correct version of `mongodb-client-encryption`'
);
}

const AutoEncrypter = mongodbClientEncryption.extension(require('../index')).AutoEncrypter;

const kInternalClient = Symbol('internalClient');
Expand Down
36 changes: 18 additions & 18 deletions package-lock.json

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