bun
bun copied to clipboard
Respect current indentation in package.json when rewriting via `bun` CLI
What version of Bun is running?
0.6.3
What platform is your computer?
Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64
What steps can reproduce the bug?
- Create a
package.json
manually using tabs or more/less than 2 spaces. - Run any
bun
command that modifiespackage.json
, such asbun add zod
What is the expected behavior?
The indentation already present inside package.json
will be respected.
What do you see instead?
The entire file is rewritten as 2-space indentation, regardless of what the file was using prior.
Additional information
I'm aware this is a minor issue, but it should also be fairly trivial to resolve and would be a quality-of-life change. When using Bun to add a package to a project - especially one that is already established - it's not ideal to have to reindent the file manually every single time.
There's an argument for "just leave it as 2-space indentation", but it's not always my own project and I can't make that upstream decision, and comitting a massive reindentation of the package.json
upstream isn't a polite thing to do.
Related: #1979, #2614
That would be great. We’re using tabs, so reformatting package.json
after each bun update
is a little bit excessive.
I'm running bun locally in a project that is designed to use node, and although we have prettier
set up to autoformat package.json
, the diff is useless until after that formatting happens, so this does add an extra (albeit small) step for me on each commit.
1+ this would be an advantage over npm
Any expected time, when this gets fixed?
Related: #4563
It's annoying having to reformat the package.json after each bun update
. Either autodetect the current indentation and respect it, or provide a config switch to reformat or not.
Although it's an old post, one thought is to infer these details from a .editorconfig
placed at the project root, which other formatters like Prettier do if no configuration file is found.
In Bun's case, a configuration file is too heavy, though I think this would work as a viable, possible IDE-agnostic solution to this. If I knew Zig I would have done this but I do not, wallow wallow
An alternative I've been using is to use aliases for any package management command Bun uses. It's quite absurd but gets the job done for me, something like the following:
alias bunf="bun run format"
alias buni="bun install $@ && bunf"
alias bunr="bun remove $@ && bunf"
...
It's a bit cursed though and a real solution would do the problem it's justice.
EDIT: Pre-commit hooks are a better alternative if you don't mind the idea of having another runtime.
@cyrus01337 I agree, respecting the .editorconfig
would be the best solution.
It's annoying having to reformat the package.json after each bun update. Either autodetect the current indentation and respect it, or provide a config switch to reformat or not.
@tholu, I can totally relate to this.
🎉