refactor(@deltachat/stdio-rpc-server): make getRPCServerPath and startDeltaChat synchronous

This commit is contained in:
DavidSM100
2025-12-04 18:27:27 -05:00
committed by l
parent 602f0a088e
commit be920bf3bf
2 changed files with 7 additions and 7 deletions

View File

@@ -15,7 +15,7 @@ export interface SearchOptions {
*/ */
export function getRPCServerPath( export function getRPCServerPath(
options?: Partial<SearchOptions> options?: Partial<SearchOptions>
): Promise<string>; ): string;
@@ -33,7 +33,7 @@ export interface StartOptions {
* @param directory directory for accounts folder * @param directory directory for accounts folder
* @param options * @param options
*/ */
export function startDeltaChat(directory: string, options?: Partial<SearchOptions & StartOptions> ): Promise<DeltaChatOverJsonRpcServer> export function startDeltaChat(directory: string, options?: Partial<SearchOptions & StartOptions> ): DeltaChatOverJsonRpcServer
export namespace FnTypes { export namespace FnTypes {

View File

@@ -1,6 +1,6 @@
//@ts-check //@ts-check
import { spawn } from "node:child_process"; import { spawn } from "node:child_process";
import { stat } from "node:fs/promises"; import { statSync } from "node:fs";
import os from "node:os"; import os from "node:os";
import process from "node:process"; import process from "node:process";
import { ENV_VAR_NAME, PATH_EXECUTABLE_NAME } from "./src/const.js"; import { ENV_VAR_NAME, PATH_EXECUTABLE_NAME } from "./src/const.js";
@@ -36,7 +36,7 @@ function findRPCServerInNodeModules() {
} }
/** @type {import("./index").FnTypes.getRPCServerPath} */ /** @type {import("./index").FnTypes.getRPCServerPath} */
export async function getRPCServerPath(options = {}) { export function getRPCServerPath(options = {}) {
const { takeVersionFromPATH, disableEnvPath } = { const { takeVersionFromPATH, disableEnvPath } = {
takeVersionFromPATH: false, takeVersionFromPATH: false,
disableEnvPath: false, disableEnvPath: false,
@@ -45,7 +45,7 @@ export async function getRPCServerPath(options = {}) {
// 1. check if it is set as env var // 1. check if it is set as env var
if (process.env[ENV_VAR_NAME] && !disableEnvPath) { if (process.env[ENV_VAR_NAME] && !disableEnvPath) {
try { try {
if (!(await stat(process.env[ENV_VAR_NAME])).isFile()) { if (!statSync(process.env[ENV_VAR_NAME]).isFile()) {
throw new Error( throw new Error(
`expected ${ENV_VAR_NAME} to point to the deltachat-rpc-server executable` `expected ${ENV_VAR_NAME} to point to the deltachat-rpc-server executable`
); );
@@ -68,8 +68,8 @@ export async function getRPCServerPath(options = {}) {
import { StdioDeltaChat } from "@deltachat/jsonrpc-client"; import { StdioDeltaChat } from "@deltachat/jsonrpc-client";
/** @type {import("./index").FnTypes.startDeltaChat} */ /** @type {import("./index").FnTypes.startDeltaChat} */
export async function startDeltaChat(directory, options = {}) { export function startDeltaChat(directory, options = {}) {
const pathToServerBinary = await getRPCServerPath(options); const pathToServerBinary = getRPCServerPath(options);
const server = spawn(pathToServerBinary, { const server = spawn(pathToServerBinary, {
env: { env: {
RUST_LOG: process.env.RUST_LOG, RUST_LOG: process.env.RUST_LOG,