-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(arborist): refactor arborist bin to use consistent timing/logging
This attempts to make the arborist bin script behave more like the npm cli with regards to the handing of timing and logging. It also adds the a `logfile` argument to write logs to a file instead of (or in addition to) stderr. This can be helpful for benchmarking performance of loggins or terminal display.
- Loading branch information
1 parent
1b4385f
commit 72b34f4
Showing
17 changed files
with
490 additions
and
359 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
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
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,19 @@ | ||
const Arborist = require('../') | ||
const print = require('./lib/print-tree.js') | ||
const options = require('./lib/options.js') | ||
require('./lib/logging.js') | ||
require('./lib/timers.js') | ||
|
||
const start = process.hrtime() | ||
new Arborist(options).loadActual(options).then(tree => { | ||
const end = process.hrtime(start) | ||
if (!process.argv.includes('--quiet')) { | ||
print(tree) | ||
} | ||
const printTree = require('./lib/print-tree.js') | ||
|
||
console.error(`read ${tree.inventory.size} deps in ${end[0] * 1000 + end[1] / 1e6}ms`) | ||
if (options.save) { | ||
tree.meta.save() | ||
} | ||
if (options.saveHidden) { | ||
tree.meta.hiddenLockfile = true | ||
tree.meta.filename = options.path + '/node_modules/.package-lock.json' | ||
tree.meta.save() | ||
} | ||
}).catch(er => console.error(er)) | ||
module.exports = (options, time) => new Arborist(options) | ||
.loadActual(options) | ||
.then(time) | ||
.then(async ({ timing, result: tree }) => { | ||
printTree(tree) | ||
if (options.save) { | ||
await tree.meta.save() | ||
} | ||
if (options.saveHidden) { | ||
tree.meta.hiddenLockfile = true | ||
tree.meta.filename = options.path + '/node_modules/.package-lock.json' | ||
await tree.meta.save() | ||
} | ||
return `read ${tree.inventory.size} deps in ${timing.ms}` | ||
}) |
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
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,34 +1,38 @@ | ||
const options = require('./lib/options.js') | ||
require('./lib/logging.js') | ||
require('./lib/timers.js') | ||
|
||
const Arborist = require('../') | ||
const a = new Arborist(options) | ||
const query = options._.shift() | ||
const start = process.hrtime() | ||
a.loadVirtual().then(tree => { | ||
// only load the actual tree if the virtual one doesn't have modern metadata | ||
if (!tree.meta || !(tree.meta.originalLockfileVersion >= 2)) { | ||
console.error('old metadata, load actual') | ||
throw 'load actual' | ||
} else { | ||
console.error('meta ok, return virtual tree') | ||
return tree | ||
} | ||
}).catch(() => a.loadActual()).then(tree => { | ||
const end = process.hrtime(start) | ||
if (!query) { | ||
for (const node of tree.inventory.values()) { | ||
if (node.package.funding) { | ||
console.log(node.name, node.location, node.package.funding) | ||
|
||
const log = require('./lib/logging.js') | ||
|
||
module.exports = (options, time) => { | ||
const query = options._.shift() | ||
const a = new Arborist(options) | ||
return a | ||
.loadVirtual() | ||
.then(tree => { | ||
// only load the actual tree if the virtual one doesn't have modern metadata | ||
if (!tree.meta || !(tree.meta.originalLockfileVersion >= 2)) { | ||
log.error('old metadata, load actual') | ||
throw 'load actual' | ||
} else { | ||
log.error('meta ok, return virtual tree') | ||
return tree | ||
} | ||
} | ||
} else { | ||
for (const node of tree.inventory.query('name', query)) { | ||
if (node.package.funding) { | ||
console.log(node.name, node.location, node.package.funding) | ||
}) | ||
.catch(() => a.loadActual()) | ||
.then(time) | ||
.then(({ timing, result: tree }) => { | ||
if (!query) { | ||
for (const node of tree.inventory.values()) { | ||
if (node.package.funding) { | ||
log.info(node.name, node.location, node.package.funding) | ||
} | ||
} | ||
} else { | ||
for (const node of tree.inventory.query('name', query)) { | ||
if (node.package.funding) { | ||
log.info(node.name, node.location, node.package.funding) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
console.error(`read ${tree.inventory.size} deps in ${end[0] * 1000 + end[1] / 1e6}ms`) | ||
}) | ||
return `read ${tree.inventory.size} deps in ${timing.ms}` | ||
}) | ||
} |
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,21 +1,14 @@ | ||
const Arborist = require('../') | ||
|
||
const { inspect } = require('util') | ||
const options = require('./lib/options.js') | ||
const print = require('./lib/print-tree.js') | ||
require('./lib/logging.js') | ||
require('./lib/timers.js') | ||
const printTree = require('./lib/print-tree.js') | ||
|
||
const start = process.hrtime() | ||
new Arborist(options).buildIdealTree(options).then(tree => { | ||
const end = process.hrtime(start) | ||
print(tree) | ||
console.error(`resolved ${tree.inventory.size} deps in ${end[0] + end[1] / 10e9}s`) | ||
if (tree.meta && options.save) { | ||
tree.meta.save() | ||
} | ||
}).catch(er => { | ||
const opt = { depth: Infinity, color: true } | ||
console.error(er.code === 'ERESOLVE' ? inspect(er, opt) : er) | ||
process.exitCode = 1 | ||
}) | ||
module.exports = (options, time) => new Arborist(options) | ||
.buildIdealTree(options) | ||
.then(time) | ||
.then(async ({ timing, result: tree }) => { | ||
printTree(tree) | ||
if (tree.meta && options.save) { | ||
await tree.meta.save() | ||
} | ||
return `resolved ${tree.inventory.size} deps in ${timing.seconds}` | ||
}) |
Oops, something went wrong.