-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(arborist): refactor arborist bin to use consistent timing/logging #4452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.