gpui-bridge 0.0.0-stage → 0.2.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.
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ // Public API of the gpui-bridge Node client.
2
+ import { existsSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import { dirname, join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { connect } from "./app.js";
7
+ import { HostProcess } from "./host-process.js";
8
+ export * from "./app.js";
9
+ export * from "./protocol.js";
10
+ const exe = process.platform === "win32" ? "gpui-bridge-host.exe" : "gpui-bridge-host";
11
+ // dist/index.js -> the package root
12
+ const pkg = join(dirname(fileURLToPath(import.meta.url)), "..");
13
+ const nodeRequire = createRequire(import.meta.url);
14
+ // The platform the host must run on, and the suffix of the package that ships it.
15
+ const platform = `${process.platform}-${process.arch}`;
16
+ /**
17
+ * Walks up from this file looking for a Cargo build of the host. The number of folders
18
+ * between a client and the workspace root is not part of the contract, so this survives
19
+ * a client moving inside `packages/` (or anywhere else).
20
+ */
21
+ function repoTarget() {
22
+ let dir = dirname(fileURLToPath(import.meta.url));
23
+ for (let depth = 0; depth < 6; depth++) {
24
+ for (const profile of ["debug", "release"]) {
25
+ const candidate = join(dir, "target", profile, exe);
26
+ if (existsSync(candidate))
27
+ return candidate;
28
+ }
29
+ dir = dirname(dir);
30
+ }
31
+ return undefined;
32
+ }
33
+ /**
34
+ * The binary of `@indios/gpui-bridge-<platform>-<arch>`, an optional dependency of this package:
35
+ * npm and pnpm install only the one whose `os`/`cpu` match the machine, so whatever is
36
+ * installed here is a host this machine can run. That package carries no code, only the
37
+ * asset, so it is found through its manifest (it declares no `exports` to walk).
38
+ */
39
+ function packagedHost() {
40
+ try {
41
+ const manifest = nodeRequire.resolve(`@indios/gpui-bridge-${platform}/package.json`);
42
+ const candidate = join(dirname(manifest), "bin", exe);
43
+ return existsSync(candidate) ? candidate : undefined;
44
+ }
45
+ catch {
46
+ return undefined; // another platform, or a checkout where the asset was never staged
47
+ }
48
+ }
49
+ /** The host to run: `$GPUI_BRIDGE_HOST`, then the packaged one, then a build in this repository. */
50
+ export function defaultHostPath() {
51
+ return process.env.GPUI_BRIDGE_HOST ?? packagedHost() ?? repoTarget() ?? join(pkg, "..", "..", "..", "target", "debug", exe);
52
+ }
53
+ /** Starts the host and completes the handshake. Rejects with a clear message if the host cannot start. */
54
+ export function createApp(options = {}) {
55
+ const path = options.hostPath ?? defaultHostPath();
56
+ const args = options.headless ? ["--no-window"] : [];
57
+ return connect(path, (events) => new HostProcess({ path, args, debug: options.debug ?? false, ...events }));
58
+ }