Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli-repl): avoid instantiating libmongocrypt for mongosh --version #1739

Merged
merged 1 commit into from
Nov 15, 2023
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
46 changes: 26 additions & 20 deletions packages/cli-repl/src/build-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,7 @@ function getSystemArch(): (typeof process)['arch'] {
: process.arch;
}

/**
* Return an object with information about this mongosh instance,
* in particular, when it was built and how.
*/
// eslint-disable-next-line @typescript-eslint/require-await
export async function buildInfo({
withSegmentApiKey,
}: {
withSegmentApiKey?: boolean;
} = {}): Promise<BuildInfo> {
const dependencyVersionInfo: BuildInfo['deps'] = {
...CliServiceProvider.getVersionInformation(),
};

export function baseBuildInfo(): Omit<BuildInfo, 'deps'> {
const runtimeData = {
nodeVersion: process.version,
opensslVersion: process.versions.openssl,
Expand All @@ -57,15 +44,13 @@ export async function buildInfo({
// Runtime platform can differ e.g. because homebrew on macOS uses
// npm packages published from Linux
runtimePlatform: process.platform,
deps: { ...dependencyVersionInfo },
};

try {
const buildInfo = { ...require('./build-info.json'), ...runtimeData };
if (!withSegmentApiKey) {
delete buildInfo.segmentApiKey;
}
return buildInfo;
return {
...require('./build-info.json'),
...runtimeData,
};
} catch {
const { version } = require('../package.json');
return {
Expand All @@ -80,3 +65,24 @@ export async function buildInfo({
};
}
}

/**
* Return an object with information about this mongosh instance,
* in particular, when it was built and how.
*/
// eslint-disable-next-line @typescript-eslint/require-await
export async function buildInfo({
withSegmentApiKey,
}: {
withSegmentApiKey?: boolean;
} = {}): Promise<BuildInfo> {
const dependencyVersionInfo: BuildInfo['deps'] = {
...CliServiceProvider.getVersionInformation(),
};

const buildInfo = { ...baseBuildInfo(), deps: { ...dependencyVersionInfo } };
if (!withSegmentApiKey) {
delete buildInfo.segmentApiKey;
}
return buildInfo;
}
4 changes: 2 additions & 2 deletions packages/cli-repl/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CliRepl } from './cli-repl';
import { parseCliArgs } from './arg-parser';
import { runSmokeTests } from './smoke-tests';
import { USAGE } from './constants';
import { buildInfo } from './build-info';
import { baseBuildInfo, buildInfo } from './build-info';
import { getStoragePaths, getGlobalConfigPaths } from './config-directory';
import { getCryptLibraryPaths } from './crypt-library-paths';
import { getTlsCertificateSelector } from './tls-certificate-selector';
Expand Down Expand Up @@ -116,7 +116,7 @@ async function main() {
}

if (options.version) {
console.log((await buildInfo()).version);
console.log(baseBuildInfo().version);
return;
}
if (options.buildInfo) {
Expand Down