diff
Compare npm package versions to identify changes between releases or between local and registry packages. View differences in code or file names to understand updates.
Instructions
Show diff between package versions or between local and registry
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| package | No | Package spec for comparison (e.g. pkg@1.0.0..pkg@2.0.0) | |
| specs | No | Two package specs to compare (e.g. ['pkg@1.0.0', 'pkg@2.0.0']) | |
| path | No | Absolute path to local package (compares local vs registry) | |
| diffNameOnly | No | Only show file names that changed |
Implementation Reference
- src/index.ts:661-689 (handler)The "diff" tool is defined and implemented here using `server.tool`. It takes input parameters for package specifications and path, constructs the npm command arguments, executes it using the `run` helper function, and returns the result.
// ── npm diff ── server.tool( "diff", "Show diff between package versions or between local and registry", { package: z.string().optional().describe("Package spec for comparison (e.g. pkg@1.0.0..pkg@2.0.0)"), specs: z.array(z.string()).optional().describe("Two package specs to compare (e.g. ['pkg@1.0.0', 'pkg@2.0.0'])"), path: z.string().optional().describe("Absolute path to local package (compares local vs registry)"), diffNameOnly: z.boolean().optional().describe("Only show file names that changed"), }, async ({ package: pkg, specs, path, diffNameOnly }) => { const args = ["diff"]; if (specs && specs.length > 0) { for (const s of specs) args.push(`--diff=${s}`); } else if (pkg) { args.push(`--diff=${pkg}`); } if (diffNameOnly) args.push("--diff-name-only"); try { const { stdout } = await run(args, path); return { content: [{ type: "text", text: stdout || "No differences found" }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, );