Claude Code से dependency management: npm, pnpm, Yarn और CI
Claude Code से npm, pnpm और Yarn updates को lockfile, audit, update PR और CI verification के साथ सुरक्षित चलाएं।
Dependency management सिर्फ latest version लगाना नहीं है
JavaScript और TypeScript projects में dependencies बहुत जल्दी बदलती हैं। React, Vite, TypeScript, ESLint, test tools, UI packages, payment SDKs और build plugins मिलकर छोटे project को भी सैकड़ों direct और transitive packages पर निर्भर बना देते हैं।
Claude Code इस काम में मदद कर सकता है, लेकिन सुरक्षित तरीका यह नहीं है कि उसे सीधे npm install package@latest चलाने को कहा जाए। बेहतर तरीका है: पहले repository inspect करवाएं, package manager और lockfile पहचानें, patch/minor/major updates अलग करें, security audit समझें, Renovate या Dependabot PR review करवाएं, और अंत में CI से proof लें।
lockfile वह file है जो exact installed versions और integrity data को fix करती है। npm में package-lock.json, pnpm में pnpm-lock.yaml, और Yarn में yarn.lock होता है। package.json acceptable range बताता है; lockfile actual result बताता है। CI को lockfile verify करना चाहिए, उसे quietly rewrite नहीं करना चाहिए।
CI workflow की broader picture के लिए Claude Code CI/CD setup देखें। workspace या monorepo के लिए pnpm workspace guide उपयोगी है।
Safe workflow
Dependency updates को पांच steps में रखें: inspect, plan, update PR, CI, human decision.
flowchart LR
scan["Inspect\noutdated / audit"] --> plan["Plan\npatch / minor / major"]
plan --> pr["Update PR\nRenovate / Dependabot"]
pr --> ci["CI\ninstall / test / build"]
ci --> review["Claude Code review\nrisk and evidence"]
review --> merge["Human decision\nmerge or reject"]
Claude Code को पहले edit नहीं, inspect करने को कहें।
claude -p "
Inspect dependency management in this repository. Do not edit files yet.
Report package manager, lockfile, outdated direct dependencies,
security audit command, scripts that must pass, and risky major updates.
Return file paths and exact commands.
"
यह prompt Claude Code को पहले context समझने पर मजबूर करता है। Beginner के लिए इसे inventory की तरह समझें: पहले tools, versions और risks की list बनती है, फिर update होता है।
npm, pnpm और Yarn की basic table
एक repository में package managers mix न करें। हर tool का lockfile और CI command अलग होता है।
| Tool | Lockfile | CI install | Outdated check | Security audit |
|---|---|---|---|---|
| npm | package-lock.json | npm ci | npm outdated | npm audit --audit-level=high |
| pnpm | pnpm-lock.yaml | pnpm install --frozen-lockfile | pnpm outdated --format table | pnpm audit --audit-level high |
| Yarn modern | yarn.lock | yarn install --immutable | yarn up -i या yarn up <pattern> | yarn npm audit --recursive --severity high |
npm docs में npm ci automated environments के लिए बताया गया है, और mismatch होने पर यह lockfile update नहीं करता बल्कि fail करता है। pnpm में --frozen-lockfile, Yarn में --immutable भी यही idea देते हैं। Update PR lockfile बदलता है; CI proof देता है कि वही lockfile reproduce हो सकता है।
Copy-paste verification script
इसे scripts/verify-deps.mjs में रखें। यह npm/pnpm/Yarn detect करता है, frozen install चलाता है, high severity audit करता है, और typecheck, test, build scripts मिलें तो उन्हें run करता है।
#!/usr/bin/env node
import { existsSync, readFileSync } from "node:fs";
import { spawnSync } from "node:child_process";
function readPackageJson() {
return JSON.parse(readFileSync("package.json", "utf8"));
}
function detectPackageManager(pkg) {
const declared = pkg.packageManager || "";
if (declared.startsWith("pnpm@")) return "pnpm";
if (declared.startsWith("yarn@")) return "yarn";
if (declared.startsWith("npm@")) return "npm";
if (existsSync("pnpm-lock.yaml")) return "pnpm";
if (existsSync("yarn.lock")) return "yarn";
if (existsSync("package-lock.json")) return "npm";
throw new Error("No package manager or lockfile detected.");
}
function run(command, args) {
const label = [command, ...args].join(" ");
console.log(`\n$ ${label}`);
const result = spawnSync(command, args, {
stdio: "inherit",
shell: process.platform === "win32",
});
if (result.status !== 0) throw new Error(`Command failed: ${label}`);
}
const pkg = readPackageJson();
const manager = detectPackageManager(pkg);
const installCommands = {
npm: ["npm", ["ci"]],
pnpm: ["pnpm", ["install", "--frozen-lockfile"]],
yarn: ["yarn", ["install", "--immutable"]],
};
const auditCommands = {
npm: ["npm", ["audit", "--audit-level=high"]],
pnpm: ["pnpm", ["audit", "--audit-level", "high"]],
yarn: ["yarn", ["npm", "audit", "--recursive", "--severity", "high"]],
};
const scriptCommands = {
npm: (name) => ["npm", ["run", name]],
pnpm: (name) => ["pnpm", ["run", name]],
yarn: (name) => ["yarn", ["run", name]],
};
run(...installCommands[manager]);
run(...auditCommands[manager]);
for (const name of ["typecheck", "test", "build"]) {
if (pkg.scripts?.[name]) run(...scriptCommands[manager](name));
else console.log(`\n- skip ${name}: script not found`);
}
console.log(`\nDependency verification passed with ${manager}.`);
package.json में script जोड़ें:
{
"scripts": {
"deps:verify": "node scripts/verify-deps.mjs"
}
}
यह update script नहीं है। यह verification gate है। Claude Code, Renovate, Dependabot और manual changes सभी को इसी gate से गुजरना चाहिए।
तीन practical use cases
पहला use case: छोटी web app में dev tools update करना। ESLint, Prettier, Vite, Vitest और TypeScript के patch/minor updates group किए जा सकते हैं। Major updates को अलग PR में रखें।
claude -p "
Prepare a dependency update plan for devDependencies only.
Group patch and minor updates for lint/test/build tools.
Do not update major versions.
Run the dependency verification script after changes.
"
दूसरा use case: vulnerability audit. audit fix --force को default response न बनाएं। पहले JSON output देखें और Claude Code से पूछें कि issue direct dependency में है या transitive dependency में, fixed version क्या है, lockfile-only update काफी है या major चाहिए।
npm audit --json
pnpm audit --json
yarn npm audit --recursive --json
तीसरा use case: workspace या monorepo. Dependency management में internal boundaries भी शामिल हैं। packages/ui को apps/web import नहीं करना चाहिए। Internal packages में workspace:* use करना चाहिए।
claude -p "
Inspect this workspace before dependency updates.
Find packages/* importing from apps/*, internal dependencies not using workspace:*,
duplicated versions of react/typescript/eslint, and scripts that should use filters.
Do not edit files.
"
Renovate और Dependabot
Renovate तब अच्छा है जब rules fine-grained चाहिए। यह config devDependencies patch/minor को CI pass होने पर automerge कर सकता है, और major updates को human review पर छोड़ता है।
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:recommended"],
"dependencyDashboard": true,
"lockFileMaintenance": {
"enabled": true,
"schedule": ["before 5am on monday"],
"automerge": true
},
"packageRules": [
{
"matchManagers": ["npm"],
"matchDepTypes": ["devDependencies"],
"matchUpdateTypes": ["patch", "minor"],
"automerge": true
},
{
"matchUpdateTypes": ["major"],
"labels": ["dependency", "major-update"],
"automerge": false
}
]
}
GitHub repositories में simple start के लिए Dependabot काफी है।
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 5
groups:
dev-tooling:
dependency-type: "development"
update-types:
- "minor"
- "patch"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
GitHub Actions को भी update list में रखें। पुराना actions/setup-node dependency PR debugging को मुश्किल बना सकता है।
CI verification
name: dependency-check
on:
pull_request:
push:
branches: [main]
jobs:
verify-dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: corepack enable
- run: node scripts/verify-deps.mjs
Cache बाद में जोड़ें। पहले reproducibility prove करें।
Common failures
पहली गलती CI में npm install चलाना है; npm ci use करें। दूसरी गलती audit fix --force से शुरुआत करना है। तीसरी गलती कई major updates को एक PR में डालना है। चौथी गलती सिर्फ package.json देखना और lockfile diff ignore करना है। पांचवीं गलती dev dependency और production dependency को same risk मानना है। Content site में MDX या build update से code blocks, ads या CTA टूट सकते हैं; इसके लिए verification receipt workflow देखें।
PR review prompt
claude -p "
Review this dependency update PR.
Focus on package.json, lockfile, CI config, and test output.
Report updated packages, direct vs transitive changes, major updates,
peer dependency changes, commands that passed or failed, and manual checks.
Do not change files unless there is a blocking issue.
"
Good review evidence देती है: क्या बदला, कौन सा command pass हुआ, क्या fail हुआ, और human को merge से पहले क्या देखना है।
References और next step
Official docs: npm ci, npm audit, pnpm install, pnpm audit, yarn install, yarn npm audit, Claude Code CLI, Dependabot options, और Renovate automerge।
इस workflow को team में लागू करना हो तो Claude Code security audit और CLAUDE.md best practices देखें। Real repository के लिए rules चाहिए हों तो training and consultation next step है।
वास्तव में test करने पर result
इस flow में सबसे बड़ा improvement update generation और verification को अलग करना था। Claude Code plan और review कर सकता है, लेकिन deps:verify और lockfile diff decide करते हैं कि PR ready है या नहीं। Major updates को automerge से बाहर रखने पर failures debug करना आसान हो गया।
मुफ़्त PDF: Claude Code cheatsheet
Email डालें और commands, review habits तथा safe workflow वाली एक-page PDF पाएँ.
हम आपका data सुरक्षित रखते हैं और spam नहीं भेजते.
लेखक के बारे में
Masa
Claude Code workflow और team adoption पर काम करने वाला engineer.
संबंधित लेख
Claude Code permission safety ladder: access धीरे-धीरे बढ़ाएं
read-only से limited edits, proof commands और deploy checks तक permission बढ़ाने की सुरक्षित ladder.
Claude Code Small PR Proof Pack: छोटे PR को review-ready बनाना
Claude Code PR के लिए diff, checks, public URL, CTA path और rollback वाला practical proof pack.
Claude Code Review Gate Before Commit: diff, test, public URL और CTA जांच
Claude Code से commit से पहले review gate बनाएं: diff, build, public URL, Gumroad, consultation, tests और unrelated files।