dependency-upgrade by sickn33/antigravity-awesome-skills
npx skills add https://github.com/sickn33/antigravity-awesome-skills --skill dependency-upgrade掌握主要依赖版本升级、兼容性分析、分阶段升级策略以及全面的测试方法。
resources/implementation-playbook.md。MAJOR.MINOR.PATCH (例如,2.3.1)
MAJOR: 破坏性变更
MINOR: 新功能,向后兼容
PATCH: 错误修复,向后兼容
^2.3.1 = >=2.3.1 <3.0.0 (次要更新)
~2.3.1 = >=2.3.1 <2.4.0 (补丁更新)
2.3.1 = 精确版本
# npm
npm outdated
npm audit
npm audit fix
# yarn
yarn outdated
yarn audit
# 检查主要更新
npx npm-check-updates
npx npm-check-updates -u # 更新 package.json
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# 查看某个包为何被安装
npm ls package-name
yarn why package-name
# 查找重复包
npm dedupe
yarn dedupe
# 可视化依赖关系
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) {
// 根据矩阵验证包版本
}
# 1. 识别当前版本
npm list --depth=0
# 2. 检查破坏性变更
# 阅读 CHANGELOG.md 和 MIGRATION.md
# 3. 创建升级计划
echo "升级顺序:
1. TypeScript
2. React
3. React Router
4. 测试库
5. 构建工具" > UPGRADE_PLAN.md
# 不要一次性升级所有内容!
# 步骤 1:更新 TypeScript
npm install typescript@latest
# 测试
npm run test
npm run build
# 步骤 2:更新 React (一次只升级一个主要版本)
npm install react@17 react-dom@17
# 再次测试
npm run test
# 步骤 3:继续处理其他包
npm install react-router-dom@6
# 依此类推...
// tests/compatibility.test.js
describe('依赖兼容性', () => {
it('应具有兼容的 React 版本', () => {
const reactVersion = require('react/package.json').version;
const reactDomVersion = require('react-dom/package.json').version;
expect(reactVersion).toBe(reactDomVersion);
});
it('不应有对等依赖警告', () => {
// 运行 npm ls 并检查警告
});
});
# 使用变更日志解析器
npx changelog-parser react 16.0.0 17.0.0
# 或手动检查
curl https://raw.githubusercontent.com/facebook/react/main/CHANGELOG.md
# React 升级代码修改工具
npx react-codeshift <transform> <path>
# 示例:更新生命周期方法
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');
// 用新 API 替换旧 API
content = content.replace(
/componentWillMount/g,
'UNSAFE_componentWillMount'
);
// 更新导入
content = content.replace(
/import { Component } from 'react'/g,
"import React, { Component } from 'react'"
);
fs.writeFileSync(file, content);
});
});
// 确保升级前后测试通过
npm run test
// 如果需要,更新测试工具
npm install @testing-library/react@latest
// tests/integration/app.test.js
describe('应用集成', () => {
it('应能渲染而不崩溃', () => {
render(<App />);
});
it('应能处理导航', () => {
const { getByText } = render(<App />);
fireEvent.click(getByText('Navigate'));
expect(screen.getByText('New Page')).toBeInTheDocument();
});
});
// visual-regression.test.js
describe('视觉回归', () => {
it('应匹配快照', () => {
const { container } = render(<App />);
expect(container.firstChild).toMatchSnapshot();
});
});
// cypress/e2e/app.cy.js
describe('端到端测试', () => {
it('应能完成用户流程', () => {
cy.visit('/');
cy.get('[data-testid="login"]').click();
cy.get('input[name="email"]').type('user@example.com');
cy.get('button[type="submit"]').click();
cy.url().should('include', '/dashboard');
});
});
// 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"
}
# .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
# 保存当前状态
git stash
git checkout -b upgrade-branch
# 尝试升级
npm install package@latest
# 运行测试
if npm run test; then
echo "升级成功"
git add package.json package-lock.json
git commit -m "chore: upgrade package"
else
echo "升级失败,正在回滚"
git checkout main
git branch -D upgrade-branch
npm install # 从 package-lock.json 恢复
fi
# npm
npm install --package-lock-only # 仅更新锁定文件
npm ci # 根据锁定文件进行干净安装
# yarn
yarn install --frozen-lockfile # CI 模式
yarn upgrade-interactive # 交互式升级
# npm 7+: 严格的对等依赖
npm install --legacy-peer-deps # 忽略对等依赖
# npm 8+: 覆盖对等依赖
npm install --force
# 更新所有工作区包
npm install --workspaces
# 更新特定工作区
npm install package@latest --workspace=packages/app
升级前:
- [ ] 审查当前依赖版本
- [ ] 阅读变更日志了解破坏性变更
- [ ] 创建功能分支
- [ ] 备份当前状态 (git tag)
- [ ] 运行完整的测试套件 (基线)
升级过程中:
- [ ] 一次升级一个依赖项
- [ ] 更新对等依赖项
- [ ] 修复 TypeScript 错误
- [ ] 如果需要,更新测试
- [ ] 每次升级后运行测试套件
- [ ] 检查包大小影响
升级后:
- [ ] 完整的回归测试
- [ ] 性能测试
- [ ] 更新文档
- [ ] 部署到预发布环境
- [ ] 监控错误
- [ ] 部署到生产环境
每周安装次数
108
代码仓库
GitHub 星标数
26.9K
首次出现
2026年1月28日
安全审计
安装于
gemini-cli102
opencode102
github-copilot99
codex99
cursor95
claude-code94
Master major dependency version upgrades, compatibility analysis, staged upgrade strategies, and comprehensive testing approaches.
resources/implementation-playbook.md.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. 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
# 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...
// 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
# 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();
});
});
// 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('user@example.com');
cy.get('button[type="submit"]').click();
cy.url().should('include', '/dashboard');
});
});
// 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"
}
# .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
# 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
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
Weekly Installs
108
Repository
GitHub Stars
26.9K
First Seen
Jan 28, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
gemini-cli102
opencode102
github-copilot99
codex99
cursor95
claude-code94
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
159,700 周安装