Skip to content
Closed
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: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ The following table describes add-on component version compatibility for the Nod
| [bson-ext](https://www.npmjs.com/package/bson-ext) | ^1.0.0 \|\| ^2.0.0 | ^4.0.0 | N/A | N/A | N/A |
| [kerberos](https://www.npmjs.com/package/kerberos) | ^1.0.0 | ^1.0.0 \|\| ^2.0.0 | ^1.0.0 \|\| ^2.0.0 | ^2.0.1 | ^2.0.1 |
| [mongodb-client-encryption](https://www.npmjs.com/package/mongodb-client-encryption) | ^1.0.0 | ^1.0.0 \|\| ^2.0.0 | ^2.3.0 | ^6.0.0 | ^6.0.0 |
| [mongodb-legacy](https://www.npmjs.com/package/mongodb-legacy) | N/A | ^4.0.0 | ^5.0.0 | ^6.0.0 | ^6.0.0 |
| [@mongodb-js/zstd](https://www.npmjs.com/package/@mongodb-js/zstd) | N/A | ^1.0.0 | ^1.0.0 | ^1.1.0 | ^1.1.0 \|\| ^2.0.0 |


Expand Down
1 change: 0 additions & 1 deletion etc/docs/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const RELEASES_JSON_FILE = './template/static/versions.json';

const copyGeneratedDocsToDocsFolder = () => exec(`cp -R temp/. ../../docs/.`);
const removeTempDirectory = () => exec('rm -rf temp');
const installDependencies = () => exec('npm i --no-save --legacy-peer-deps typedoc@0.26.7');
const buildDocs = ({ tag }: VersionSchema) => {
const revision = tag === LATEST_TAG ? 'main' : `v${tag}.0`;
return exec(`npm run build:typedoc -- --gitRevision ${revision}`);
Expand Down
1 change: 0 additions & 1 deletion etc/notes/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,5 @@ The following is a list of packages the Node.js team is responsible for and thes
- https://github.com/mongodb-js/mongodb-client-encryption
- https://github.com/mongodb-js/kerberos
- https://github.com/mongodb-js/zstd
- https://github.com/mongodb-js/nodejs-mongodb-legacy
- https://github.com/mongodb-js/mongodb-connection-string-url
- https://github.com/mongodb-js/dbx-js-tools (Node.js team developer tools, not a product)
197 changes: 0 additions & 197 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
"mocha": "^11.7.1",
"mocha-sinon": "^2.1.2",
"mongodb-client-encryption": "^7.0.0-alpha.1",
"mongodb-legacy": "^6.1.3",
"nyc": "^15.1.0",
"prettier": "^3.6.2",
"semver": "^7.7.2",
Expand Down
87 changes: 0 additions & 87 deletions test/mongodb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as process from 'node:process';
import * as vm from 'node:vm';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function printExports() {
Expand All @@ -24,78 +22,6 @@ function printExports() {
}
}

/**
* Using node's require resolution logic this function will locate the entrypoint for the `'mongodb-legacy'` module,
* then execute the `mongodb-legacy` module in a `vm` context that replaces the global require function with a custom
* implementation. The custom version of `require` will return the local instance of the driver import (magically compiled by ts-node) when
* the module specifier is 'mongodb' and otherwise defer to the normal require behavior to import relative files and stdlib modules.
* Each of the legacy module's patched classes are placed on the input object.
*
* @param exportsToOverride - An object that is an import of the MongoDB driver to be modified by this function
*/
function importMongoDBLegacy(exportsToOverride: Record<string, unknown>) {
const mongodbLegacyEntryPoint = require.resolve('mongodb-legacy');
const mongodbLegacyLocation = path.dirname(mongodbLegacyEntryPoint);
const mongodbLegacyIndex = fs.readFileSync(mongodbLegacyEntryPoint, {
encoding: 'utf8'
});

// eslint-disable-next-line @typescript-eslint/no-require-imports
const localMongoDB = require('../src/index');
const ctx = vm.createContext({
module: { exports: null },
require: (mod: string) => {
if (mod === 'mongodb') {
return localMongoDB;
} else if (mod.startsWith('.')) {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require(path.join(mongodbLegacyLocation, mod));
}
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require(mod);
}
});
vm.runInContext(mongodbLegacyIndex, ctx);

const mongodbLegacy = ctx.module.exports;

Object.defineProperty(exportsToOverride, 'Admin', { get: () => mongodbLegacy.Admin });
Object.defineProperty(exportsToOverride, 'FindCursor', { get: () => mongodbLegacy.FindCursor });
Object.defineProperty(exportsToOverride, 'ListCollectionsCursor', {
get: () => mongodbLegacy.ListCollectionsCursor
});
Object.defineProperty(exportsToOverride, 'ListIndexesCursor', {
get: () => mongodbLegacy.ListIndexesCursor
});
Object.defineProperty(exportsToOverride, 'AggregationCursor', {
get: () => mongodbLegacy.AggregationCursor
});
Object.defineProperty(exportsToOverride, 'ChangeStream', {
get: () => mongodbLegacy.ChangeStream
});
Object.defineProperty(exportsToOverride, 'Collection', { get: () => mongodbLegacy.Collection });
Object.defineProperty(exportsToOverride, 'Db', { get: () => mongodbLegacy.Db });
Object.defineProperty(exportsToOverride, 'GridFSBucket', {
get: () => mongodbLegacy.GridFSBucket
});
Object.defineProperty(exportsToOverride, 'ClientSession', {
get: () => mongodbLegacy.ClientSession
});
Object.defineProperty(exportsToOverride, 'MongoClient', { get: () => mongodbLegacy.MongoClient });
Object.defineProperty(exportsToOverride, 'ClientSession', {
get: () => mongodbLegacy.ClientSession
});
Object.defineProperty(exportsToOverride, 'GridFSBucketWriteStream', {
get: () => mongodbLegacy.GridFSBucketWriteStream
});
Object.defineProperty(exportsToOverride, 'OrderedBulkOperation', {
get: () => mongodbLegacy.OrderedBulkOperation
});
Object.defineProperty(exportsToOverride, 'UnorderedBulkOperation', {
get: () => mongodbLegacy.UnorderedBulkOperation
});
}

export * from '../src/admin';
export * from '../src/bson';
export * from '../src/bulk/common';
Expand Down Expand Up @@ -212,16 +138,3 @@ export * from '../src/write_concern';

// Must be last for precedence
export * from '../src/index';

/**
* TODO(NODE-4979): ENABLE_MONGODB_LEGACY is 'true' by default for now
*/
const ENABLE_MONGODB_LEGACY =
typeof process.env.ENABLE_MONGODB_LEGACY === 'string' && process.env.ENABLE_MONGODB_LEGACY !== ''
? process.env.ENABLE_MONGODB_LEGACY
: 'true';

if (ENABLE_MONGODB_LEGACY === 'true') {
// Override our own exports with the legacy patched ones
importMongoDBLegacy(module.exports);
}
2 changes: 1 addition & 1 deletion test/tools/runner/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import * as types from 'node:util/types';
import { expect } from 'chai';
import { type Context } from 'mocha';
import ConnectionString from 'mongodb-connection-string-url';
import { type CompressorName } from 'mongodb-legacy';
import * as qs from 'querystring';
import * as url from 'url';

import type { CompressorName } from '../../../src/cmap/wire_protocol/compression';
import {
type AuthMechanism,
Double,
Expand Down
Loading