mirror of
https://github.com/arthur-pbty/arthur-os.git
synced 2026-08-01 20:28:16 +02:00
Allow for lazy-install of bun runtime
This commit is contained in:
+26
-8
@@ -29,22 +29,40 @@ fi
|
||||
node_bin="\$node_root/bin/node"
|
||||
npx_bin="\$node_root/bin/npx"
|
||||
|
||||
ensure_bin_runtime() {
|
||||
local bin_path=\$1
|
||||
local shebang
|
||||
|
||||
IFS= read -r shebang < "\$bin_path"
|
||||
|
||||
if [[ \$shebang == "#!"*"/bun"* || \$shebang == "#!"*"/env bun"* ]]; then
|
||||
if omarchy-cmd-missing bun; then
|
||||
echo "Installing bun runtime for \$package..."
|
||||
omarchy-pkg-add bun
|
||||
hash -r
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
exec_package_bin() {
|
||||
local package_bin_path=\$1
|
||||
|
||||
if [[ -n \$package_bin_path ]]; then
|
||||
ensure_bin_runtime "\$package_bin_path"
|
||||
PATH="\$node_root/bin:\$PATH" exec "\$package_bin_path" "\$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Resolve the package bin inside npx, then run it with node@latest available for node shebangs.
|
||||
# Some wrappers are aliases, e.g. playwright-cli wraps the playwright bin.
|
||||
"\$node_bin" "\$npx_bin" --yes --prefer-online --package "\$package" -- true
|
||||
|
||||
package_bin_path=\$("\$node_bin" "\$npx_bin" --yes --package "\$package" -- which "\$package" 2>/dev/null)
|
||||
|
||||
if [[ -n \$package_bin_path ]]; then
|
||||
PATH="\$node_root/bin:\$PATH" exec "\$package_bin_path" "\$@"
|
||||
fi
|
||||
exec_package_bin "\$package_bin_path" "\$@"
|
||||
|
||||
# Scoped packages like @openai/codex expose an unscoped bin like codex.
|
||||
package_bin_path=\$("\$node_bin" "\$npx_bin" --yes --package "\$package" -- which "\$command" 2>/dev/null)
|
||||
|
||||
if [[ -n \$package_bin_path ]]; then
|
||||
PATH="\$node_root/bin:\$PATH" exec "\$package_bin_path" "\$@"
|
||||
fi
|
||||
exec_package_bin "\$package_bin_path" "\$@"
|
||||
|
||||
echo "Could not resolve npm bin for \$package / \$command" >&2
|
||||
exit 127
|
||||
|
||||
Reference in New Issue
Block a user