@deltachat/stdio-rpc-server 1.138.0 → 1.139.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +2 -0
  2. package/index.d.ts +5 -2
  3. package/index.js +34 -14
  4. package/package.json +15 -11
package/README.md CHANGED
@@ -20,7 +20,9 @@ import { C } from "@deltachat/jsonrpc-client";
20
20
  async function main() {
21
21
  const dc = await startDeltaChat("deltachat-data");
22
22
  console.log(await dc.rpc.getSystemInfo());
23
+ dc.close()
23
24
  }
25
+ main()
24
26
  ```
25
27
 
26
28
  For a more complete example refer to https://github.com/deltachat-bot/echo/pull/69/files (TODO change link when pr is merged).
package/index.d.ts CHANGED
@@ -20,17 +20,20 @@ export function getRPCServerPath(
20
20
 
21
21
 
22
22
  export type DeltaChatOverJsonRpcServer = StdioDeltaChat & {
23
- shutdown: () => Promise<void>;
24
23
  readonly pathToServerBinary: string;
25
24
  };
26
25
 
26
+ export interface StartOptions {
27
+ /** whether to disable outputting stderr to the parent process's stderr */
28
+ muteStdErr: boolean;
29
+ }
27
30
 
28
31
  /**
29
32
  *
30
33
  * @param directory directory for accounts folder
31
34
  * @param options
32
35
  */
33
- export function startDeltaChat(directory: string, options?: Partial<SearchOptions> ): Promise<DeltaChatOverJsonRpcServer>
36
+ export function startDeltaChat(directory: string, options?: Partial<SearchOptions & StartOptions> ): Promise<DeltaChatOverJsonRpcServer>
34
37
 
35
38
 
36
39
  export namespace FnTypes {
package/index.js CHANGED
@@ -22,10 +22,6 @@ import {
22
22
  import package_json from "./package.json" with { type: "json" };
23
23
  import { createRequire } from "node:module";
24
24
 
25
- // exports
26
- // - [ ] a raw starter that has a stdin/out handle thingie like desktop uses
27
- // - [X] a function that already wraps the stdio handle from above into the deltachat jsonrpc bindings
28
-
29
25
  function findRPCServerInNodeModules() {
30
26
  const arch = os.arch();
31
27
  const operating_system = process.platform;
@@ -43,6 +39,32 @@ function findRPCServerInNodeModules() {
43
39
  }
44
40
  }
45
41
 
42
+ /**
43
+ * @returns {Promise<string>}
44
+ */
45
+ async function getLocationInPath() {
46
+ const exec = promisify(execFile);
47
+
48
+ if (os.platform() === "win32") {
49
+ const { stdout: executable } = await exec("where", [PATH_EXECUTABLE_NAME], {
50
+ shell: true,
51
+ });
52
+ return executable;
53
+ }
54
+
55
+ try {
56
+ const { stdout: executable } = await exec(
57
+ "command",
58
+ ["-v", PATH_EXECUTABLE_NAME],
59
+ { shell: true }
60
+ );
61
+ return executable;
62
+ } catch (error) {
63
+ if (error.code > 0) return "";
64
+ else throw error;
65
+ }
66
+ }
67
+
46
68
  /** @type {import("./index").FnTypes.getRPCServerPath} */
47
69
  export async function getRPCServerPath(
48
70
  options = { skipSearchInPath: false, disableEnvPath: false }
@@ -65,19 +87,18 @@ export async function getRPCServerPath(
65
87
 
66
88
  // 2. check if it can be found in PATH
67
89
  if (!process.env[SKIP_SEARCH_IN_PATH] && !skipSearchInPath) {
68
- const exec = promisify(execFile);
69
-
70
- const { stdout: executable } =
71
- os.platform() !== "win32"
72
- ? await exec("command", ["-v", PATH_EXECUTABLE_NAME])
73
- : await exec("where", [PATH_EXECUTABLE_NAME]);
90
+ const executable = await getLocationInPath();
74
91
 
75
92
  // by just trying to execute it and then use "command -v deltachat-rpc-server" (unix) or "where deltachat-rpc-server" (windows) to get the path to the executable
76
93
  if (executable.length > 1) {
77
94
  // test if it is the right version
78
95
  try {
79
96
  // for some unknown reason it is in stderr and not in stdout
80
- const { stderr } = await promisify(execFile)(executable, ["--version"]);
97
+ const { stderr } = await promisify(execFile)(
98
+ executable,
99
+ ["--version"],
100
+ { shell: true }
101
+ );
81
102
  const version = stderr.slice(0, stderr.indexOf("\n"));
82
103
  if (package_json.version !== version) {
83
104
  throw new Error(
@@ -109,6 +130,7 @@ export async function startDeltaChat(directory, options) {
109
130
  RUST_LOG: process.env.RUST_LOG || "info",
110
131
  DC_ACCOUNTS_PATH: directory,
111
132
  },
133
+ stdio: ["pipe", "pipe", options.muteStdErr ? "ignore" : "inherit"],
112
134
  });
113
135
 
114
136
  server.on("error", (err) => {
@@ -123,13 +145,11 @@ export async function startDeltaChat(directory, options) {
123
145
  throw new Error("Server quit");
124
146
  });
125
147
 
126
- server.stderr.pipe(process.stderr);
127
-
128
148
  /** @type {import('./index').DeltaChatOverJsonRpcServer} */
129
149
  //@ts-expect-error
130
150
  const dc = new StdioDeltaChat(server.stdin, server.stdout, true);
131
151
 
132
- dc.shutdown = async () => {
152
+ dc.close = () => {
133
153
  shouldClose = true;
134
154
  if (!server.kill()) {
135
155
  console.log("server termination failed");
package/package.json CHANGED
@@ -3,24 +3,28 @@
3
3
  "main": "index.js",
4
4
  "name": "@deltachat/stdio-rpc-server",
5
5
  "optionalDependencies": {
6
- "@deltachat/stdio-rpc-server-darwin-arm64": "1.138.0",
7
- "@deltachat/stdio-rpc-server-android-arm64": "1.138.0",
8
- "@deltachat/stdio-rpc-server-linux-arm64": "1.138.0",
9
- "@deltachat/stdio-rpc-server-linux-arm": "1.138.0",
10
- "@deltachat/stdio-rpc-server-android-arm": "1.138.0",
11
- "@deltachat/stdio-rpc-server-win32-i32": "1.138.0",
12
- "@deltachat/stdio-rpc-server-linux-i32": "1.138.0",
13
- "@deltachat/stdio-rpc-server-darwin-x64": "1.138.0",
14
- "@deltachat/stdio-rpc-server-win32-x64": "1.138.0",
15
- "@deltachat/stdio-rpc-server-linux-x64": "1.138.0"
6
+ "@deltachat/stdio-rpc-server-darwin-arm64": "1.139.0",
7
+ "@deltachat/stdio-rpc-server-android-arm64": "1.139.0",
8
+ "@deltachat/stdio-rpc-server-linux-arm64": "1.139.0",
9
+ "@deltachat/stdio-rpc-server-linux-arm": "1.139.0",
10
+ "@deltachat/stdio-rpc-server-android-arm": "1.139.0",
11
+ "@deltachat/stdio-rpc-server-win32-ia32": "1.139.0",
12
+ "@deltachat/stdio-rpc-server-linux-ia32": "1.139.0",
13
+ "@deltachat/stdio-rpc-server-darwin-x64": "1.139.0",
14
+ "@deltachat/stdio-rpc-server-win32-x64": "1.139.0",
15
+ "@deltachat/stdio-rpc-server-linux-x64": "1.139.0"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "@deltachat/jsonrpc-client": "*"
19
19
  },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/deltachat/deltachat-core-rust.git"
23
+ },
20
24
  "scripts": {
21
25
  "prepack": "node scripts/update_optional_dependencies_and_version.js"
22
26
  },
23
27
  "type": "module",
24
28
  "types": "index.d.ts",
25
- "version": "1.138.0"
29
+ "version": "1.139.0"
26
30
  }