Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort package.json dependencies alphabetically #77396

Open
wants to merge 2 commits into
base: canary
Choose a base branch
from

Conversation

diegomais
Copy link

Description

This PR adds alphabetical sorting for dependencies and devDependencies in the generated package.json file. The sorting uses simple string comparison to match the behavior of npm, yarn, and pnpm package managers.

Changes

  • Added sorting for both dependencies and devDependencies sections
  • Used basic string comparison (< and > operators)
  • Maintains consistent ordering across different package managers

Testing

To verify this change:

  1. Create a new Next.js project with various dependencies:
    pnpm create next-app test-app --typescript --tailwind --eslint
  2. Check the generated package.json file to ensure:
    • Dependencies are sorted alphabetically
    • DevDependencies are sorted alphabetically
    • The order matches what you'd see after running pnpm install
  3. Verify that the installation process works correctly with the sorted dependencies

Impact

This change improves the consistency of generated package.json files and makes them more predictable across different package managers. It's a small but useful improvement for maintainability and readability.

Sort dependencies and devDependencies in package.json file generated
using simple string comparison to match package manager behavior.

This ensures consistent ordering across npm, yarn, and pnpm installations.
@ijjk ijjk added the create-next-app Related to our CLI tool for quickly starting a new Next.js application. label Mar 22, 2025
@ijjk
Copy link
Member

ijjk commented Mar 22, 2025

Allow CI Workflow Run

  • approve CI run for commit: 7083a79

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@diegomais
Copy link
Author

Before this change, package managers would reorder dependencies in package.json after installation, causing unnecessary git diffs like this:

Screenshot 2025-03-21 at 21 11 42

This was problematic because:

  • It created noise in git history
  • Made it harder to review actual dependency changes
  • Caused unnecessary merge conflicts
  • Required manual sorting to maintain consistency

Now the dependencies are pre-sorted in the same way package managers would sort them, preventing these unnecessary changes from being committed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants