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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.jsx text eol=lf
*.css text eol=lf
*.json text eol=lf
.husky/* text eol=lf
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,7 @@ sketch
storybook-static/

# End of https://www.toptal.com/developers/gitignore/api/node,react,storybookjs

# Documentation managed in GitHub Issues
docs/

95 changes: 95 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/sh

# Bun が利用できない環境(GUI Git クライアント等)では警告を出してスキップする
if ! command -v bun >/dev/null 2>&1; then
echo "[WARN] bun コマンドが見つからないため、セキュリティ監査をスキップします。"
exit 0
fi

CHECK_LOCK=0
CHECK_BUN_VERSION=0

ZERO_SHA="0000000000000000000000000000000000000000"

# push されるすべての ref 行を処理(Windows Git Bash の \r 混入を除去)
while read -r local_ref local_sha remote_ref remote_sha; do
local_sha=$(echo "$local_sha" | tr -d '\r')
remote_sha=$(echo "$remote_sha" | tr -d '\r')

# ブランチ削除時はスキップ
if [ "$local_sha" = "$ZERO_SHA" ] || [ -z "$local_sha" ]; then
continue
fi

CHANGED_FILES=""

# 差分ファイルの取得
if [ "$remote_sha" = "$ZERO_SHA" ]; then
# 新規ブランチ push 時: リモート未反映のコミット群から変更ファイル一覧を取得(マージコミット含む)
COMMITS=$(git rev-list "$local_sha" --not --remotes 2>/dev/null)
if [ -n "$COMMITS" ]; then
CHANGED_FILES=$(git log --name-only --pretty=format: $COMMITS 2>/dev/null | sort -u)
else
# コミットが見つからない場合はブランチの直近ツリーを走査
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r -m "$local_sha" 2>/dev/null)
fi
else
# 通常更新時: remote_sha がローカルに存在するか確認(fetch 漏れや force push 対策)
if git cat-file -e "$remote_sha" 2>/dev/null; then
CHANGED_FILES=$(git log --name-only --pretty=format: "$remote_sha..$local_sha" 2>/dev/null | sort -u)
else
# remote_sha が存在しない場合はローカルの未 push コミットへフォールバック
COMMITS=$(git rev-list "$local_sha" --not --remotes 2>/dev/null)
if [ -n "$COMMITS" ]; then
CHANGED_FILES=$(git log --name-only --pretty=format: $COMMITS 2>/dev/null | sort -u)
else
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r -m "$local_sha" 2>/dev/null)
fi
fi
fi

if echo "$CHANGED_FILES" | grep -q "^bun\.lock$"; then
CHECK_LOCK=1
fi
if echo "$CHANGED_FILES" | grep -q "^mise\.toml$"; then
CHECK_BUN_VERSION=1
fi
done

# 1. 依存パッケージの脆弱性検査 (bun.lock 変更時)
if [ "$CHECK_LOCK" -eq 1 ]; then
echo "[pre-push] bun.lock の変更を検知しました。依存パッケージの脆弱性を検査します..."
AUDIT_OUTPUT=$(bun audit --audit-level=critical 2>&1)
AUDIT_EXIT=$?

if [ "$AUDIT_EXIT" -ne 0 ]; then
# オフラインや通信エラー(error: POST ... など行頭に error: がある場合)は警告を出して通過
if echo "$AUDIT_OUTPUT" | grep -qE '^error:'; then
echo "[WARN] bun audit で通信エラーが発生しました。オフライン等のため push を許可します:"
echo "$AUDIT_OUTPUT"
else
echo "[ERROR] bun.lock に Critical レベルの脆弱性が検出されました。push を中断します:"
echo "$AUDIT_OUTPUT"
echo ""
echo "回避して push する必要がある場合は 'git push --no-verify' を使用してください。"
exit 1
fi
else
echo "[pre-push] bun.lock の Critical 脆弱性検査に合格しました。"
fi
fi

# 2. Bun ランタイム本体の脆弱性検査 (mise.toml 変更時)
if [ "$CHECK_BUN_VERSION" -eq 1 ]; then
echo "[pre-push] mise.toml の変更を検知しました。固定された Bun の脆弱性を検査します..."
bun scripts/audit-bun.ts
BUN_AUDIT_EXIT=$?

if [ "$BUN_AUDIT_EXIT" -ne 0 ]; then
echo "[ERROR] 固定された Bun バージョンに重大な脆弱性が検出されたため、push を中断します。"
echo "回避して push する必要がある場合は 'git push --no-verify' を使用してください。"
exit 1
fi
fi

exit 0
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ Vite + React 19 + TypeScript のプロジェクトテンプレート
- Vite 8
- TypeScript 5.9
- Biome (Linter / Formatter)
- Husky (pre-commit hook)
- Husky (pre-commit / pre-push hook)
- mise (ランタイムバージョン管理)
- Claude Code GitHub Actions (コードレビュー / Issue対応)

## 開発環境のセットアップ

本テンプレートは `mise` で Bun のバージョンを固定しています。

```bash
# mise が導入されている場合、指定バージョンをインストール
mise install

# 依存パッケージの導入
bun install
```

## 使い方

1. "Use this template" ボタンからリポジトリを作成
2. `bun install`
2. `mise install && bun install`
3. `bun run dev`

## スクリプト一覧
Expand All @@ -25,6 +38,29 @@ Vite + React 19 + TypeScript のプロジェクトテンプレート
- `bun run format` — Biome でフォーマット
- `bun run check:fix` — Biome でリント+自動修正
- `bun run preview` — ビルド結果のプレビュー
- `bun run test` — 単体テスト実行
- `bun run audit:deps` — 依存パッケージの脆弱性検査(Critical)
- `bun run audit:tools` — 上流 Bun ランタイムの脆弱性照合
- `bun run audit:all` — 依存パッケージおよび Bun ランタイムの全件検査

## セキュリティ検査(Git フック)

Husky によるローカルフックを設定しています。

- **pre-commit**: ステージされたファイルに Biome による検査・整形を実行します。
- **pre-push**:
- `bun.lock` の変更時: `bun audit --audit-level=critical` を実行し、Critical 脆弱性があれば push を中断します。
- `mise.toml` の変更時: 上流リポジトリ(`oven-sh/bun`)の公開 Advisory と照合し、High 以上の脆弱性があれば push を中断します。
- オフライン時や外部 API 障害時は、警告を表示した上で push を許可します。
- ※GitHub API の未認証レートリミット(60回/時)対策として、CI や共有 IP 環境では `GITHUB_TOKEN` または `GH_TOKEN` の環境変数設定を推奨します。

### フックのスキップ

緊急時やオフライン時にフックの検査を回避して push する必要がある場合は、`--no-verify` オプションを使用します。

```bash
git push --no-verify
```

## 規約

Expand Down
52 changes: 52 additions & 0 deletions mise.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
bun = "1.4.4"
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"format": "biome format --write .",
"check:fix": "biome check --write .",
"preview": "vite preview",
"prepare": "husky"
"prepare": "husky",
"test": "bun test",
"audit:deps": "bun audit --audit-level=critical",
"audit:tools": "bun scripts/audit-bun.ts",
"audit:all": "bun run audit:deps && bun run audit:tools"
},
"dependencies": {
"react": "^19.2.7",
Expand Down
Loading
Loading