Skip to content

Commit 3e2985d

Browse files
committed
feat(compass-shell): Integrate worker runtime with compass shell, hide it behind an env varibable
1 parent 33ee35c commit 3e2985d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

packages/compass-shell/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@leafygreen-ui/icon-button": "^5.0.2",
5757
"@mongosh/browser-repl": "0.0.0-dev.0",
5858
"@mongosh/browser-runtime-electron": "0.0.0-dev.0",
59+
"@mongosh/node-runtime-worker-thread": "0.0.0-dev.0",
5960
"@mongosh/service-provider-server": "0.0.0-dev.0",
6061
"hadron-react-buttons": "^4.0.4",
6162
"mongodb-redux-common": "0.0.2"

packages/compass-shell/src/modules/runtime.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ElectronRuntime } from '@mongosh/browser-runtime-electron';
22
import { CompassServiceProvider } from '@mongosh/service-provider-server';
3+
import { WorkerRuntime } from '@mongosh/node-runtime-worker-thread';
34

45
/**
56
* The prefix.
@@ -38,17 +39,29 @@ export default function reducer(state = INITIAL_STATE, action) {
3839

3940
function reduceSetupRuntime(state, action) {
4041
if (action.error || !action.dataService) {
41-
return {error: action.error, dataService: null, runtime: null};
42+
return { error: action.error, dataService: null, runtime: null };
4243
}
4344

4445
if (state.dataService === action.dataService) {
4546
return state;
4647
}
4748

48-
const runtime = new ElectronRuntime(
49-
CompassServiceProvider.fromDataService(action.dataService),
50-
action.appRegistry
51-
);
49+
const { url, options } = action.dataService.getConnectionOptions();
50+
51+
const runtime = !!process.env.COMPASS_SHELL_EXPERIMENTAL_WORKER_RUNTIME
52+
? new WorkerRuntime(
53+
url,
54+
options,
55+
{},
56+
{
57+
env: { ...process.env, ELECTRON_RUN_AS_NODE: 1 },
58+
serialization: 'advanced',
59+
}
60+
)
61+
: new ElectronRuntime(
62+
CompassServiceProvider.fromDataService(action.dataService),
63+
action.appRegistry
64+
);
5265

5366
return {
5467
error: action.error,

0 commit comments

Comments
 (0)