bencoveney / barrelsby

Automatic TypeScript barrels (index.ts files) for your entire code base

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sort exports alphabetically

4ekki opened this issue · comments

commented

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.

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

commented

Not stale

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...

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

commented

Still actual

commented

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.

commented

Still actual

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.

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

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

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