|
1 | | -const options = require('./lib/options.js') |
2 | | -require('./lib/logging.js') |
3 | | -require('./lib/timers.js') |
4 | | - |
5 | 1 | const Arborist = require('../') |
6 | | -const a = new Arborist(options) |
7 | | -const query = options._.shift() |
8 | | -const start = process.hrtime() |
9 | | -a.loadVirtual().then(tree => { |
10 | | - // only load the actual tree if the virtual one doesn't have modern metadata |
11 | | - if (!tree.meta || !(tree.meta.originalLockfileVersion >= 2)) { |
12 | | - console.error('old metadata, load actual') |
13 | | - throw 'load actual' |
14 | | - } else { |
15 | | - console.error('meta ok, return virtual tree') |
16 | | - return tree |
17 | | - } |
18 | | -}).catch(() => a.loadActual()).then(tree => { |
19 | | - const end = process.hrtime(start) |
20 | | - if (!query) { |
21 | | - for (const node of tree.inventory.values()) { |
22 | | - if (node.package.funding) { |
23 | | - console.log(node.name, node.location, node.package.funding) |
| 2 | + |
| 3 | +const log = require('./lib/logging.js') |
| 4 | + |
| 5 | +module.exports = (options, time) => { |
| 6 | + const query = options._.shift() |
| 7 | + const a = new Arborist(options) |
| 8 | + return a |
| 9 | + .loadVirtual() |
| 10 | + .then(tree => { |
| 11 | + // only load the actual tree if the virtual one doesn't have modern metadata |
| 12 | + if (!tree.meta || !(tree.meta.originalLockfileVersion >= 2)) { |
| 13 | + log.error('old metadata, load actual') |
| 14 | + throw 'load actual' |
| 15 | + } else { |
| 16 | + log.error('meta ok, return virtual tree') |
| 17 | + return tree |
24 | 18 | } |
25 | | - } |
26 | | - } else { |
27 | | - for (const node of tree.inventory.query('name', query)) { |
28 | | - if (node.package.funding) { |
29 | | - console.log(node.name, node.location, node.package.funding) |
| 19 | + }) |
| 20 | + .catch(() => a.loadActual()) |
| 21 | + .then(time) |
| 22 | + .then(({ timing, result: tree }) => { |
| 23 | + if (!query) { |
| 24 | + for (const node of tree.inventory.values()) { |
| 25 | + if (node.package.funding) { |
| 26 | + log.info(node.name, node.location, node.package.funding) |
| 27 | + } |
| 28 | + } |
| 29 | + } else { |
| 30 | + for (const node of tree.inventory.query('name', query)) { |
| 31 | + if (node.package.funding) { |
| 32 | + log.info(node.name, node.location, node.package.funding) |
| 33 | + } |
| 34 | + } |
30 | 35 | } |
31 | | - } |
32 | | - } |
33 | | - console.error(`read ${tree.inventory.size} deps in ${end[0] * 1000 + end[1] / 1e6}ms`) |
34 | | -}) |
| 36 | + return `read ${tree.inventory.size} deps in ${timing.ms}` |
| 37 | + }) |
| 38 | +} |
0 commit comments