Skip to content
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ lib
.nyc_output/
coverage/
*.d.ts
!test/register-bson.d.ts
*.tgz
docs/public

Expand Down
2 changes: 1 addition & 1 deletion api-extractor.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "<projectFolder>/lib/bson.d.ts",
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
"apiReport": {
"enabled": false
},
Expand Down
26 changes: 0 additions & 26 deletions bower.json

This file was deleted.

6 changes: 6 additions & 0 deletions docs/upgrade-to-v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,9 @@ EJSON.parse("...", { strict: false }); /* migrate to */ EJSON.parse("...", { r
// stringify
EJSON.stringify({}, { strict: true }); /* migrate to */ EJSON.stringify({}, { relaxed: false });
EJSON.stringify({}, { strict: false }); /* migrate to */ EJSON.stringify({}, { relaxed: true });

### The BSON default export has been removed.

* If you import BSON commonjs style `const BSON = require('bson')` then the `BSON.default` property is no longer present.
* If you import BSON esmodule style `import BSON from 'bson'` then this code will crash upon loading. **TODO: This is not the case right now but it will be after NODE-4713.**
* This error will throw: `SyntaxError: The requested module 'bson' does not provide an export named 'default'`.
2 changes: 1 addition & 1 deletion etc/benchmarks/lib_runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function getLibs() {
const hash = stdout.trim();
return {
name: 'local',
lib: await import('../../lib/bson.js'),
lib: await import('../../lib/index.js'),
version: hash
};
})(),
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@
"config": {
"native": false
},
"main": "lib/bson.js",
"main": "lib/index.js",
"module": "dist/bson.esm.js",
"browser": {
"./lib/bson.js": "./dist/bson.browser.umd.js",
"./lib/index.js": "./dist/bson.browser.umd.js",
"./dist/bson.esm.js": "./dist/bson.browser.esm.js"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const tsConfig = {
tsconfig: false,
include: ['src/**/*']
};
const input = 'src/bson.ts';
const input = 'src/index.ts';

const plugins = (options = { browser: false }) => {
return [
Expand Down
38 changes: 0 additions & 38 deletions src/bson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { Code } from './code';
import { DBRef } from './db_ref';
import { Decimal128 } from './decimal128';
import { Double } from './double';
import { EJSON } from './extended_json';
import { Int32 } from './int_32';
import { Long } from './long';
import { MaxKey } from './max_key';
import { MinKey } from './min_key';
import { ObjectId } from './objectid';
import { BSONError, BSONTypeError } from './error';
import { calculateObjectSize as internalCalculateObjectSize } from './parser/calculate_size';
// Parts of the parser
import { deserialize as internalDeserialize, DeserializeOptions } from './parser/deserializer';
Expand Down Expand Up @@ -247,39 +245,3 @@ export function deserializeStream(
// Return object containing end index of parsing and list of documents
return index;
}

/**
* BSON default export
* @deprecated Please use named exports
* @privateRemarks
* We want to someday deprecate the default export,
* so none of the new TS types are being exported on the default
* @public
*/
const BSON = {
Binary,
Code,
DBRef,
Decimal128,
Double,
Int32,
Long,
UUID,
Map,
MaxKey,
MinKey,
ObjectId,
BSONRegExp,
BSONSymbol,
Timestamp,
EJSON,
setInternalBufferSize,
serialize,
serializeWithBufferAndIndex,
deserialize,
calculateObjectSize,
deserializeStream,
BSONError,
BSONTypeError
};
export default BSON;
19 changes: 19 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as BSON from './bson';

// Export all named properties from BSON to support
// import { ObjectId, serialize } from 'bson';
// const { ObjectId, serialize } = require('bson');
export * from './bson';

// Export BSON as a namespace to support:
// import { BSON } from 'bson';
// const { BSON } = require('bson');
export { BSON };

// BSON does **NOT** have a default export

// The following will crash in es module environments
// import BSON from 'bson';

// The following will work as expected, BSON as a namespace of all the APIs (BSON.ObjectId, BSON.serialize)
// const BSON = require('bson');
3 changes: 2 additions & 1 deletion test/node/exports.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect } from 'chai';
import * as BSON from '../register-bson';
import { sorted, byStrings } from './tools/utils';

Expand Down Expand Up @@ -30,7 +31,7 @@ const EXPECTED_EXPORTS = [
'deserialize',
'calculateObjectSize',
'deserializeStream',
'default'
'BSON'
];

const EXPECTED_EJSON_EXPORTS = ['parse', 'stringify', 'serialize', 'deserialize'];
Expand Down
1 change: 1 addition & 0 deletions test/register-bson.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../src/index'
2 changes: 1 addition & 1 deletion test/register-bson.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let BSON;
if (web) {
BSON = loadBSONWithGlobal().BSON;
} else {
BSON = require('../src/bson');
BSON = require('../src/index');
}

// Some mocha tests need to know the environment for instanceof assertions or be skipped
Expand Down