Skip to content

Commit b2da534

Browse files
gribnoysupaddaleax
andauthored
refactor(node-runtime-worker-thread): Use nullish coalescing instead of if statement, fix typos
Co-authored-by: Anna Henningsen <[email protected]>
1 parent eeb542c commit b2da534

File tree

3 files changed

+10
-21
lines changed

3 files changed

+10
-21
lines changed

packages/node-runtime-worker-thread/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"url": "https://github.com/mongodb-js/mongosh"
1515
},
1616
"engines": {
17-
"node": "^12.4.0"
17+
"node": ">=12.4.0"
1818
},
1919
"scripts": {
2020
"pretest": "npm run webpack-build-dev -- --no-stats --no-devtool",

packages/node-runtime-worker-thread/src/child-process-proxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ const worker = createCaller(
4040

4141
function waitForWorkerReadyProxy<T extends Function>(fn: T): T {
4242
return new Proxy(fn, {
43-
async apply(target, thisArg, argumetsList) {
43+
async apply(target, thisArg, argumentsList) {
4444
await workerReadyPromise;
45-
return target.call(thisArg, ...Array.from(argumetsList));
45+
return target.call(thisArg, ...Array.from(argumentsList));
4646
}
4747
});
4848
}

packages/node-runtime-worker-thread/src/index.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,22 @@ class WorkerEvaluationListener {
1616
this.exposedListener = exposeAll<EvaluationListener>(
1717
{
1818
onPrompt(question, type) {
19-
if (workerRuntime.evaluationListener?.onPrompt) {
20-
return workerRuntime.evaluationListener.onPrompt(question, type);
21-
}
22-
23-
return '';
19+
return workerRuntime.evaluationListener.onPrompt?.(question, type) ?? '';
2420
},
25-
onPrint(value) {
26-
if (workerRuntime.evaluationListener?.onPrint) {
27-
workerRuntime.evaluationListener.onPrint(value);
21+
onPrint(values) {
22+
return workerRuntime.evaluationListener?.onPrint?.(values);
2823
}
2924
},
3025
toggleTelemetry(enabled) {
31-
if (workerRuntime.evaluationListener?.toggleTelemetry) {
32-
workerRuntime.evaluationListener.toggleTelemetry(enabled);
26+
return workerRuntime.evaluationListener?.toggleTelemetry?.(enabled);
3327
}
3428
},
3529
onClearCommand() {
36-
if (workerRuntime.evaluationListener?.onClearCommand) {
37-
workerRuntime.evaluationListener.onClearCommand();
38-
}
30+
return workerRuntime.evaluationListener.onClearCommand?.();
3931
},
4032
onExit() {
41-
if (workerRuntime.evaluationListener?.onExit) {
42-
return workerRuntime.evaluationListener.onExit();
43-
}
44-
45-
return Promise.resolve() as Promise<never>;
33+
return workerRuntime.evaluationListener?.onExit?.() ??
34+
Promise.resolve() as Promise<never>;
4635
}
4736
},
4837
childProcess

0 commit comments

Comments
 (0)