This repository has been archived by the owner on Jul 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pkglock): fall back to regular ensure-pkg if installer fails-ish
- Loading branch information
Showing
2 changed files
with
41 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters