From 8da3d5a469203888882b864127b25964ada3c883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 26 Feb 2018 18:31:38 -0800 Subject: [PATCH] fix(perf): stop using the readPackageJson version to update packages --- index.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index d3ea0e9..d579422 100644 --- a/index.js +++ b/index.js @@ -15,11 +15,10 @@ const path = require('path') const readPkgJson = BB.promisify(require('read-package-json')) const rimraf = BB.promisify(require('rimraf')) -const appendFileAsync = BB.promisify(fs.appendFile) const readFileAsync = BB.promisify(fs.readFile) const statAsync = BB.promisify(fs.stat) const symlinkAsync = BB.promisify(fs.symlink) -const truncateAsync = BB.promisify(fs.truncate) +const writeFileAsync = BB.promisify(fs.writeFile) class Installer { constructor (opts) { @@ -253,17 +252,16 @@ class Installer { const depPath = dep.path(this.prefix) const depPkgPath = path.join(depPath, 'package.json') const parent = dep.requiredBy.values().next().value - const pkgPath = path.join(parent.path(this.prefix), 'package.json') - return readPkgJson(pkgPath) - .then(parentPkg => - parentPkg.dependencies[dep.name] || - parentPkg.devDependencies[dep.name] || - parentPkg.optionalDependencies[dep.name] + return readJson(parent.path(this.prefix), 'package.json') + .then(ppkg => + (ppkg.dependencies && ppkg.dependencies[dep.name]) || + (ppkg.devDependencies && ppkg.devDependencies[dep.name]) || + (ppkg.optionalDependencies && ppkg.optionalDependencies[dep.name]) ) .then(from => npa.resolve(dep.name, from)) .then(from => { pkg._from = from.toString() }) - .then(() => truncateAsync(depPkgPath)) - .then(() => appendFileAsync(depPkgPath, JSON.stringify(pkg, null, 2))) + .then(() => writeFileAsync(depPkgPath, JSON.stringify(pkg, null, 2))) + .then(pkg) } // A cute little mark-and-sweep collector!