( packageJsonPath: string, )
| 56 | } |
| 57 | |
| 58 | export async function getTotalDependencies( |
| 59 | packageJsonPath: string, |
| 60 | ): Promise<DependencyTotals> { |
| 61 | const formattedPath = path.relative(process.cwd(), packageJsonPath); |
| 62 | |
| 63 | return logger.task( |
| 64 | `Counting direct dependencies in ${formattedPath}`, |
| 65 | async () => { |
| 66 | const parsedDeps = await readJsonFile<PackageJson>(packageJsonPath); |
| 67 | |
| 68 | const mergedDeps = objectFromEntries( |
| 69 | dependencyGroupLong.map(group => { |
| 70 | const deps = parsedDeps[group]; |
| 71 | return [group, deps == null ? [] : objectToKeys(deps)]; |
| 72 | }), |
| 73 | ); |
| 74 | |
| 75 | const depTotals = objectFromEntries( |
| 76 | objectToKeys(mergedDeps).map(deps => [ |
| 77 | deps, |
| 78 | new Set(mergedDeps[deps]).size, |
| 79 | ]), |
| 80 | ); |
| 81 | |
| 82 | const depTotal = Object.values(depTotals).reduce( |
| 83 | (acc, count) => acc + count, |
| 84 | 0, |
| 85 | ); |
| 86 | const groupsSummary = objectToEntries(depTotals) |
| 87 | .filter(([, count]) => count > 0) |
| 88 | .map(([group, count]) => `${count} ${group}`) |
| 89 | .join(', '); |
| 90 | const message = `Found ${pluralizeToken('direct dependency', depTotal)} in ${formattedPath} (${groupsSummary})`; |
| 91 | |
| 92 | return { message, result: depTotals }; |
| 93 | }, |
| 94 | ); |
| 95 | } |
no test coverage detected