-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: experimental command line flag to print the dependency tree
- Loading branch information
Konstantin Yegupov
committed
Jun 13, 2019
1 parent
4ff99b4
commit c431bc4
Showing
6 changed files
with
57 additions
and
14 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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { DepDict, TestOptions, MonitorOptions, DepTree } from './types'; | ||
|
||
// This option is still experimental and might be deprecated. | ||
// It might be a better idea to convert it to a command (i.e. do not perform test/monitor). | ||
export function maybePrintDeps(options: TestOptions | MonitorOptions, rootPackage: DepTree) { | ||
if (options['print-deps']) { | ||
if (options.json) { | ||
// Will produce 2 JSON outputs, one for the deps, one for the vuln scan. | ||
console.log(JSON.stringify(rootPackage, null, 2)); | ||
} else { | ||
printDeps({[rootPackage.name!]: rootPackage}); | ||
} | ||
} | ||
} | ||
|
||
function printDeps(depDict: DepDict, prefix: string = '') { | ||
let counter = 0; | ||
const keys = Object.keys(depDict); | ||
for (const name of keys) { | ||
const dep = depDict[name]; | ||
let branch = '├─ '; | ||
const last = (counter === keys.length - 1); | ||
if (last) { | ||
branch = '└─ '; | ||
} | ||
console.log(prefix + (prefix ? branch : '') + dep.name + ' @ ' + dep.version); | ||
if (dep.dependencies) { | ||
printDeps(dep.dependencies, prefix + (last ? ' ' : '│ ')); | ||
} | ||
counter++; | ||
} | ||
} |
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