Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .devcontainer/codespaces/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "Config Base (Codespaces)",
"image": "ghcr.io/keito4/config-base:1.62.2",
"features": {
"ghcr.io/devcontainers/features/sshd:1": {},
"ghcr.io/devcontainers-extra/features/homebrew-package:1": {},
"ghcr.io/eitsupi/devcontainer-features/jq-likes:2": {},
"ghcr.io/devcontainers/features/node:1": {
Expand Down Expand Up @@ -67,5 +68,6 @@
"description": "Gemini CLI google_accounts.json (base64 encoded)"
}
},
"postCreateCommand": "/workspaces/config/script/install-npm-globals.sh",
"postStartCommand": "/usr/local/script/install-skills.sh && /usr/local/script/restore-cli-auth.sh"
}
64 changes: 64 additions & 0 deletions script/install-npm-globals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
# ============================================================================
# Install npm global packages from npm/global.json
# ============================================================================
# Codespaces の Node.js feature がグローバルパッケージをリセットするため、
# postCreateCommand でこのスクリプトを実行して再インストール
#
# Usage: ./script/install-npm-globals.sh

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="${SCRIPT_DIR}/.."
GLOBAL_JSON="${REPO_ROOT}/npm/global.json"

# 色定義
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'

info() { echo -e "${BLUE}[INFO]${NC} $1"; }
success() { echo -e "${GREEN}✓${NC} $1"; }
error() { echo -e "${RED}ERROR:${NC} $1" >&2; }

if [[ ! -f "$GLOBAL_JSON" ]]; then
error "npm/global.json not found: $GLOBAL_JSON"
exit 1
fi

# インストールするパッケージリスト(Node.js feature でリセットされるもの)
PACKAGES=(
"happy-coder"
"@openai/codex"
"@google/gemini-cli"
"vercel"
)

info "Installing npm global packages from npm/global.json..."

for pkg in "${PACKAGES[@]}"; do
version=$(node -pe "require('${GLOBAL_JSON}').dependencies['${pkg}']?.version || ''" 2>/dev/null || echo "")

if [[ -z "$version" ]]; then
info "Skipping $pkg (not found in global.json)"
continue
fi

# 既にインストール済みかチェック
installed_version=$(npm list -g "$pkg" --depth=0 2>/dev/null | grep "$pkg@" | sed 's/.*@//' || echo "")

if [[ "$installed_version" == "$version" ]]; then
success "$pkg@$version (already installed)"
else
info "Installing $pkg@$version..."
if npm install -g "${pkg}@${version}" --silent 2>/dev/null; then
success "$pkg@$version"
else
error "Failed to install $pkg@$version"
fi
fi
Comment on lines +54 to +61

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Install failures are silently swallowed — script exits 0 regardless.

When npm install -g fails, the error is logged but the script continues and ultimately exits 0. Since this runs as postCreateCommand, a silent success could leave the Codespace in a broken state without the user noticing (e.g., happy-coder missing). Consider tracking failures and exiting non-zero at the end.

♻️ Suggested approach
+fail_count=0
+
 for pkg in "${PACKAGES[@]}"; do
     ...
         if npm install -g "${pkg}@${version}" --silent 2>/dev/null; then
             success "$pkg@$version"
         else
             error "Failed to install $pkg@$version"
+            ((fail_count++))
         fi
     fi
 done

-info "Done!"
+if [[ $fail_count -gt 0 ]]; then
+    error "$fail_count package(s) failed to install"
+    exit 1
+fi
+
+info "Done!"
🤖 Prompt for AI Agents
In `@script/install-npm-globals.sh` around lines 54 - 61, The npm install failures
are logged but ignored; modify the install loop around npm install -g
"${pkg}@${version}" so that failures are tracked and cause a non‑zero exit:
introduce a failure flag (e.g., INSTALL_FAIL=0) and set it to 1 in the else
branch that runs error "Failed to install $pkg@$version", then after the loop
check the flag (if INSTALL_FAIL -ne 0) and exit 1 (or exit with a
combined/nonzero status). Ensure you reference the existing variables pkg and
version and the npm install command so the flag-setting logic is added in the
same block and the final exit occurs after all packages are processed.

done

info "Done!"
Loading