Skip to content

Commit

Permalink
refactor: removes 3rd party dependency 'figures' (#941)
Browse files Browse the repository at this point in the history
## Description

- removes 3rd party dependency 'figures'
- replaces it with the only characters from the package we actually use.

## Motivation and Context

Less dependencies => less maintenance overhead. Moreover, the part of
figures we actually use is _so_ trivial it's simpler to pull it in.


## How Has This Been Tested?

- [x] green ci

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [x] Refactor (non-breaking change which fixes an issue without
changing functionality)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
  • Loading branch information
sverweij authored Jun 29, 2024
1 parent c8f7fa1 commit 838b3e8
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 73 deletions.
11 changes: 4 additions & 7 deletions configs/plugins/3d-reporter-plugin.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as path from "node:path";
import figures from "figures";

const TEMPLATE = `
<html>
Expand Down Expand Up @@ -74,9 +73,7 @@ function formatFileName(pFileName) {
return `${path.dirname(pFileName)}/<b>${path.basename(pFileName)}</b>`;
}
function formatDependency(pFrom, pTo) {
return `${formatFileName(pFrom)} ${figures.arrowRight}</br>${formatFileName(
pTo
)}`;
return `${formatFileName(pFrom)} →</br>${formatFileName(pTo)}`;
}

/**
Expand All @@ -100,14 +97,14 @@ function render3DThing(pCruiseResult) {
source: pCurrentModule.source,
target: pDependency.resolved,
label: formatDependency(pCurrentModule.source, pDependency.resolved),
}))
})),
),
[]
[],
);

return TEMPLATE.replace(/@@NODES@@/g, JSON.stringify(lNodes)).replace(
/@@LINKS@@/g,
JSON.stringify(lLinks)
JSON.stringify(lLinks),
);
}

Expand Down
26 changes: 0 additions & 26 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
"test:u": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings mocha --grep \"^\\[[U]\\]\"",
"test:e": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings mocha --grep \"^\\[[E]\\]\"",
"test:cover": "LANG=en_US.UTF-8 NODE_OPTIONS=--no-warnings c8 mocha",
"test:glob": "set -f && test \"`bin/dependency-cruise.mjs --no-config test/extract/__mocks__/gather-globbing/packages/**/src/**/*.js | grep \"no dependency violations found\"`\" = \" no dependency violations found (6 modules, 0 dependencies cruised)\"",
"test:glob": "set -f && test \"`bin/dependency-cruise.mjs --no-config test/extract/__mocks__/gather-globbing/packages/**/src/**/*.js | grep \"no dependency violations found\"`\" = \" no dependency violations found (6 modules, 0 dependencies cruised)\"",
"test:load": "hyperfine --warmup 3 --runs 30 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --no-cache --no-progress\"",
"test:load:short": "hyperfine --warmup 1 --runs 5 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --no-cache --no-progress\"",
"test:load:cached": "hyperfine --warmup 3 --runs 30 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --cache node_modules/.cache/dependency-cruiser/load-cached --no-progress\"",
Expand All @@ -212,7 +212,6 @@
"chalk": "5.3.0",
"commander": "12.1.0",
"enhanced-resolve": "5.17.0",
"figures": "6.1.0",
"ignore": "5.3.1",
"interpret": "^3.1.1",
"is-installed-globally": "1.0.0",
Expand Down
5 changes: 2 additions & 3 deletions src/cli/format-meta-info.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import chalk from "chalk";
import figures from "figures";

import { getAvailableTranspilers, allExtensions } from "#main/index.mjs";

function bool2Symbol(pBool) {
return pBool ? chalk.green(figures.tick) : chalk.red(figures.cross);
return pBool ? chalk.green("√") : chalk.red("x");
}

function formatTranspilers() {
Expand All @@ -30,7 +29,7 @@ export default function formatMetaInfo() {
Supported:
If you need a supported, but not enabled transpiler ('${chalk.red(
figures.cross,
"x",
)}' below), just install
it in the same folder dependency-cruiser is installed. E.g. 'npm i livescript'
will enable livescript support if it's installed in your project folder.
Expand Down
5 changes: 1 addition & 4 deletions src/cli/init-config/write-config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { writeFileSync } from "node:fs";
import figures from "figures";
import chalk from "chalk";
import {
fileExists,
Expand Down Expand Up @@ -30,9 +29,7 @@ export default function writeConfig(
try {
writeFileSync(pFileName, pConfig);
pOutStream.write(
`\n ${chalk.green(
figures.tick,
)} Successfully created '${pFileName}'\n\n`,
`\n ${chalk.green("√")} Successfully created '${pFileName}'\n\n`,
);
/* c8 ignore start */
} catch (pError) {
Expand Down
7 changes: 2 additions & 5 deletions src/cli/init-config/write-run-scripts-to-manifest.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable security/detect-object-injection */
import { writeFileSync } from "node:fs";
import figures from "figures";
import chalk from "chalk";
import { PACKAGE_MANIFEST as _PACKAGE_MANIFEST } from "../defaults.mjs";
import { readManifest } from "./environment-helpers.mjs";
Expand Down Expand Up @@ -121,13 +120,11 @@ function getSuccessMessage(pDestinationManifestFileName) {
return EXPERIMENTAL_SCRIPT_DOC.reduce(
(pAll, pScript) => {
return `${pAll}${
`\n ${chalk.green(figures.play)} ${pScript.headline}` +
`\n ${chalk.green("►")} ${pScript.headline}` +
`\n${wrapAndIndent(`${pScript.description}`, lExplanationIndent)}\n\n`
}`;
},
` ${chalk.green(
figures.tick,
)} Run scripts added to '${pDestinationManifestFileName}':\n`,
` ${chalk.green("√")} Run scripts added to '${pDestinationManifestFileName}':\n`,
);
}

Expand Down
5 changes: 2 additions & 3 deletions src/cli/listeners/cli-feedback.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import chalk from "chalk";
import figures from "figures";
import { SUMMARY } from "#utl/bus.mjs";

const FULL_ON = 100;

function normalizeParameters(pParameters) {
return {
barSize: 10,
block: figures.squareSmallFilled,
blank: figures.squareSmall,
block: "■",
blank: "□",
...(pParameters || {}),
};
}
Expand Down
27 changes: 8 additions & 19 deletions src/report/error.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { EOL } from "node:os";
import chalk from "chalk";
import figures from "figures";
import {
formatPercentage,
formatViolation as _formatViolation,
Expand All @@ -20,9 +19,7 @@ const EXTRA_PATH_INFORMATION_INDENT = 6;
function formatMiniDependency(pMiniDependency) {
return EOL.concat(
wrapAndIndent(
pMiniDependency
.map(({ name }) => name)
.join(` ${figures.arrowRight} ${EOL}`),
pMiniDependency.map(({ name }) => name).join(` → ${EOL}`),
EXTRA_PATH_INFORMATION_INDENT,
),
);
Expand All @@ -33,29 +30,23 @@ function formatModuleViolation(pViolation) {
}

function formatDependencyViolation(pViolation) {
return `${chalk.bold(pViolation.from)} ${figures.arrowRight} ${chalk.bold(
pViolation.to,
)}`;
return `${chalk.bold(pViolation.from)}${chalk.bold(pViolation.to)}`;
}

function formatCycleViolation(pViolation) {
return `${chalk.bold(pViolation.from)} ${
figures.arrowRight
} ${formatMiniDependency(pViolation.cycle)}`;
return `${chalk.bold(pViolation.from)}${formatMiniDependency(pViolation.cycle)}`;
}

function formatReachabilityViolation(pViolation) {
return `${chalk.bold(pViolation.from)} ${figures.arrowRight} ${chalk.bold(
return `${chalk.bold(pViolation.from)} ${chalk.bold(
pViolation.to,
)}${formatMiniDependency(pViolation.via)}`;
}

function formatInstabilityViolation(pViolation) {
return `${formatDependencyViolation(pViolation)}${EOL}${wrapAndIndent(
chalk.dim(
`instability: ${formatPercentage(pViolation.metrics.from.instability)} ${
figures.arrowRight
} ${formatPercentage(pViolation.metrics.to.instability)}`,
`instability: ${formatPercentage(pViolation.metrics.from.instability)}${formatPercentage(pViolation.metrics.to.instability)}`,
),
EXTRA_PATH_INFORMATION_INDENT,
)}`;
Expand Down Expand Up @@ -96,7 +87,7 @@ function sumMeta(pMeta) {
}

function formatSummary(pSummary) {
let lMessage = `${EOL}${figures.cross} ${sumMeta(
let lMessage = `${EOL}x ${sumMeta(
pSummary,
)} dependency violations (${formatMeta(pSummary)}). ${
pSummary.totalCruised
Expand All @@ -117,7 +108,7 @@ function addExplanation(pRuleSet, pLong) {
function formatIgnoreWarning(pNumberOfIgnoredViolations) {
if (pNumberOfIgnoredViolations > 0) {
return chalk.yellow(
`${figures.warning} ${pNumberOfIgnoredViolations} known violations ignored. Run with --no-ignore-known to see them.${EOL}`,
` ${pNumberOfIgnoredViolations} known violations ignored. Run with --no-ignore-known to see them.${EOL}`,
);
}
return "";
Expand All @@ -129,9 +120,7 @@ function report(pResults, pLong) {
);

if (lNonIgnorableViolations.length === 0) {
return `${EOL}${chalk.green(
figures.tick,
)} no dependency violations found (${
return `${EOL}${chalk.green("√")} no dependency violations found (${
pResults.summary.totalCruised
} modules, ${
pResults.summary.totalDependenciesCruised
Expand Down
5 changes: 1 addition & 4 deletions src/report/text.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import figures from "figures";
import chalk from "chalk";

const DEFAULT_OPTIONS = {
Expand Down Expand Up @@ -41,9 +40,7 @@ function stringifyModule(pModule) {
}

function stringify(pFlatDependency) {
return `${stringifyModule(pFlatDependency.from)} ${
figures.arrowRight
} ${stringifyModule(pFlatDependency.to)}`;
return `${stringifyModule(pFlatDependency.from)}${stringifyModule(pFlatDependency.to)}`;
}

/**
Expand Down

0 comments on commit 838b3e8

Please sign in to comment.