@@ -1409,24 +1409,38 @@ export function commandSupportsReadConcern(command: Document, options?: Document
1409
1409
return false ;
1410
1410
}
1411
1411
1412
- /**
1413
- * A utility function to get the instance of mongodb-client-encryption, if it exists.
1414
- *
1415
- * @throws MongoMissingDependencyError if mongodb-client-encryption isn't installed.
1416
- * @returns
1417
- */
1418
- export function getMongoDBClientEncryption ( ) {
1419
- let mongodbClientEncryption ;
1412
+ /** A utility function to get the instance of mongodb-client-encryption, if it exists. */
1413
+ export function getMongoDBClientEncryption ( ) : {
1414
+ extension : ( mdb : unknown ) => {
1415
+ AutoEncrypter : any ;
1416
+ ClientEncryption : any ;
1417
+ } ;
1418
+ } | null {
1419
+ let mongodbClientEncryption = null ;
1420
1420
1421
1421
// NOTE(NODE-4254): This is to get around the circular dependency between
1422
1422
// mongodb-client-encryption and the driver in the test scenarios.
1423
1423
if (
1424
1424
typeof process . env . MONGODB_CLIENT_ENCRYPTION_OVERRIDE === 'string' &&
1425
1425
process . env . MONGODB_CLIENT_ENCRYPTION_OVERRIDE . length > 0
1426
1426
) {
1427
- mongodbClientEncryption = require ( process . env . MONGODB_CLIENT_ENCRYPTION_OVERRIDE ) ;
1427
+ try {
1428
+ // NOTE(NODE-3199): Ensure you always wrap an optional require literally in the try block
1429
+ // Cannot be moved to helper utility function, bundlers search and replace the actual require call
1430
+ // in a way that makes this line throw at bundle time, not runtime, catching here will make bundling succeed
1431
+ mongodbClientEncryption = require ( process . env . MONGODB_CLIENT_ENCRYPTION_OVERRIDE ) ;
1432
+ } catch {
1433
+ // ignore
1434
+ }
1428
1435
} else {
1429
- mongodbClientEncryption = require ( 'mongodb-client-encryption' ) ;
1436
+ try {
1437
+ // NOTE(NODE-3199): Ensure you always wrap an optional require literally in the try block
1438
+ // Cannot be moved to helper utility function, bundlers search and replace the actual require call
1439
+ // in a way that makes this line throw at bundle time, not runtime, catching here will make bundling succeed
1440
+ mongodbClientEncryption = require ( 'mongodb-client-encryption' ) ;
1441
+ } catch {
1442
+ // ignore
1443
+ }
1430
1444
}
1431
1445
1432
1446
return mongodbClientEncryption ;
0 commit comments