Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
fix(pkglock): fall back to regular ensure-pkg if installer fails-ish
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Nov 12, 2018
1 parent 1a15eb1 commit 6c4f80d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
49 changes: 31 additions & 18 deletions lib/lock-worker.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
'use strict'

let config
let ensurePkg
let prepare

if (require.main === module && process.argv[2] === 'ensure-pkg') {
process.nextTick(async function () {
let [cache, integrity, pkg] = process.argv.slice(3)
pkg = JSON.parse(pkg)
if (!config) { config = require('./config.js') }
const opts = config().concat({
cache,
integrity,
log: require('npmlog'),
// loglevel: 'silly',
'restore-missing': true,
force: true
}, {
other () { return true }
})
opts.log.heading = 'tink'
opts.log.level = opts.loglevel
opts.log.notice('fs', 'unpacking', `${pkg.name}@${pkg.version}`)
await require('./commands/prepare.js').handler(opts, [pkg.name])
main(...process.argv.slice(3))
}

module.exports = main
async function main (cache, integrity, pkg) {
pkg = JSON.parse(pkg)
if (!config) { config = require('./config.js') }
const opts = config().concat({
cache,
integrity,
log: require('npmlog'),
// loglevel: 'silly',
'restore-missing': true,
force: true
}, {
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') }
} catch (err) {
if (!ensurePkg) { ensurePkg = require('./ensure-package.js') }
await ensurePkg(cache, pkg.name, pkg, opts)
}
}
14 changes: 10 additions & 4 deletions lib/pkglock.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,19 @@ function getPkg (cache, scope, pkgName) {

let ensurePkg
let config
let ensureDep
async function fetchPackage (cache, pkg, hash) {
if (!ensurePkg) { ensurePkg = require('./ensure-package.js') }
if (!config) { config = require('./config.js') }
await ensurePkg(cache, pkg.name, pkg, config().concat({
cache,
integrity: hash
}))
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
}))
}
}

function fetchPackageSync (cache, pkg, integrity) {
Expand Down

0 comments on commit 6c4f80d

Please sign in to comment.