Skip to content

Upgrade bundled sort-package-json to latest #104

Description

@karlhorky

Hi @unional, hope you're well!

I recently contributed a fix to sort-package-json to use the npm algorithm for sorting dependencies (to avoid endless diffs between sort-package-json and npm):

Would it be possible to get the bundled version of sort-package-json upgraded from ^1.57.0 to latest (at least ^3.2.0)?

Intermediate releases with breaking changes are as follows:

Activity

  1. unional commented on May 5, 2025

    @unional
    Collaborator

    Hi, the main issue is the ESM.

    Electron back then doesn't support ESM.

    Later-on it starts supporting it, but not sure if VSCode accepts ESM import yet.

  2. karlhorky commented on May 6, 2025

    @karlhorky
    ContributorAuthor

    Oh interesting, didn't know there was an issue with ESM support in VS Code 👀 looks like it's coming in the April 2025 iteration?

  3. unional commented on May 6, 2025

    @unional
    Collaborator

    That's great news. Yes. This extension couldn't update to `sort-package-json' 2.0.0 because of that.

    Hopefully microsoft/vscode#245214 works well.

  4. karlhorky commented on May 8, 2025

    @karlhorky
    ContributorAuthor

    VS Code April 2025 (1.100) is out, with "ESM support for extensions"! 🚀

  5. changed the title [-]Upgrade bundled sort-package-json to latest (3.2.0)[/-] [+]Upgrade bundled sort-package-json to latest[/+] on Jul 10, 2025
  6. karlhorky commented on Jul 10, 2025

    @karlhorky
    ContributorAuthor

    @unional would it make sense to check the checkbox in the Renovate Dependency Dashboard issue to open the PR for fix(deps): update dependency sort-package-json to v3?

  7. unional commented on Jul 12, 2025

    @unional
    Collaborator

    Thanks. It seems like no other extensions have issue with ESM. Will took into it hopefully this weekend.

  8. unional commented on Jul 13, 2025

    @unional
    Collaborator

    It doesn't work. Getting error: Dynamic require of "path" is not supported..

    It needs more work to convert it to async and then try using dynamic import.
    Need a lot of changes to make that happen.

  9. unional commented on Jul 13, 2025

    @unional
    Collaborator

    Still has some other issues.

    ref: microsoft/vscode#130367

  10. karlhorky commented on Jul 14, 2025

    @karlhorky
    ContributorAuthor

    Thanks for the update! I've subscribed to that microsoft/vscode#130367 issue, so I'll keep an eye on any new developments there.

  11. karlhorky commented on Aug 11, 2025

    @karlhorky
    ContributorAuthor

    @unional I saw your comment in the issue:

    I'm getting Dynamic require of "path" is not supported. when trying to convert unional/vscode-sort-package-json to ESM.

    Need to find out what's causing that.

    microsoft/vscode#130367 (comment)


    Do you think that you could push a branch / PR with your changes and a CI step showing the error (and update your comment with the link to the branch / PR)? I'm thinking maybe it would help others to assist with the problem.

  12. unional commented on Aug 14, 2025

    @unional
    Collaborator

    Sorry I'm not likely able to look at it in the next few weeks.

    I might be able to push the branch I was working on sometimes in the next 2 weeks.

    I recall the problem is that there is some code in vscode loading path dynamically.

  13. karlhorky commented on Sep 2, 2025

    @karlhorky
    ContributorAuthor

    Ok sounds good, looking forward to hearing more :)

  14. karlhorky commented on May 6, 2026

    @karlhorky
    ContributorAuthor

    @unional anything that has changed since Sep 2025?

    I did see this issue related to require(esm) is now resolved (although maybe unrelated to the problem you described above):


    Actually, maybe the extension doesn't need to be converted to ESM yet? Looking again at sort-package-json, sort-package-json@2.11.0 added dual CJS/ESM release support - still exposed in sort-package-json@3.6.1. The existing require(modulePath) in vscode-sort-package-json should be able to load it as CJS:

    https://github.com/keithamus/sort-package-json/blob/v3.6.1/package.json#L20-L32

    https://github.com/unional/vscode-sort-package-json/blob/38d47dd722c67ea03a84abfc2db372e2962ac8c5/src/getSortFn.ts#L21-L23

    But even sticking with CommonJS, there is one change that should be made: sort-package-json@3.6.1 requires Node.js >=20, while vscode-sort-package-json still supports VS Code >=1.77. So bumping engines.vscode to >= 1.90.0 (first VS Code version with extension host on Node.js >= 20) seems like it would be good:

    https://github.com/keithamus/sort-package-json/blob/v3.6.1/package.json#L105-L107

    https://github.com/unional/vscode-sort-package-json/blob/38d47dd722c67ea03a84abfc2db372e2962ac8c5/package.json#L83-L85

  15. unional commented on May 17, 2026

    @unional
    Collaborator

    @karlhorky Thanks. It seems like it is working now when I try it locally. Releasing a new version. Please share to see if it works or not.

  16. unional commented on May 21, 2026

    @unional
    Collaborator

    Closing

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions