Open 9oelM opened 3 years ago
Am I right that npm
always use 2 spaces, and you have Tabs because of some other tool?
I like to have keep format, but I do not want to spend time to writing it. So please send PR.
We recently changed the indentation in our project, and I noticed that package-lock.json
inherits the indentation of package.json
. Though this may only happen if package-lock.json
has been recreated from scratch (I didn't test it much).
One way to work around this, is to run the package-lock.json
file through e.g. prettier after it is updated, to clean up the white space usage.
I think Prettier would be overkill for this use case. A full Prettier installion through npm is 3.9 MB. While Prettier is good at folding related code onto one line so it's easier to read, it could conflict with automatic formats from other tools, and package locks often don't need to be read by humans.
I think a simpler and faster approach would be to use parsers directly, for example:
JSON.stringify(JSON.parse(packageLock), undefined, space)
Note that in order to support Yarn and pnpm, a Yaml parser would be necessary, and to support Bun, a proprietary binary parser would be necessary.
Alternatively we could call out to different package managers, but I don't think there's a unified API for all lockfiles yet.
Hi, thank you for writing such a useful library. I got one little thing to suggest so I dropped by here.
I have upgraded with the following versions by running
npx browserslist@latest --update-db
:Everything just seems to be working fine. However I found that the entire lines in
package-lock.json
are perceived to be changed by Git due to indentation. In the screen capture below, right side is after upgrading; Left is before. As you can see, there is no practical change, but it seems thatcaniuse-lite
would write output with a default indentation of 2 spaces, regardless of any existing indentation (which in my case was tab).To help understand even more easily, I just copied & pasted the files.
Before running
npx browserslist@latest --update-db
After running
So.. down to the conclusion: it would be nice if
npx browserslist@latest --update-db
could preserve any existing indentation mechanism to help deduce only useful diffs.But after a little inspection into the source code.. I wonder if
npx browserslist@latest --update-db
actually makes a change inpackage-lock.json
? Could it be something else causing the problem?