@nativedesktop/host 0.1.0 → 0.1.1
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/package.json +1 -1
- package/src/index.test.ts +18 -1
- package/src/index.ts +18 -3
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// layout. Run with: bun test packages/host/
|
|
4
4
|
import { test, expect } from "bun:test";
|
|
5
5
|
import { resolve } from "node:path";
|
|
6
|
-
import { hostBinaryCandidates, hostPackageName, hostPlatformKey, resolveBackend } from "./index.ts";
|
|
6
|
+
import { hostBinaryCandidates, hostPackageName, hostPlatformKey, resolveBackend, resolveHostBinary } from "./index.ts";
|
|
7
7
|
|
|
8
8
|
// --- backend selection: platform × env × flag ------------------------------
|
|
9
9
|
|
|
@@ -82,3 +82,20 @@ test("hostPlatformKey rejects unsupported platforms", () => {
|
|
|
82
82
|
expect(hostPlatformKey("darwin", "arm64")).toBe("darwin-arm64");
|
|
83
83
|
expect(() => hostPlatformKey("sunos", "arm64")).toThrow(/unsupported platform/);
|
|
84
84
|
});
|
|
85
|
+
|
|
86
|
+
// --- resolveHostBinary error path: gtk on macOS, installed (not a checkout) ---
|
|
87
|
+
|
|
88
|
+
test("gtk on darwin outside a source checkout states the three real options", async () => {
|
|
89
|
+
// packageDir has no build.zig/swift two levels up, so isSourceCheckout is
|
|
90
|
+
// false -- the shape of an installed copy inside some other project's
|
|
91
|
+
// node_modules (packageName is already undefined for gtk+darwin regardless
|
|
92
|
+
// of packageDir, since PLATFORM_PACKAGES has no entry for it).
|
|
93
|
+
const err = await resolveHostBinary({ backend: "gtk", platform: "darwin", arch: "arm64", packageDir: "/tmp/not-a-checkout/node_modules/@nativedesktop/host" }).catch(
|
|
94
|
+
(e: Error) => e,
|
|
95
|
+
);
|
|
96
|
+
expect(err).toBeInstanceOf(Error);
|
|
97
|
+
const message = (err as Error).message;
|
|
98
|
+
expect(message).toContain("by design");
|
|
99
|
+
expect(message).toContain("source checkout");
|
|
100
|
+
expect(message).toContain("explicit binary path");
|
|
101
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -139,9 +139,11 @@ function isSourceCheckout(repoRoot: string): boolean {
|
|
|
139
139
|
* Outside a checkout with no prebuilt, throws naming the missing platform
|
|
140
140
|
* package (or the supported target list when none exists for this machine).
|
|
141
141
|
*/
|
|
142
|
-
export async function resolveHostBinary(
|
|
142
|
+
export async function resolveHostBinary(
|
|
143
|
+
opts: { backend?: Backend; platform?: string; arch?: string; packageDir?: string } = {},
|
|
144
|
+
): Promise<string> {
|
|
143
145
|
const backend = resolveBackend(opts);
|
|
144
|
-
const { packageName, binaryName, repoRoot, fresh } = hostBinaryCandidates(backend);
|
|
146
|
+
const { packageName, binaryName, repoRoot, fresh } = hostBinaryCandidates(backend, opts);
|
|
145
147
|
const prebuilt = prebuiltHostBinary(backend);
|
|
146
148
|
const source = isSourceCheckout(repoRoot);
|
|
147
149
|
|
|
@@ -163,12 +165,25 @@ export async function resolveHostBinary(opts: { backend?: Backend } = {}): Promi
|
|
|
163
165
|
return buildBackend(backend, repoRoot, fresh);
|
|
164
166
|
}
|
|
165
167
|
|
|
168
|
+
const key = hostPlatformKey(opts.platform, opts.arch);
|
|
169
|
+
// gtk-on-macOS is the one combination that will never get a package entry
|
|
170
|
+
// (see PLATFORM_PACKAGES above), so the generic "unsupported target" hint
|
|
171
|
+
// below reads as a dead end instead of the three real ways forward. State
|
|
172
|
+
// them explicitly: this is by design, not missing packaging.
|
|
173
|
+
if (!packageName && backend === "gtk" && key.startsWith("darwin-")) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`@nativedesktop/host: no gtk host binary for "${key}". The gtk backend ships no macOS prebuilt ` +
|
|
176
|
+
`by design (it links Homebrew paths). Either build one from a NativeDesktop source checkout ` +
|
|
177
|
+
`(${backendBuildHint(backend)}), or pass an explicit binary path instead of resolving one ` +
|
|
178
|
+
`(e.g. launchApp({ hostBinary }) in @nativedesktop/test).`,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
166
181
|
const hint = packageName
|
|
167
182
|
? `Expected ${packageName}/bin/${binaryName} (an optionalDependency of @nativedesktop/host); ` +
|
|
168
183
|
`reinstall without --no-optional, or build in a NativeDesktop checkout (${backendBuildHint(backend)}).`
|
|
169
184
|
: `No prebuilt package exists for this target; supported targets are darwin-arm64 (appkit) and ` +
|
|
170
185
|
`linux-x64 (gtk). Build in a NativeDesktop checkout (${backendBuildHint(backend)}).`;
|
|
171
|
-
throw new Error(`@nativedesktop/host: no ${backend} host binary for "${
|
|
186
|
+
throw new Error(`@nativedesktop/host: no ${backend} host binary for "${key}". ${hint}`);
|
|
172
187
|
}
|
|
173
188
|
|
|
174
189
|
function backendBuildHint(backend: Backend): string {
|