mcpField
D
dependency-upgrade

dependency-upgrade

github.com/ovachiever開発5648 回インストール48 週間前に更新
リポジトリ

dependency-upgrade について

dependency-upgrade は、アプリケーションや開発ツールチェーンを保守する開発者向けの依存関係アップグレードスキルです。互換性の分析、段階的な更新、テスト検証、自動更新を扱います。

主な機能

  1. 01依存関係の監査とツリー分析
  2. 02バージョン互換性マトリクス
  3. 03段階的なアップグレード戦略
  4. 04ユニット・統合・E2E テスト
  5. 05Renovate と Dependabot による自動更新

活用シーン

  1. 01フレームワークのメジャーバージョン更新の計画
  2. 02既知の脆弱性がある依存関係の更新
  3. 03依存関係の競合や互換性問題の調査
  4. 04更新後のテストとロールバック計画の策定

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/ovachiever/droid-tings --skill dependency-upgrade

インストール後、Claude Code で/dependency-upgradeを入力して読み込まれたか確認します。

詳細

依存関係のアップグレード

メジャーな依存関係のバージョンアップ、互換性分析、段階的なアップグレード戦略、包括的なテスト手法を習得します。

このスキルを使う場面

  • メジャーなフレームワークのバージョンをアップグレードするとき
  • セキュリティ上の脆弱性がある依存関係を更新するとき
  • レガシーな依存関係を最新化するとき
  • 依存関係の競合を解決するとき
  • 段階的なアップグレード手順を計画するとき
  • 互換性マトリクスをテストするとき
  • 依存関係の更新を自動化するとき

セマンティックバージョニングの確認

MAJOR.MINOR.PATCH (e.g., 2.3.1)

MAJOR: Breaking changes
MINOR: New features, backward compatible
PATCH: Bug fixes, backward compatible

^2.3.1 = >=2.3.1 <3.0.0 (minor updates)
~2.3.1 = >=2.3.1 <2.4.0 (patch updates)
2.3.1 = exact version

依存関係の分析

依存関係を監査する
# npm
npm outdated
npm audit
npm audit fix

# yarn
yarn outdated
yarn audit

# Check for major updates
npx npm-check-updates
npx npm-check-updates -u  # Update package.json
依存関係ツリーを分析する
# See why a package is installed
npm ls package-name
yarn why package-name

# Find duplicate packages
npm dedupe
yarn dedupe

# Visualize dependencies
npx madge --image graph.png src/

互換性マトリクス

// compatibility-matrix.js
const compatibilityMatrix = {
  'react': {
    '16.x': {
      'react-dom': '^16.0.0',
      'react-router-dom': '^5.0.0',
      '@testing-library/react': '^11.0.0'
    },
    '17.x': {
      'react-dom': '^17.0.0',
      'react-router-dom': '^5.0.0 || ^6.0.0',
      '@testing-library/react': '^12.0.0'
    },
    '18.x': {
      'react-dom': '^18.0.0',
      'react-router-dom': '^6.0.0',
      '@testing-library/react': '^13.0.0'
    }
  }
};

function checkCompatibility(packages) {
  // Validate package versions against matrix
}

段階的なアップグレード戦略

フェーズ 1:計画
# 1. Identify current versions
npm list --depth=0

# 2. Check for breaking changes
# Read CHANGELOG.md and MIGRATION.md

# 3. Create upgrade plan
echo "Upgrade order:
1. TypeScript
2. React
3. React Router
4. Testing libraries
5. Build tools" > UPGRADE_PLAN.md
フェーズ 2:段階的な更新
# Don't upgrade everything at once!

# Step 1: Update TypeScript
npm install typescript@latest

# Test
npm run test
npm run build

# Step 2: Update React (one major version at a time)
npm install react@17 react-dom@17

# Test again
npm run test

# Step 3: Continue with other packages
npm install react-router-dom@6

# And so on...
フェーズ 3:検証
// tests/compatibility.test.js
describe('Dependency Compatibility', () => {
  it('should have compatible React versions', () => {
    const reactVersion = require('react/package.json').version;
    const reactDomVersion = require('react-dom/package.json').version;

    expect(reactVersion).toBe(reactDomVersion);
  });

  it('should not have peer dependency warnings', () => {
    // Run npm ls and check for warnings
  });
});

破壊的変更への対応

破壊的変更を特定する
# Use changelog parsers
npx changelog-parser react 16.0.0 17.0.0

# Or manually check
curl https://raw.githubusercontent.com/facebook/react/main/CHANGELOG.md
自動修正用の Codemod
# React upgrade codemods
npx react-codeshift <transform> <path>

# Example: Update lifecycle methods
npx react-codeshift \
  --parser tsx \
  --transform react-codeshift/transforms/rename-unsafe-lifecycles.js \
  src/
カスタム移行スクリプト
// migration-script.js
const fs = require('fs');
const glob = require('glob');

glob('src/**/*.tsx', (err, files) => {
  files.forEach(file => {
    let content = fs.readFileSync(file, 'utf8');

    // Replace old API with new API
    content = content.replace(
      /componentWillMount/g,
      'UNSAFE_componentWillMount'
    );

    // Update imports
    content = content.replace(
      /import { Component } from 'react'/g,
      "import React, { Component } from 'react'"
    );

    fs.writeFileSync(file, content);
  });
});

テスト戦略

ユニットテスト
// Ensure tests pass before and after upgrade
npm run test

// Update test utilities if needed
npm install @testing-library/react@latest
統合テスト
// tests/integration/app.test.js
describe('App Integration', () => {
  it('should render without crashing', () => {
    render(<App />);
  });

  it('should handle navigation', () => {
    const { getByText } = render(<App />);
    fireEvent.click(getByText('Navigate'));
    expect(screen.getByText('New Page')).toBeInTheDocument();
  });
});
ビジュアルリグレッションテスト
// visual-regression.test.js
describe('Visual Regression', () => {
  it('should match snapshot', () => {
    const { container } = render(<App />);
    expect(container.firstChild).toMatchSnapshot();
  });
});
E2E テスト
// cypress/e2e/app.cy.js
describe('E2E Tests', () => {
  it('should complete user flow', () => {
    cy.visit('/');
    cy.get('[data-testid="login"]').click();
    cy.get('input[name="email"]').type('[email protected]');
    cy.get('button[type="submit"]').click();
    cy.url().should('include', '/dashboard');
  });
});

依存関係の更新を自動化する

Renovate の設定
// renovate.json
{
  "extends": ["config:base"],
  "packageRules": [
    {
      "matchUpdateTypes": ["minor", "patch"],
      "automerge": true
    },
    {
      "matchUpdateTypes": ["major"],
      "automerge": false,
      "labels": ["major-update"]
    }
  ],
  "schedule": ["before 3am on Monday"],
  "timezone": "America/New_York"
}
Dependabot の設定
# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: "npm"
    directory: "/"
    schedule:
      interval: "weekly"
    open-pull-requests-limit: 5
    reviewers:
      - "team-leads"
    commit-message:
      prefix: "chore"
      include: "scope"

ロールバック計画

// rollback.sh
#!/bin/bash

# Save current state
git stash
git checkout -b upgrade-branch

# Attempt upgrade
npm install package@latest

# Run tests
if npm run test; then
  echo "Upgrade successful"
  git add package.json package-lock.json
  git commit -m "chore: upgrade package"
else
  echo "Upgrade failed, rolling back"
  git checkout main
  git branch -D upgrade-branch
  npm install  # Restore from package-lock.json
fi

よくあるアップグレードパターン

ロックファイルの管理
# npm
npm install --package-lock-only  # Update lock file only
npm ci  # Clean install from lock file

# yarn
yarn install --frozen-lockfile  # CI mode
yarn upgrade-interactive  # Interactive upgrades
Peer Dependency の解決
# npm 7+: strict peer dependencies
npm install --legacy-peer-deps  # Ignore peer deps

# npm 8+: override peer dependencies
npm install --force
ワークスペースのアップグレード
# Update all workspace packages
npm install --workspaces

# Update specific workspace
npm install package@latest --workspace=packages/app

リソース

  • references/semver.md:セマンティックバージョニングガイド
  • references/compatibility-matrix.md:よくある互換性の問題
  • references/staged-upgrades.md:段階的なアップグレード戦略
  • references/testing-strategy.md:包括的なテスト手法
  • assets/upgrade-checklist.md:手順ごとのチェックリスト
  • assets/compatibility-matrix.csv:バージョン互換性テーブル
  • scripts/audit-dependencies.sh:依存関係監査スクリプト

ベストプラクティス

  1. 変更履歴を読む:変更内容を把握します
  2. 段階的にアップグレードする:一度に 1 つのメジャーバージョンをアップグレードします
  3. 十分にテストする:ユニットテスト、統合テスト、E2E テストを実施します
  4. Peer Dependency を確認する:早い段階で競合を解決します
  5. ロックファイルを使う:再現可能なインストールを確保します
  6. 更新を自動化する:Renovate または Dependabot を使います
  7. 監視する:アップグレード後の実行時エラーに注意します
  8. 文書化する:アップグレードの記録を残します

アップグレードチェックリスト

Pre-Upgrade:
- [ ] Review current dependency versions
- [ ] Read changelogs for breaking changes
- [ ] Create feature branch
- [ ] Backup current state (git tag)
- [ ] Run full test suite (baseline)

During Upgrade:
- [ ] Upgrade one dependency at a time
- [ ] Update peer dependencies
- [ ] Fix TypeScript errors
- [ ] Update tests if needed
- [ ] Run test suite after each upgrade
- [ ] Check bundle size impact

Post-Upgrade:
- [ ] Full regression testing
- [ ] Performance testing
- [ ] Update documentation
- [ ] Deploy to staging
- [ ] Monitor for errors
- [ ] Deploy to production

よくある落とし穴

  • すべての依存関係を一度にアップグレードする
  • アップグレードのたびにテストしない
  • Peer Dependency の警告を無視する
  • ロックファイルの更新を忘れる
  • 破壊的変更に関する注意事項を読まない
  • メジャーバージョンを飛ばす
  • ロールバック計画を用意しない

コメント