This repository has been archived by the owner. It is now read-only.

Detect indent size when saving installed packages to a package.json #3180

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
6 participants
@Rowno
Copy link

Rowno commented Feb 20, 2013

No description provided.

@isaacs

This comment has been minimized.

Copy link
Member

isaacs commented Mar 4, 2013

Unnecessary complexity. No thanks. JSON uses 2 spaces.

@isaacs isaacs closed this Mar 4, 2013

@Rowno

This comment has been minimized.

Copy link

Rowno commented Mar 5, 2013

😢

@ljharb

This comment has been minimized.

Copy link
Contributor

ljharb commented Mar 30, 2013

This is unfortunate - "JSON uses 2 spaces" isn't correct, part of the spec, or universal.

@ljharb ljharb referenced this pull request Mar 30, 2013

Closed

Less package json change #3299

@isaacs

This comment has been minimized.

Copy link
Member

isaacs commented Apr 13, 2013

It's unfortunate, perhaps, but you guys have no idea what kind of door you're trying to open up here. npm writes a LOT of json files. If you use 3 spaces, and I use tabs, and I install your package, should I get your indentation or mine in the package.json files? (Yes, those are rewritten for consistency in the package.tgz file.) Even leaving that edge case aside, off the top of my head, there are like 3 other places where npm writes package.json that touched by this patch: version.js, rm.js, view.js, and so on. You're not appreciating the cost of making this configurable.

Indenting with 2 spaces is how npm writes human-readable json. This is universal within npm. If you don't like it, that's fine, there are many tools that can edit json and autoformat it however you like. True, it's not part of the spec, which is why npm will graciously read and parse whatever json format you give it.

@ljharb

This comment has been minimized.

Copy link
Contributor

ljharb commented Apr 13, 2013

That's a fair point - i'm simply talking about preserving the existing indentation on a per-file basis - in other words, i think "making it consistent throughout a project" is a goal that's beyond the scope of what all these tools are trying to do. Certainly if you're writing to a new file, a default of 2 spaces makes perfect sense.

@balupton

This comment has been minimized.

Copy link

balupton commented Apr 26, 2013

@isaacs definitely understand the need to avoid opening the huge door of canned worms, perhaps as a potential compromise, can we make this just happen when writing to the project's package.json file when we are using --save like npm install --save somedep?

@ljharb

This comment has been minimized.

Copy link
Contributor

ljharb commented Apr 26, 2013

fwiw, I've written https://npmjs.org/package/json-file-plus, and i have #3299 ready to be updated to use it :-)

@ljharb ljharb referenced this pull request Feb 22, 2014

Closed

Less package json changes #4760

Dreamseer added a commit to Dreamseer/kickstart that referenced this pull request Sep 15, 2014

whitneyit referenced this pull request in Microsoft/TypeScript Nov 5, 2014

@resir014 resir014 referenced this pull request Nov 27, 2015

Merged

Fixes to editorconfig #759

alrra added a commit to MicrosoftEdge/Demos that referenced this pull request Dec 14, 2016

Add EditorConfig properties for `package.json`
The indent size used by `npm` to write in the `package.json` is
2 spaces, and that cannot be changed.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Ref npm/npm#3180 (comment)
@Zashy

This comment has been minimized.

Copy link

Zashy commented Jan 23, 2017

@isaacs Yarn seems to handle this fine, just fyi. And as everyone knows, yarn is faster.

@KashGit KashGit referenced this pull request May 22, 2017

Open

sample #2

@nylen

This comment has been minimized.

Copy link

nylen commented Jun 8, 2017

Fixed in 64b67f0 and npm 5...

Indentation is now detected and preserved for package.json, package-lock.json, and npm-shrinkwrap.json. If the package lock is missing, it will default to package.json’s current indentation.

zarjay added a commit to zarjay/dotfiles that referenced this pull request Sep 9, 2017

Remove package.json settings
No longer needed because npm FINALLY preserves indentation of package.json files. npm/npm#3180
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.