Skip to content
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

Display dependency graph progress #71

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/cli/progress.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const logger = require('./logger');

let currentSpinner;

const getStartMessage = (stage) => {
Expand Down Expand Up @@ -44,7 +46,7 @@ const getEndMessage = (stage) => {

const onProgress =
(ora) =>
({type, stage, message}) => {
({type, stage, message, progress}) => {
switch (type) {
case 'start':
currentSpinner = ora().start(getStartMessage(stage));
Expand All @@ -55,6 +57,11 @@ const onProgress =
case 'update':
currentSpinner.text = message;
break;
case 'progress':
currentSpinner.text = `${getStartMessage(stage)} ${logger.colors.DIM}${progress}${
logger.colors.RESET
}`;
break;
default:
break;
}
Expand Down
19 changes: 15 additions & 4 deletions src/graph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {postProcessGraph, addDependencyGraphData, getRegistryDataMultiple} = requ

const generateGraphPromise = async (
appPath,
{packageData, loadDataFrom = false, rootIsShell = false, includeDev = false} = {},
{packageData, loadDataFrom = false, rootIsShell = false, includeDev = false, onProgress} = {},
) => {
const lockfile = await loadLockfile(appPath);

Expand Down Expand Up @@ -68,6 +68,7 @@ const generateGraphPromise = async (
} else if (loadDataFrom === 'registry') {
const {data, errors: registryErrors} = await getRegistryDataMultiple(
includeDev ? allConnectedPackages : prodDependencies,
onProgress,
);
additionalPackageData = data;
errors = [...errors, ...registryErrors];
Expand Down Expand Up @@ -98,14 +99,24 @@ const generateGraphAsync = (appPath, options, done = () => {}) => {

const generateGraph = (
appPath,
{packageData, loadDataFrom = false, rootIsShell = false, includeDev = false} = {},
{packageData, loadDataFrom = false, rootIsShell = false, includeDev = false, onProgress} = {},
done = undefined,
) => {
if (typeof done === 'function') {
return generateGraphAsync(appPath, {packageData, loadDataFrom, rootIsShell, includeDev}, done);
return generateGraphAsync(
appPath,
{packageData, loadDataFrom, rootIsShell, includeDev, onProgress},
done,
);
}

return generateGraphPromise(appPath, {packageData, loadDataFrom, rootIsShell, includeDev});
return generateGraphPromise(appPath, {
packageData,
loadDataFrom,
rootIsShell,
includeDev,
onProgress,
});
};

module.exports = generateGraph;
7 changes: 6 additions & 1 deletion src/graph/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ const getRegistryData = (packageName, packageVersion) =>
req.end();
});

const getRegistryDataMultiple = async (packages) => {
const getRegistryDataMultiple = async (packages, onProgress = () => {}) => {
const totalCount = packages.length;
let currentCount = 0;
const errors = [];
const threadCount = 10;
const jobCount = Math.ceil(packages.length / threadCount);
Expand All @@ -312,6 +314,9 @@ const getRegistryDataMultiple = async (packages) => {
try {
const {name, version} = packages[globalJobIndex];
const packageData = await getRegistryData(name, version);

currentCount += 1;
onProgress?.(`${currentCount}/${totalCount}`);
return [...prevData, packageData];
} catch (error) {
errors.push(error);
Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ const getReport = async ({
// Generate the dependency graph
onProgress({type: 'start', stage: 'graph'});
const dGraph =
dependencyGraph || (await getDependencyGraph(appPath, {loadDataFrom, rootIsShell, includeDev}));
dependencyGraph ||
(await getDependencyGraph(appPath, {
loadDataFrom,
rootIsShell,
includeDev,
onProgress: (progress) => onProgress({type: 'progress', stage: 'graph', progress}),
}));
const packageGraph = dGraph.root;
errors = [...errors, ...(dGraph.errors || [])];
onProgress({type: 'end', stage: 'graph'});
Expand Down