Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not pretty-print package-lock.json to prevent corrupting git lines count history #186

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/misc/npm-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,20 @@ Makes various commands more forceful.
* skips cache when requesting from the registry.
* prevents checks against clobbering non-npm files.

### format-package-lock

* Default: false
* Type: Boolean

Format `package-lock.json` as a human readable file.

### format-shrinkwrap

* Default: false
* Type: Boolean

Format `npm-shrinkwrap.json` as a human readable file.

### fetch-retries

* Default: 2
Expand Down
4 changes: 4 additions & 0 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ Object.defineProperty(exports, 'defaults', {get: function () {
editor: osenv.editor(),
'engine-strict': false,
force: false,
'format-package-lock': false,
'format-shrinkwrap': false,

'fetch-retries': 2,
'fetch-retry-factor': 10,
Expand Down Expand Up @@ -282,6 +284,8 @@ exports.types = {
editor: String,
'engine-strict': Boolean,
force: Boolean,
'format-package-lock': Boolean,
'format-shrinkwrap': Boolean,
'fetch-retries': Number,
'fetch-retry-factor': Number,
'fetch-retry-mintimeout': Number,
Expand Down
18 changes: 16 additions & 2 deletions lib/shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,25 @@ function checkPackageFile (dir, name) {
return readFile(
file, 'utf8'
).then((data) => {
let indent
let newline
if (name === PKGLOCK && npm.config.get('format-package-lock') === false) {
indent = 0
newline = 0
}
else if (name === SHRINKWRAP && npm.config.get('format-shrinkwrap') === false) {
indent = 0
newline = 0
}
else {
indent = detectIndent(data).indent
newline = detectNewline(data)
}
return {
path: file,
raw: data,
indent: detectIndent(data).indent,
newline: detectNewline(data)
indent,
newline
}
}).catch({code: 'ENOENT'}, () => {})
}