Skip to content

Do not sort main keys in package.json #11294

Closed

Description

@Artur-

Description of the bug / feature

Please do not touch the main keys of package.json. The order that npm init creates the keys is just fine, you should not sort those alphabetically. npm install also only sorts the dependencies, I have never seen it change the other parts of package.json

This has apparently been introduced as a side effect of #7431

Minimal reproducible example

vaadin init --pre packagejson
cd packagejson
mvn

Expected behavior

The name field should still be first in package.json

Actual behavior

The name field is moved below dependencies and devDependencies

Versions:

- Vaadin / Flow version: 21 alpha 7

Activity

  1. pleku commented on Jun 23, 2021

    @pleku

    So apparently any top level keys should be left unsorted, only the objects that contain the dependencies should be sorted by #7431 https://docs.npmjs.com/cli/v7/configuring-npm/package-json

  2. denis-anisimov commented on Jun 23, 2021

    @denis-anisimov
    Contributor

    So apparently any top level keys should be left unsorted, only the objects that contain the dependencies should be sorted by

    I don't understand this comment

    Does it mean that dependencies can be at any place ? Does it mean that devDependencies can be at any place ?

  3. pleku commented on Jun 23, 2021

    @pleku

    Apparently we only fixed the randomness, which is great.
    Now the issue apparently is that the order we use for the main level keys is not the same as what npm itself uses.
    The problem will be the same - the file is modified when running flow even when there should be no changes - the ordering of keys will change (?) and as the file is in version control, there will be unnecessary updates to it which can cause annoying merge conflicts in projects.

    Does it mean that dependencies can be at any place ? Does it mean that devDependencies can be at any place ?

    When running

    npm init --yes
    npm install @vaadin/vaadin-button
    npm install @vaaadin/vaadin-text-field -D
    

    I get

    {
      "name": "npm-test",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "dependencies": {
        "@vaadin/vaadin-button": "^20.0.0"
      },
      "devDependencies": {
        "@vaadin/vaadin-text-field": "^20.0.0"
      }
    }
    

    Which can be used as an example of main level keys ordering when we create a new package.json file.
    Then I think after that we should not touch the main level keys, except only to add the vaadin main level key at correct location, which I guess should be at the end (after devDependencies) or where it is currently. Then when modifying dependencies or devDependencies, we keep that sorted like it was done.

  4. denis-anisimov commented on Jun 23, 2021

    @denis-anisimov
    Contributor

    This is again is not description of the task.
    This is an example.

    The package.json can be created in many ways: I can create it manually, I can generate it using npm , Flow generates it.

    In every such case the order will be different , different keys will be in the file.

    The ticket #7431 complains that vaadin key sometimes may be before dependencies .

    The main problem for some reason with the tasks is not a technical solution but the absence of the exact description what should be done. Apparently I have to write the exact task description instead of the reporter:

    • don't sort any key inside the main/root Json object except: vaadin should be the last one.
    • sort keys inside dependencies, devDependencies, vaadin objects

    is this the expected behavior which we can agree on ?

    I strongly dislike the situation when the developer has to write the exact description of the task instead of the reporter but apparently this needs to be done now for every ticket from now on.

  5. pleku commented on Jun 23, 2021

    @pleku

    is this the expected behavior which we can agree on ?

    Otherwise seems OK, but in case the vaadin key is already present, and the developer adds another top level key after it, I think flow should not move the vaadin key to be after it as this is again an unnecessary change.

    I strongly dislike the situation when the developer has to write the exact description of the task instead of the reporter but apparently this needs to be done now for every ticket from now on.

    It is the responsibility of the developer who makes the fix to understand what he is fixing and how it should be fixed. This is regardless of what the reported has written or has not written. Also the reviewer of the code needs to double check this when making the review code - not just look at the code. In case there is no clarity on the fix or report is too obscure, we take the time to discuss or ask for more details.

  6. denis-anisimov commented on Jun 23, 2021

    @denis-anisimov
    Contributor

    It is the responsibility of the developer who makes the fix to understand what he is fixing and how it should be fixed.

    yes, and this is a responsibility of the reporter to make description so that the fix is done according to the expectation.
    The fix for #7431 is done based on the description in the ticket.

    Also the reviewer of the code needs to double check this when making the review code - not just look at the code. In case there is no clarity on the fix or report is too obscure, we take the time to discuss or ask for more details.

    Apparently this is failing and I would say this is impossible. The reality is incompatible with this wish.

    Several hours spent on clarifying the ticket: that's the reality.

  7. added a commit that references this issue on Jun 23, 2021
    d3d82d5
  8. added a commit that references this issue on Jun 24, 2021
    e8d1d3c
  9. added 2 commits that reference this issue on Jun 25, 2021
    f7bf5d9
    9b32bef
  10. added 2 commits that reference this issue on Jun 28, 2021
    0ee226e
    060cb90
  11. added a commit that references this issue on Jun 28, 2021
    dfc929b
  12. vaadin-bot commented on Jun 28, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 21.0.0.alpha8. For prerelease versions, it will be included in its final version.

  13. added a commit that references this issue on Jun 30, 2021
    4a84ded
  14. vaadin-bot commented on Jul 5, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 20.0.4. For prerelease versions, it will be included in its final version.

  15. vaadin-bot commented on Aug 9, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 14.7.0.alpha3 and is also targeting the upcoming stable 14.7.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions