f626c12e49
全局包安装失败原本只 print 警告,decman 退出码仍为 0,违反声明式语义。 改为汇总后 raise decman.SourceError,符合官方 docstring 推荐(失败应被感知, 下次 sync 会重试)。保留"尝试所有包"逻辑,一次性看到全部失败。
85 lines
2.3 KiB
Python
85 lines
2.3 KiB
Python
import decman
|
|
from decman import File, Module
|
|
from decman.plugins.pacman import packages as pacman_packages
|
|
|
|
BUN_GLOBAL_PACKAGES = [
|
|
"@vue/language-server",
|
|
"dockerfile-language-server-nodejs",
|
|
"opencode-ai",
|
|
]
|
|
|
|
GO_INSTALL_PACKAGES = [
|
|
"github.com/code-yeongyu/go-claude-code-comment-checker/cmd/comment-checker@latest",
|
|
]
|
|
|
|
|
|
class DevModule(Module):
|
|
def __init__(self, user: str):
|
|
super().__init__("dev")
|
|
self.user = user
|
|
|
|
def files(self):
|
|
return {
|
|
f"/home/{self.user}/.config/mise/config.toml": File(
|
|
source_file="./home/.config/mise/config.toml",
|
|
owner=self.user,
|
|
),
|
|
}
|
|
|
|
@pacman_packages
|
|
def pacman_packages(self) -> set[str]:
|
|
return {
|
|
"ast-grep",
|
|
"bash-language-server",
|
|
"biome",
|
|
"bun",
|
|
"github-cli",
|
|
"go",
|
|
"gopls",
|
|
"lazygit",
|
|
"mise",
|
|
"neovim",
|
|
"nodejs",
|
|
"ruff",
|
|
"shellcheck",
|
|
"shfmt",
|
|
"tmux",
|
|
"typescript-language-server",
|
|
"uv",
|
|
"yaml-language-server",
|
|
"zellij",
|
|
}
|
|
|
|
def after_update(self, store):
|
|
failures: list[str] = []
|
|
for pkg in BUN_GLOBAL_PACKAGES:
|
|
try:
|
|
decman.prg(
|
|
[
|
|
"bun",
|
|
"add",
|
|
"-g",
|
|
pkg,
|
|
"--registry=https://registry.npmmirror.com",
|
|
],
|
|
user=self.user,
|
|
mimic_login=True,
|
|
)
|
|
except Exception as e:
|
|
failures.append(f"bun: {pkg} ({e})")
|
|
for pkg in GO_INSTALL_PACKAGES:
|
|
try:
|
|
decman.prg(
|
|
["go", "install", pkg],
|
|
user=self.user,
|
|
env_overrides={"GOPROXY": "https://goproxy.cn"},
|
|
mimic_login=True,
|
|
)
|
|
except Exception as e:
|
|
failures.append(f"go: {pkg} ({e})")
|
|
if failures:
|
|
raise decman.SourceError(
|
|
f"{len(failures)} 个全局包安装失败:\n"
|
|
+ "\n".join(f" - {f}" for f in failures)
|
|
)
|