From 0b28ac72d29132e9b761717aba20506854465865 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Fri, 8 Sep 2017 23:00:16 +1000 Subject: install: fix bug with rollback of failed optional packages on Windows This change ensures an fsync after updating `package.json` on Windows, which prevents an issue that intermittently occurs when rolling back a package with many dependencies such as fsevents. In testing it does not appear that fsync has as much of a performance impact on Windows as it does on other platforms, so this should not affect install times on Windows materially. Fixes: #17671 Fixes: #18287 Fixes: #18453 Fixes: #18380 Fixes: #18441 PR-URL: https://github.com/npm/npm/pull/18458 Credit: @marcins Reviewed-By: @iarna --- lib/install/update-package-json.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/install/update-package-json.js b/lib/install/update-package-json.js index 14339d001..afffaf780 100644 --- a/lib/install/update-package-json.js +++ b/lib/install/update-package-json.js @@ -4,6 +4,7 @@ var writeFileAtomic = require('write-file-atomic') var moduleName = require('../utils/module-name.js') var deepSortObject = require('../utils/deep-sort-object.js') var sortedObject = require('sorted-object') +var isWindows = require('../utils/is-windows.js') var sortKeys = [ 'dependencies', 'devDependencies', 'bundleDependencies', @@ -47,7 +48,9 @@ module.exports = function (mod, buildpath, next) { var data = JSON.stringify(sortedObject(pkg), null, 2) + '\n' writeFileAtomic(path.resolve(buildpath, 'package.json'), data, { - // We really don't need this guarantee, and fsyncing here is super slow. - fsync: false + // We really don't need this guarantee, and fsyncing here is super slow. Except on + // Windows where there isn't a big performance difference and it prevents errors when + // rolling back optional packages (#17671) + fsync: isWindows }, next) } -- cgit v1.2.3