|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | | -let config |
4 | 3 | let ensurePkg |
5 | 4 | let prepare |
6 | 5 |
|
| 6 | +const figgyPudding = require('figgy-pudding') |
| 7 | + |
| 8 | +const MainOpts = figgyPudding({ |
| 9 | + log: { default: () => require('libnpm').log }, |
| 10 | + loglevel: { default: 'notice' } |
| 11 | +}, { |
| 12 | + other () { return true } |
| 13 | +}) |
| 14 | + |
7 | 15 | if (require.main === module && process.argv[2] === 'ensure-pkg') { |
8 | 16 | main(...process.argv.slice(3)) |
9 | 17 | } |
10 | 18 |
|
11 | 19 | module.exports = main |
12 | | -async function main (cache, integrity, pkg) { |
13 | | - pkg = JSON.parse(pkg) |
14 | | - if (!config) { config = require('./config.js') } |
15 | | - const opts = config().concat({ |
| 20 | +async function main (cache, integrity, pkg, opts) { |
| 21 | + opts = MainOpts(JSON.parse(opts)).concat({ |
16 | 22 | cache, |
17 | 23 | integrity, |
18 | | - log: require('npmlog'), |
19 | | - // loglevel: 'silly', |
20 | 24 | 'restore-missing': true, |
21 | 25 | force: true |
22 | | - }, { |
23 | | - other () { return true } |
24 | 26 | }) |
| 27 | + pkg = JSON.parse(pkg) |
25 | 28 | opts.log.heading = 'tink' |
26 | | - opts.log.notice('fs', 'unpacking', `${pkg.name}@${pkg.version}`) |
| 29 | + opts.log.level = opts.loglevel |
| 30 | + opts.log.notice('fs', 'fetching', `${pkg.name}@${pkg.version}`) |
27 | 31 | try { |
28 | 32 | if (!prepare) { prepare = require('./commands/prepare.js') } |
29 | | - opts.log.level = 'silent' |
30 | | - const res = await prepare.handler(opts.concat({ |
31 | | - loglevel: 'silent' |
32 | | - }), [pkg.name]) |
| 33 | + const res = await prepare.handler(opts, [pkg.name]) |
33 | 34 | if (res && !res.pkgCount) { throw new Error('no packages installed') } |
34 | 35 | } catch (err) { |
35 | 36 | if (!ensurePkg) { ensurePkg = require('./ensure-package.js') } |
36 | | - opts.log.level = opts.loglevel |
37 | 37 | await ensurePkg(cache, pkg.name, pkg, opts) |
38 | 38 | } |
39 | 39 | } |
0 commit comments