From 45faca88f9b2fc6fb3a542826170f19dc4a549a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 12 Nov 2018 11:23:29 -0800 Subject: [PATCH] fix(installer): improvements to automatic lazy require workflow --- lib/installer.js | 6 ++++++ lib/lock-worker.js | 10 +++++++--- lib/pkglock.js | 9 +-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/installer.js b/lib/installer.js index f60653c..bbdf76e 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -148,6 +148,9 @@ class Installer { this.tree.delDep(dep) } } + if (!this.tree.dependencies.size) { + throw new Error('No dependencies found matching filter') + } } this.log('silly', 'tree', this.tree) this.expectedTotal = 0 @@ -311,7 +314,10 @@ class Installer { } async tinkifyBins () { + const old = process.tink + process.tink = null const bins = await glob(path.join(this.prefix, 'node_modules/**/.bin/*')) + process.tink = old this.log('verbose', 'tinkifyBins', 'convering installed bins to use tink:', bins) return BB.map(bins, async bin => { const real = await realpathAsync(bin) diff --git a/lib/lock-worker.js b/lib/lock-worker.js index 0b14173..69fad47 100644 --- a/lib/lock-worker.js +++ b/lib/lock-worker.js @@ -23,14 +23,18 @@ async function main (cache, integrity, pkg) { other () { return true } }) opts.log.heading = 'tink' - opts.log.level = opts.loglevel opts.log.notice('fs', 'unpacking', `${pkg.name}@${pkg.version}`) try { if (!prepare) { prepare = require('./commands/prepare.js') } - const { pkgCount } = await prepare.handler(opts, [pkg.name]) - if (!pkgCount) { throw new Error('no packages installed') } + opts.log.level = 'silent' + const res = await prepare.handler(opts.concat({ + loglevel: 'silent' + }), [pkg.name]) + if (res && !res.pkgCount) { throw new Error('no packages installed') } } catch (err) { + throw err if (!ensurePkg) { ensurePkg = require('./ensure-package.js') } + opts.log.level = opts.loglevel await ensurePkg(cache, pkg.name, pkg, opts) } } diff --git a/lib/pkglock.js b/lib/pkglock.js index 4f446ee..9806efd 100644 --- a/lib/pkglock.js +++ b/lib/pkglock.js @@ -310,14 +310,7 @@ async function fetchPackage (cache, pkg, hash) { if (!ensurePkg) { ensurePkg = require('./ensure-package.js') } if (!config) { config = require('./config.js') } if (!ensureDep) { ensureDep = require('./lock-worker.js') } - try { - await ensureDep(cache, hash, pkg) - } catch (err) { - await ensurePkg(cache, pkg.name, pkg, config().concat({ - cache, - integrity: hash - })) - } + await ensureDep(cache, hash, pkg) } function fetchPackageSync (cache, pkg, integrity) {