Skip to content

Commit

Permalink
feat: allow providing custom dep graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabidobo committed Jan 13, 2023
1 parent 311ff76 commit e3b4a77
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 85 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"d3-node": "3.0.0",
"ora": "6.1.2",
"sandworm-utils": "1.10.4",
"sandworm-utils": "1.11.0",
"yargs": "17.6.0"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env node
const fs = require('fs/promises');
const path = require('path');
const {getChartsSVG} = require('.');
const {getReport} = require('.');

const logger = console;
let currentSpinner;

const getStartMessage = (stage) => {
switch (stage) {
case 'sizes':
return 'Getting sizes...';
case 'graph':
return 'Building dependency graph...';
case 'vulnerabilities':
return 'Getting vulnerability list...';
case 'tree':
Expand All @@ -23,8 +23,8 @@ const getStartMessage = (stage) => {

const getEndMessage = (stage) => {
switch (stage) {
case 'sizes':
return 'Computed package sizes';
case 'graph':
return 'Built dependency graph';
case 'vulnerabilities':
return 'Got vulnerabilities';
case 'tree':
Expand Down Expand Up @@ -107,7 +107,7 @@ require('yargs')
logger.log('\x1b[36m%s\x1b[0m', `Sinkchart 🧭`);
const {default: ora} = await import('ora');

const {svgs, name, version} = await getChartsSVG({
const {svgs, name, version} = await getReport({
types: argv.t ? [argv.t] : undefined,
appPath: argv.p,
includeDev: argv.d,
Expand Down
33 changes: 13 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const {graph} = require('sandworm-utils');
const {getDependencyGraph, addDependencyGraphData} = require('sandworm-utils');
const {getVulnerabilities} = require('./vulnerabilities');
const {buildTree, buildTreemap} = require('./charts');
const {decorateWithSize} = require('./package');

const getChartsSVG = async ({
const getReport = async ({
types = ['tree', 'treemap'],
appPath,
includeDev = false,
Expand All @@ -12,21 +11,13 @@ const getChartsSVG = async ({
maxDepth = 7,
showLicenseInfo = true,
onProgress = () => {},
packageSizes = null,
dependencyGraph,
}) => {
const packageTree = (await graph(appPath)).root;

if (types.includes('treemap')) {
onProgress({type: 'start', stage: 'sizes'});
if (!packageSizes) {
await decorateWithSize({
modules: packageTree.dependencies,
onProgress,
appPath
});
}
onProgress({type: 'end', stage: 'sizes'});
}
onProgress({type: 'start', stage: 'graph'});
const packageTree = (
dependencyGraph || (await getDependencyGraph(appPath, {loadDataFromDisk: true}))
).root;
onProgress({type: 'end', stage: 'graph'});

onProgress({type: 'start', stage: 'vulnerabilities'});
const vulnerabilities = await getVulnerabilities({
Expand All @@ -49,7 +40,7 @@ const getChartsSVG = async ({
const methods = {
tree: buildTree,
treemap: buildTreemap,
}
};

const svgs = await types.reduce(async (agg, type) => {
const current = await agg;
Expand All @@ -69,9 +60,11 @@ const getChartsSVG = async ({
svgs,
name: packageTree.name,
version: packageTree.version,
}
};
};

module.exports = {
getChartsSVG,
getReport,
getDependencyGraph,
addDependencyGraphData,
};
54 changes: 0 additions & 54 deletions src/package.js

This file was deleted.

8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2780,10 +2780,10 @@ safe-regex-test@^1.0.0:
resolved "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==

sandworm-utils@1.10.4:
version "1.10.4"
resolved "https://registry.yarnpkg.com/sandworm-utils/-/sandworm-utils-1.10.4.tgz#c5ded8149efa67831b96e39ed6ad938235e39565"
integrity sha512-0zMiHb8ZuowmrIjb77kvaCQIQbktkErT6TFkc3Y7UEbb9F156YuY/zQz2WjwEDZzcXgFOTpJLG9t1sRLSElBeQ==
sandworm-utils@1.11.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/sandworm-utils/-/sandworm-utils-1.11.0.tgz#3189917538c1d3f108886cf1ba37be1c9ea7b9f9"
integrity sha512-f/IYDxo1LN218AAu4JonEZddTtjXgVo9AluqtKypw0M5HFLrSRQT+3SXTerS7r8/WsqDQ8xn6wJF86SYY1u8pg==
dependencies:
"@pnpm/lockfile-file" "6.0.2"
"@pnpm/logger" "5.0.0"
Expand Down

0 comments on commit e3b4a77

Please sign in to comment.