Skip to content

Commit

Permalink
16.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Jun 8, 2024
1 parent 34e3795 commit 730d42a
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/assets/flat-report-example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dependency-cruiser",
"version": "16.3.2",
"version": "16.3.3",
"description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
"keywords": [
"static analysis",
Expand Down
75 changes: 75 additions & 0 deletions pw.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { basename, dirname } from "node:path";

const EOL = "\n";

const template = `graph {
layout=patchwork
fontname=Helvetica
fontsize=9
node [style=filled fontname=Helvetica fontsize=9]
$\{modules}
}
`;

const LOCALE = undefined;
const K = 1024;
const formatSize = new Intl.NumberFormat(LOCALE, {
signDisplay: "never",
style: "unit",
unit: "kilobyte",
unitDisplay: "narrow",
maximumFractionDigits: 3,
minimumFractionDigits: 3,
}).format;

const formatNumber = new Intl.NumberFormat(LOCALE).format;

// const formatNumber = (pX) => pX;

const size2color = [
[16_384, "darkred"],
[8_192, "red"],
[4_096, "orange"],
[2_048, "yellow"],
[1_024, "green"],
[512, "lightgreen"],
[0, "white"],
];

function getColor(pSize) {
let lReturnValue = "#ffffff";

for (const [lSize, lColor] of size2color) {
if (pSize >= lSize) {
return lColor;
}
}
return lReturnValue;
}

/**
* Returns the results of a cruise in JSON
*
* @param {import("../../types/cruise-result").ICruiseResult} pResults
* @returns {import("../../types/dependency-cruiser").IReporterOutput}
*/
export default function json(pResults) {
return {
output:
template.replace(
"${modules}",
pResults.modules
.filter((pModule) => pModule.experimentalStats?.size)
.filter(
(pModule) =>
!pModule.source.endsWith(".json") &&
!pModule.source.endsWith(".ts"),
)
.map((pModule) => {
return `"${basename(pModule.source) + EOL + dirname(pModule.source) + EOL + formatSize(pModule.experimentalStats.size / K)}" [area=${pModule.experimentalStats.size / (K / 3)} fillcolor="${getColor(pModule.experimentalStats.size)}"]`;
})
.join(EOL),
) + EOL,
exitCode: 0,
};
}
2 changes: 1 addition & 1 deletion src/meta.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 730d42a

Please sign in to comment.