惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
G
Google Developers Blog
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
V2EX
V
Visual Studio Blog
博客园 - Franky
S
SegmentFault 最新的问题
Jina AI
Jina AI
爱范儿
爱范儿
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
C
Check Point Blog
月光博客
月光博客
P
Proofpoint News Feed
T
The Blog of Author Tim Ferriss
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MongoDB | Blog
MongoDB | Blog
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
Martin Fowler
Martin Fowler

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Your package.json diffs are noisy for no reason. I built ...
benjamin · 2026-06-12 · via DEV Community
Cover image for Your package.json diffs are noisy for no reason. I built a zero-dep fixer.

benjamin

Open a PR, and half the package.json diff is keys that didn't actually
change — they just moved. One teammate's editor writes name at the top,
npm install shoves a field somewhere else, a codegen tool emits keys in
whatever order its hashmap felt like. None of it is a real change, but it all
shows up in review, buries the one line that matters, and turns trivial merges
into conflicts.

The fix is boring and obvious: pick one order and keep every JSON file in it.
The catch is that "one order" is more subtle than it sounds.

Why "just alphabetize it" is wrong

Run a generic JSON sorter on your package.json and you get this:

{
  "author": "...",
  "bugs": "...",
  "dependencies": { ... },
  "description": "...",
  "name": "...",
  "version": "..."
}

name and version — the two things you actually look for — are now buried in
the middle of the alphabet, below dependencies. Nobody writes package.json
that way, because the conventional order (name, version, description, …,
scripts, dependencies) is more readable than the alphabetical one.

And it gets worse: alphabetizing everything will happily reorder your
scripts block — but script order is often meaningful (prebuildbuild
postbuild, a deliberate task sequence). Sorting it is an actual bug.

So a good JSON tidier needs to know the difference between config that has a
convention
, data that should be sorted, and data whose order is load-bearing.

keytidy

One CLI, zero dependencies, Node and Python. It applies the right rule per case:

  • package.json → conventional top-level order; dependency blocks (dependencies, devDependencies, peerDependencies, …) sorted A→Z; scripts left exactly as you wrote it. Unknown fields (your prettier, jest, etc.) sort alphabetically after the known ones.
  • any other .json → clean recursive alphabetical sort, with arrays left in their original order (an array is data, not config).
npx keytidy                 # tidy ./package.json in place
npx keytidy --check         # CI gate: exit 1 if anything drifted
# or: pip install keytidy

$ npx keytidy
✓ package.json — sorted

# in CI:
$ npx keytidy --check
✗ package.json — not sorted
run keytidy to fix          # exit 1

It detects and preserves your existing indentation (2-space, 4-space, tab) and
trailing newline, so the only thing that changes is key order — no formatting
churn fighting your editor.

A few choices I'd defend

  • scripts order is sacred by default. If you really want it sorted, --sort-scripts is there, but the default assumes you ordered it on purpose.
  • Arrays are never reordered. "keywords", a list of CLI args, a config array — order can be semantic, so keytidy never touches it.
  • No JSONC magic. It refuses to parse files with comments/trailing commas rather than silently mangle a commented tsconfig.json. Honest beats clever.
  • Same answer in both languages. The Node and Python ports sort identically and emit byte-identical output, so a mixed-language monorepo gets one result.

MIT, both repos public:
keytidy (Node) ·
keytidy-py (Python).


What's your canonical package.json order — do you follow npm's, or have a
house style? And is there a JSON file in your repo whose key churn drives you up
the wall? Tell me and I'll make sure keytidy handles it.