webmcp_everywhere 0.1.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.
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # The executable Chrome starts for the native messaging host, in a packaged release.
4
+ #
5
+ # Chrome reads the path of this file from the host manifest the installer writes, and starts it with
6
+ # a very small environment. So the script holds no absolute path of its own: it finds the bundled
7
+ # host beside itself, and it looks for a Node.js instead of naming one. The whole program is one
8
+ # `exec`, because Chrome talks to the process it starts over standard input and standard output, and
9
+ # any extra process in between would break that.
10
+
11
+ set -euo pipefail
12
+
13
+ scriptDir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
14
+ hostBundle="${scriptDir}/webmcp_native_host.mjs"
15
+
16
+ # Answers whether a Node.js can run the bundled host, which is an ECMAScript module.
17
+ runsTheHost() {
18
+ local candidate="$1"
19
+ local version major
20
+ version="$("${candidate}" --version 2>/dev/null)" || return 1
21
+ version="${version#v}"
22
+ major="${version%%.*}"
23
+ if [ "${major}" -ge 20 ]; then
24
+ return 0
25
+ fi
26
+ return 1
27
+ }
28
+
29
+ # Prints the first usable Node.js, or fails when there is none.
30
+ findNode() {
31
+ local candidate
32
+ for candidate in \
33
+ "$(command -v node 2>/dev/null || true)" \
34
+ /opt/homebrew/bin/node \
35
+ /usr/local/bin/node \
36
+ /usr/bin/node; do
37
+ if [ -n "${candidate}" ] && [ -x "${candidate}" ] && runsTheHost "${candidate}"; then
38
+ echo "${candidate}"
39
+ return 0
40
+ fi
41
+ done
42
+ return 1
43
+ }
44
+
45
+ # The message goes to standard error, never to standard output, which belongs to Chrome alone.
46
+ nodeBinary="$(findNode)" || {
47
+ echo "webmcp_native_host.sh: found no Node.js 20 or later" >&2
48
+ exit 1
49
+ }
50
+
51
+ exec "${nodeBinary}" "${hostBundle}" "$@"