Skip to content

oxfmt: sortPackagejson should not sort imports/exports conditions #20341

@brokenmass

Description

@brokenmass

If sortPackageJson is enabled this code

{
  "exports": {
    "./": {
      "@scope/source": "./src/index.ts",
      "types": "./dist/index.d.ts",
      "default": "./dist/index.js"
    }
  }
}

is formatted to

{
  "exports": {
    "./": {
      "types": "./dist/index.d.ts",
      "@scope/source": "./src/index.ts",
      "default": "./dist/index.js"
    }
  }
}

Setting the types key first in the conditional imports/exports section breaks typescript monorepos that use typescript custom conditions (example @scope/source like suggested by https://colinhacks.com/essays/live-types-typescript-monorepo at point 5)

see: keithamus/sort-package-json#393 in the original sort-package-json for additional informations

this behaviour should be removed (a formatter should not alter the behaviour of code) or at least it should be possible to disable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions