Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.
Merged
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
save: only write package.json and locks if files have changed
Fixes: #17173
  • Loading branch information
zkat committed Jun 29, 2017
commit 9fdf64baa217c2001a36fae0bf6fb23f5f8447c6
7 changes: 6 additions & 1 deletion lib/install/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ function savePackageJson (tree, next) {
}

var json = JSON.stringify(tree.package, null, indent) + '\n'
writeFileAtomic(saveTarget, json, next)
if (json === packagejson) {
log.verbose('shrinkwrap', 'skipping write for package.json because there were no changes.')
next()
} else {
writeFileAtomic(saveTarget, json, next)
}
}))
}

Expand Down
21 changes: 14 additions & 7 deletions lib/shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,20 @@ function save (dir, pkginfo, opts, cb) {
)
const updated = updateLockfileMetadata(pkginfo, pkg && pkg.data)
const swdata = JSON.stringify(updated, null, info.indent) + '\n'
writeFileAtomic(info.path, swdata, (err) => {
if (err) return cb(err)
if (opts.silent) return cb(null, pkginfo)
if (!shrinkwrap && !lockfile) {
log.notice('', `created a lockfile as ${path.basename(info.path)}. You should commit this file.`)
}
if (swdata === info.raw) {
// skip writing if file is identical
log.verbose('shrinkwrap', `skipping write for ${path.basename(info.path)} because there were no changes.`)
cb(null, pkginfo)
})
} else {
writeFileAtomic(info.path, swdata, (err) => {
if (err) return cb(err)
if (opts.silent) return cb(null, pkginfo)
if (!shrinkwrap && !lockfile) {
log.notice('', `created a lockfile as ${path.basename(info.path)}. You should commit this file.`)
}
cb(null, pkginfo)
})
}
}
).then((file) => {
}, cb)
Expand Down Expand Up @@ -216,6 +222,7 @@ function checkPackageFile (dir, name) {
).then((data) => {
return {
path: file,
raw: data,
data: JSON.parse(data),
indent: detectIndent(data).indent || 2
}
Expand Down