Skip to content

Commit 90b7568

Browse files
committed
chore(shell-bson): split shell BSON logic into separate package
This is admittedly a large refactor, but one that I would believe is generally worth it: - Moving the BSON print handling out of `service-provider-core` makes sense, as `service-provider-core` is generally intended to be a library providing an *interface*, not partial implementations. - Moving the BSON classes out of `shell-api` is less architecturally important, but it does provide a little bit of additional encapsulation. It does, for example, force us to separate mongosh-specific `.help` property from core BSON constructor logic. - A number of files in other packages were using `@mongosh/service-provider-core` only as a convenient way of getting the current `bson` package, which works but is really more of a hack and there's no good reason not to just use the `bson` package that the driver team ships directly. This is also convenient on a broader basis, though, because it makes mongosh's BSON constructors generally available for other projects with similar needs to use. In Compass, we are avoiding this by using a Babel-based "manual JavaScript evaluator", but not all projects have the same technical requirements as Compass, and some may prefer the flexibility of a full-fledged JS execution environment like mongosh does.
1 parent 439c713 commit 90b7568

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+848
-504
lines changed

package-lock.json

Lines changed: 46 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@
152152
"packages/types",
153153
"packages/i18n",
154154
"packages/logging",
155-
"packages/service-provider-core",
155+
"packages/shell-bson",
156156
"packages/arg-parser",
157+
"packages/service-provider-core",
157158
"packages/service-provider-node-driver",
158159
"packages/shell-api",
159160
"packages/autocomplete",

packages/arg-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"dependencies": {
3838
"@mongosh/errors": "2.4.4",
3939
"@mongosh/i18n": "^2.15.4",
40-
"mongodb-connection-string-url": "^3.0.1"
40+
"mongodb-connection-string-url": "^3.0.2"
4141
},
4242
"devDependencies": {
4343
"@mongodb-js/devtools-connect": "^3.9.4",

packages/browser-repl/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
"@mongosh/i18n": "^2.15.4",
6464
"@mongosh/node-runtime-worker-thread": "3.3.24",
6565
"@mongosh/service-provider-core": "3.5.0",
66+
"@mongosh/shell-bson": "1.0.0",
67+
"bson": "^6.10.4",
6668
"numeral": "^2.0.6",
6769
"text-table": "^0.2.0"
6870
},

packages/browser-repl/src/components/utils/inspect.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bson } from '@mongosh/service-provider-core';
1+
import * as bson from 'bson';
22
import { expect } from 'chai';
33
import { inspect } from './inspect';
44

packages/browser-repl/src/components/utils/inspect.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { CustomInspectFunction } from 'util';
22
import { inspect as utilInspect } from 'util';
3-
import { bsonStringifiers } from '@mongosh/service-provider-core';
3+
import * as bson from 'bson';
4+
import { makeBsonStringifiers } from '@mongosh/shell-bson';
45

56
// At the time of writing, the Compass dist package contains what appear to be
67
// 155 different copies of the 'bson' module. It is impractical to attach
@@ -65,6 +66,7 @@ function attachInspectMethods(obj: any): void {
6566
attachInspectMethods(value);
6667
}
6768

69+
const bsonStringifiers = makeBsonStringifiers(bson);
6870
// Add obj[util.inspect.custom] if it does not exist and we can provide it.
6971
const bsontype = obj._bsontype as keyof typeof bsonStringifiers;
7072
if (

packages/browser-repl/src/iframe-runtime/iframe-runtime.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IframeRuntime } from './iframe-runtime';
22
import { expect } from '../../testing/chai';
33
import type { ServiceProvider } from '@mongosh/service-provider-core';
4-
import { bson } from '@mongosh/service-provider-core';
4+
import * as bson from 'bson';
55

66
describe('IframeRuntime', function () {
77
let runtime;

packages/browser-runtime-electron/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@mongosh/service-provider-node-driver": "^3.16.0",
4545
"@types/sinon": "^7.5.1",
4646
"@types/sinon-chai": "^3.2.4",
47+
"bson": "^6.10.4",
4748
"depcheck": "^1.4.7",
4849
"eslint": "^7.25.0",
4950
"prettier": "^2.8.8",

packages/browser-runtime-electron/src/electron-runtime.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ chai.use(sinonChai);
66
const { expect } = chai;
77

88
import { NodeDriverServiceProvider } from '@mongosh/service-provider-node-driver';
9-
import { bson } from '@mongosh/service-provider-core';
9+
import * as bson from 'bson';
1010
import { ElectronRuntime } from './electron-runtime';
1111
import { EventEmitter } from 'events';
1212
import type { RuntimeEvaluationListener } from '@mongosh/browser-runtime-core';

packages/cli-repl/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@
8181
"ansi-escape-sequences": "^5.1.2",
8282
"askcharacter": "^2.0.4",
8383
"askpassword": "^2.0.2",
84+
"bson": "^6.10.4",
8485
"escape-string-regexp": "^4.0.0",
8586
"is-recoverable-error": "^1.0.3",
8687
"js-yaml": "^4.1.0",
87-
"mongodb-connection-string-url": "^3.0.1",
88+
"mongodb-connection-string-url": "^3.0.2",
8889
"mongodb-log-writer": "^2.3.1",
8990
"numeral": "^2.0.6",
9091
"pretty-repl": "^4.0.1",

0 commit comments

Comments
 (0)