Skip to content

Commit 101a162

Browse files
authored
fix(cli-repl): avoid instantiating libmongocrypt for mongosh --version (#1739)
1 parent 278696a commit 101a162

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

packages/cli-repl/src/build-info.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,7 @@ function getSystemArch(): (typeof process)['arch'] {
3333
: process.arch;
3434
}
3535

36-
/**
37-
* Return an object with information about this mongosh instance,
38-
* in particular, when it was built and how.
39-
*/
40-
// eslint-disable-next-line @typescript-eslint/require-await
41-
export async function buildInfo({
42-
withSegmentApiKey,
43-
}: {
44-
withSegmentApiKey?: boolean;
45-
} = {}): Promise<BuildInfo> {
46-
const dependencyVersionInfo: BuildInfo['deps'] = {
47-
...CliServiceProvider.getVersionInformation(),
48-
};
49-
36+
export function baseBuildInfo(): Omit<BuildInfo, 'deps'> {
5037
const runtimeData = {
5138
nodeVersion: process.version,
5239
opensslVersion: process.versions.openssl,
@@ -57,15 +44,13 @@ export async function buildInfo({
5744
// Runtime platform can differ e.g. because homebrew on macOS uses
5845
// npm packages published from Linux
5946
runtimePlatform: process.platform,
60-
deps: { ...dependencyVersionInfo },
6147
};
6248

6349
try {
64-
const buildInfo = { ...require('./build-info.json'), ...runtimeData };
65-
if (!withSegmentApiKey) {
66-
delete buildInfo.segmentApiKey;
67-
}
68-
return buildInfo;
50+
return {
51+
...require('./build-info.json'),
52+
...runtimeData,
53+
};
6954
} catch {
7055
const { version } = require('../package.json');
7156
return {
@@ -80,3 +65,24 @@ export async function buildInfo({
8065
};
8166
}
8267
}
68+
69+
/**
70+
* Return an object with information about this mongosh instance,
71+
* in particular, when it was built and how.
72+
*/
73+
// eslint-disable-next-line @typescript-eslint/require-await
74+
export async function buildInfo({
75+
withSegmentApiKey,
76+
}: {
77+
withSegmentApiKey?: boolean;
78+
} = {}): Promise<BuildInfo> {
79+
const dependencyVersionInfo: BuildInfo['deps'] = {
80+
...CliServiceProvider.getVersionInformation(),
81+
};
82+
83+
const buildInfo = { ...baseBuildInfo(), deps: { ...dependencyVersionInfo } };
84+
if (!withSegmentApiKey) {
85+
delete buildInfo.segmentApiKey;
86+
}
87+
return buildInfo;
88+
}

packages/cli-repl/src/run.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { CliRepl } from './cli-repl';
1717
import { parseCliArgs } from './arg-parser';
1818
import { runSmokeTests } from './smoke-tests';
1919
import { USAGE } from './constants';
20-
import { buildInfo } from './build-info';
20+
import { baseBuildInfo, buildInfo } from './build-info';
2121
import { getStoragePaths, getGlobalConfigPaths } from './config-directory';
2222
import { getCryptLibraryPaths } from './crypt-library-paths';
2323
import { getTlsCertificateSelector } from './tls-certificate-selector';
@@ -116,7 +116,7 @@ async function main() {
116116
}
117117

118118
if (options.version) {
119-
console.log((await buildInfo()).version);
119+
console.log(baseBuildInfo().version);
120120
return;
121121
}
122122
if (options.buildInfo) {

0 commit comments

Comments
 (0)