Skip to content

Commit 3452c48

Browse files
committed
do not pretty-print package-lock.json to prevent corrupting git lines count history
1 parent 199c970 commit 3452c48

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

doc/misc/npm-config.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,20 @@ Makes various commands more forceful.
387387
* skips cache when requesting from the registry.
388388
* prevents checks against clobbering non-npm files.
389389

390+
### format-package-lock
391+
392+
* Default: false
393+
* Type: Boolean
394+
395+
Format `package-lock.json` as a human readable file.
396+
397+
### format-shrinkwrap
398+
399+
* Default: false
400+
* Type: Boolean
401+
402+
Format `npm-shrinkwrap.json` as a human readable file.
403+
390404
### fetch-retries
391405

392406
* Default: 2

lib/config/defaults.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ Object.defineProperty(exports, 'defaults', {get: function () {
141141
editor: osenv.editor(),
142142
'engine-strict': false,
143143
force: false,
144+
'format-package-lock': false,
145+
'format-shrinkwrap': false,
144146

145147
'fetch-retries': 2,
146148
'fetch-retry-factor': 10,
@@ -282,6 +284,8 @@ exports.types = {
282284
editor: String,
283285
'engine-strict': Boolean,
284286
force: Boolean,
287+
'format-package-lock': Boolean,
288+
'format-shrinkwrap': Boolean,
285289
'fetch-retries': Number,
286290
'fetch-retry-factor': Number,
287291
'fetch-retry-mintimeout': Number,

lib/shrinkwrap.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,25 @@ function checkPackageFile (dir, name) {
270270
return readFile(
271271
file, 'utf8'
272272
).then((data) => {
273+
let indent
274+
let newline
275+
if (name === PKGLOCK && npm.config.get('format-package-lock') === false) {
276+
indent = 0
277+
newline = 0
278+
}
279+
else if (name === SHRINKWRAP && npm.config.get('format-shrinkwrap') === false) {
280+
indent = 0
281+
newline = 0
282+
}
283+
else {
284+
indent = detectIndent(data).indent
285+
newline = detectNewline(data)
286+
}
273287
return {
274288
path: file,
275289
raw: data,
276-
indent: detectIndent(data).indent,
277-
newline: detectNewline(data)
290+
indent,
291+
newline
278292
}
279293
}).catch({code: 'ENOENT'}, () => {})
280294
}

0 commit comments

Comments
 (0)