barrelsby icon indicating copy to clipboard operation
barrelsby copied to clipboard

Sort exports alphabetically

Open 4ekki opened this issue 2 years ago • 11 comments

Currently, order of lines in generated barrel is not alphabetical. This cause mess when including generate-barrels script in pre-commit hooks along with linter/prettier rules that sort exports (like https://github.com/lydell/eslint-plugin-simple-import-sort/).

See the example of index.d.ts file, after generate-barrels and after linter (I had to obfuscate filenames a bit, but the idea should still be clear): image

Please sort lines alphabetically by default. Also, it could be useful to add flag, that controls case-sensivity.

4ekki avatar Sep 11 '21 11:09 4ekki

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

github-actions[bot] avatar Nov 30 '21 17:11 github-actions[bot]

Not stale

4ekki avatar Dec 07 '21 19:12 4ekki

Furthermore there are other things a little bit odd, the "sorting" is platform dependent, i.e. running barrelsby on Windoozw will give another order than on MacOS. This causes unstaged changes in CI and some epic wars between Windows/MacOS-Users...

ChristianUlbrich avatar Jan 31 '22 20:01 ChristianUlbrich

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

github-actions[bot] avatar Apr 02 '22 17:04 github-actions[bot]

Still actual

4ekki avatar Apr 03 '22 13:04 4ekki

Sorry, I meant to address this earlier. I needed time to go through and figure out how it decides the order to create the exports.

The exports are created in the order they appear in the filesystem. There is no sorting done by barrelsby from what I can tell. For now, I'm going to recommend running your linter after creating the barrel if you need them in order. This will likely become a configuration options in v3 when ESM support comes along.

BitForger avatar May 07 '22 22:05 BitForger

Still actual

4ekki avatar Jul 07 '22 20:07 4ekki

Presently I run the following via npm-run-all to address this in the event it helps someone:

{
  "scripts": { 
    "barrels": "run-s barrels:*",
    "barrels:generate": "barrelsby -d src -c node_modules/<ORG>/node-rig/profiles/default/barrelsby.json",
    "barrels:lint": "eslint src/**/index.ts --fix",
  }
}

When npm|pnpm|yarn run barrels is executed (either locally or in ci) it generates the barrel files and then performs a lint --fix on all index.ts files to normalise them according to rules.

prescience-data avatar Nov 25 '22 22:11 prescience-data

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

github-actions[bot] avatar Mar 26 '23 17:03 github-actions[bot]

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

github-actions[bot] avatar Jul 25 '23 17:07 github-actions[bot]

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

github-actions[bot] avatar Nov 24 '23 17:11 github-actions[bot]