Skip to content

Commit 1046438

Browse files
committed
fixup: compute shell version via evaluate("version()")
1 parent 77b2209 commit 1046438

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

packages/compass-shell/src/components/compass-shell/tab-compass-shell.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { usePreference } from 'compass-preferences-model/provider';
2121
import { Shell } from '@mongosh/browser-repl';
2222
import type { RootState } from '../../stores/store';
2323
import { selectRuntimeById, saveHistory } from '../../stores/store';
24+
import { useLogger } from '@mongodb-js/compass-logging/provider';
2425

2526
const compassShellStyles = css(
2627
{
@@ -74,6 +75,8 @@ function useInitialEval(
7475
return initialEvalApplied ? undefined : initialEvaluate;
7576
}
7677

78+
let _mongoshVersion = '';
79+
7780
export const CompassShell: React.FC<CompassShellProps> = ({
7881
runtime,
7982
initialHistory,
@@ -105,6 +108,33 @@ export const CompassShell: React.FC<CompassShellProps> = ({
105108
initialInput ?? ''
106109
);
107110

111+
const [mongoshVersion, setMongoshVersion] = useTabState(
112+
'mongoshVersion',
113+
_mongoshVersion
114+
);
115+
const logger = useLogger('COMPASS-SHELL');
116+
117+
useEffect(() => {
118+
const { log, mongoLogId } = logger;
119+
if (!runtime || mongoshVersion) return;
120+
runtime
121+
.evaluate('version()')
122+
.then((value) => {
123+
setMongoshVersion((_mongoshVersion = 'v' + String(value.printable)));
124+
})
125+
.catch((err) => {
126+
setMongoshVersion('[unknown]');
127+
log.error(
128+
mongoLogId(1_001_000_342),
129+
'shell',
130+
'could not evaluate mongosh version',
131+
{
132+
error: (err as Error).message,
133+
}
134+
);
135+
});
136+
}, [runtime, logger, mongoshVersion, setMongoshVersion]);
137+
108138
useOnTabReplace(() => {
109139
// Never allow to replace the shell tab to avoid destroying the runtime
110140
// unnecessarily
@@ -156,13 +186,17 @@ export const CompassShell: React.FC<CompassShellProps> = ({
156186
);
157187
}
158188

159-
if (!canRenderShell) {
189+
if (!canRenderShell || !mongoshVersion) {
160190
return <div className={compassShellStyles} />;
161191
}
162192

163193
return (
164194
<>
165-
<ShellInfoModal show={infoModalVisible} hideInfoModal={hideInfoModal} />
195+
<ShellInfoModal
196+
show={infoModalVisible}
197+
hideInfoModal={hideInfoModal}
198+
mongoshVersion={mongoshVersion}
199+
/>
166200
{/* Clicking on the shell container to focus it is a ux improvement to give
167201
the shell more of a native shell feeling. We disable the jsx-ally rules
168202
as this is a unique ux improvement solely for clicking. */}

packages/compass-shell/src/components/shell-info-modal/shell-info-modal.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ describe('InfoModal [Component]', function () {
88
let component;
99

1010
beforeEach(function () {
11-
component = mount(<ShellInfoModal show hideInfoModal={() => {}} />);
11+
component = mount(
12+
<ShellInfoModal show hideInfoModal={() => {}} mongoshVersion="v2.3.456" />
13+
);
1214
});
1315

1416
afterEach(function () {

packages/compass-shell/src/components/shell-info-modal/shell-info-modal.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ import {
1414
type TrackFunction,
1515
} from '@mongodb-js/compass-telemetry/provider';
1616

17-
const mongoshVersion = `v${
18-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-var-requires
19-
require('@mongosh/browser-repl/package.json').version
20-
}`;
21-
2217
const shortcutsTableContainerStyles = css({
2318
marginTop: spacing[2],
2419
maxHeight: '50vh',
@@ -32,9 +27,11 @@ const shortcutsTitleStyles = css({
3227
function ShellInfoModal({
3328
hideInfoModal,
3429
show,
30+
mongoshVersion,
3531
}: {
3632
hideInfoModal: () => void;
3733
show: boolean;
34+
mongoshVersion: string;
3835
}) {
3936
useTrackOnChange(
4037
(track: TrackFunction) => {

packages/compass-shell/src/plugin.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export function onActivated(
6262
createAndStoreRuntime(dataService, logger, track, connectionInfo).id
6363
: null,
6464
history: null,
65+
mongoshVersion: '',
6566
},
6667
applyMiddleware(
6768
thunk.withExtraArgument({

0 commit comments

Comments
 (0)