Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix: add node.js when packing dmg

huanggawadb84f06bf043
diff --git a/.gitignore b/.gitignore
index 50948b42aa..3dea63f66f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,8 @@ htmlcov/
**/node_modules/
dist/
build/
+# 构建时下载的 Node 运行时缓存(build-macos.sh / build-exe.ps1 用),不入库
+vendor/node/
coverage/
jiuwenswarm/channels/web/frontend/logs/
jiuwenswarm/channels/web/frontend/cd
diff --git a/scripts/build-macos.sh b/scripts/build-macos.sh
index 15317ccd31..81018a11ab 100644
--- a/scripts/build-macos.sh
+++ b/scripts/build-macos.sh
@@ -10,6 +10,73 @@ DMG_ROOT="$PROJECT_ROOT/dist/dmg-root"
VERSION="0.2.3.beta1"
DMG_PATH="$PROJECT_ROOT/dist/JiuwenSwarm-$VERSION.dmg"
+# ── 内置 Node 运行时(单架构,M 系列优先 arm64)─────────────────
+# 任选 ≥ v18 的 LTS;v20/v22 为推荐版本。可用环境变量覆盖。
+NODE_VERSION="${NODE_VERSION:-v22.11.0}"
+BUNDLE_NODE="${BUNDLE_NODE:-1}" # 0=跳过内置 node
+
+# 返回构建机的 Node 架构名。M 系列(arm64) 优先;Intel 回退 x64。
+resolve_node_arch() {
+ case "$(uname -m)" in
+ arm64) echo "arm64" ;;
+ *) echo "x64" ;;
+ esac
+}
+
+# 解析 Node 运行时来源,优先级:$NODE_DIR > vendor/node > nodejs.org 官方下载
+resolve_node_dir() {
+ if [[ -n "${NODE_DIR:-}" && -x "$NODE_DIR/bin/node" ]]; then
+ echo "$NODE_DIR"; return
+ fi
+ local vendored="$PROJECT_ROOT/vendor/node"
+ if [[ -x "$vendored/bin/node" ]]; then
+ echo "$vendored"; return
+ fi
+ local arch dir url
+ arch="$(resolve_node_arch)"
+ dir="$vendored"
+ printf 'Downloading Node %s (%s) from nodejs.org...\n' "$NODE_VERSION" "$arch"
+ url="https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-darwin-${arch}.tar.gz"
+ mkdir -p "$PROJECT_ROOT/vendor"
+
+ # 先把 tarball 下载、解压到临时目录,校验 bin/node 可执行后,
+ # 再 rm -rf 旧缓存并原子替换。任一步失败都不会破坏已有 vendor/node。
+ local tmpdir staged tarball
+ tmpdir="$(mktemp -d)"
+ tarball="$tmpdir/node.tar.gz"
+ staged="$tmpdir/node-${NODE_VERSION}-darwin-${arch}"
+
+ if ! curl -fL "$url" -o "$tarball"; then
+ rm -rf "$tmpdir"
+ printf 'Error: failed to download %s\n' "$url" >&2
+ return 1
+ fi
+
+ tar -xzf "$tarball" -C "$tmpdir"
+ if [[ ! -x "$staged/bin/node" ]]; then
+ rm -rf "$tmpdir"
+ printf 'Error: extracted tarball missing executable bin/node\n' >&2
+ return 1
+ fi
+
+ rm -rf "$dir" # 仅在替换物校验通过后才删旧缓存
+ mv "$staged" "$dir"
+ rm -rf "$tmpdir"
+ echo "$dir"
+}
+
+# 把 Node 运行时拷进 .app 包的 Contents/Resources/node-runtime
+copy_node_into_app() {
+ local src="$1"
+ local dest="$APP_PATH/Contents/Resources/node-runtime"
+ rm -rf "$dest"
+ mkdir -p "$dest"
+ # cp -R 保留 npx/npm 符号链接(指向 ../lib/node_modules/...)与可执行位。
+ cp -R "$src/." "$dest/"
+ printf 'Bundled Node %s (%s) into app: %s\n' \
+ "$( "$dest/bin/node" --version )" "$(resolve_node_arch)" "$dest"
+}
+
printf '=== JiuwenSwarm macOS package build ===\n'
printf 'Project root: %s\n\n' "$PROJECT_ROOT"
@@ -59,6 +126,14 @@ if [[ -n "$TUI_BINARY" && -f "$TUI_BINARY" ]]; then
chmod +x "$APP_PATH/Contents/MacOS/jiuwenswarm-tui"
fi
+# 内置 Node 运行时:在打 DMG 之前暂存进 .app,随后 cp -R app 到 dmg-root
+# 会把它一并卷进 DMG。
+if [[ "$BUNDLE_NODE" == "1" ]]; then
+ printf '\n[4.5/5] Bundle Node.js runtime (single arch, M-series first)...\n'
+ NODE_SRC="$(resolve_node_dir)" || exit 1
+ copy_node_into_app "$NODE_SRC"
+fi
+
printf '\n[5/5] Create DMG...\n'
rm -rf "$DMG_ROOT"
mkdir -p "$DMG_ROOT"
diff --git a/scripts/jiuwenswarm_exe_entry.py b/scripts/jiuwenswarm_exe_entry.py
index 716ea044ae..493eb78f3e 100644
--- a/scripts/jiuwenswarm_exe_entry.py
+++ b/scripts/jiuwenswarm_exe_entry.py
@@ -42,10 +42,23 @@ if getattr(sys, "frozen", False):
except Exception: # noqa: BLE001
pass
+ # macOS:把 .app 内置的 node-runtime/bin 前置到 PATH,使 shutil.which("npx")
+ # 与 playwright_runtime 默认的 "npx" 命令命中内置 Node(> v18),
+ # 用户无需单独安装 Node。入口脚本是所有冻结进程(主进程 + --desktop-run-*
+ # 子进程)的共同入口,PATH 在每个进程启动时都会被前置,幂等且随子进程继承。
+ if sys.platform == "darwin":
+ _node_bin = (
+ Path(sys.executable).resolve().parent.parent
+ / "Resources" / "node-runtime" / "bin"
+ )
+ if _node_bin.is_dir():
+ _old_path = os.environ.get("PATH", "")
+ os.environ["PATH"] = (
+ f"{_node_bin}{os.pathsep}{_old_path}" if _old_path else str(_node_bin)
# Windows: use the Node runtime bundled by scripts/build-exe.ps1, when present.
# This makes browser runtime's default "npx" command work on machines without
# a system Node.js installation. Frozen child processes inherit this PATH too.
- if os.name == "nt":
+ elif os.name == "nt":
_node_runtime = Path(sys.executable).resolve().parent / "runtime" / "node-runtime"
if (_node_runtime / "npx.cmd").is_file():
_old_path = os.environ.get("PATH", "")