Skip to content

Commit

Permalink
refactor(configs): makes the 2 sample reporter plugins ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Oct 28, 2023
1 parent afbf5e0 commit a442703
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
14 changes: 5 additions & 9 deletions .dependency-cruiser.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"\\.d\\.ts$",
"(^|/)tsconfig\\.json$",
"(^|/)(babel|webpack)\\.config\\.(js|cjs|mjs|ts|json)$",
"-reporter-plugin\\.js$",
"-reporter-plugin\\.mjs$",
"\\.schema\\.json$",
"^tools/istanbul-json-summary-to-markdown\\.mjs$",
"^src/report/json\\.mjs",
Expand All @@ -39,8 +39,7 @@
"to": {
"pathNot": [
"^src/(main|utl|config-utl)/",
"^node_modules",
"^\\.yarn/cache",
"node_modules/", // ^node_modules should work, but doesn't - on _planet yarn_. .yarn/cache/ or .yarn/berry/cache/ don't work either anymore, although it's where they're _actualy_ located. So we're stuck with this for now.
"^os$",
"^fs(/promises)?$",
"^path$",
Expand All @@ -61,8 +60,7 @@
"to": {
"pathNot": [
"$1",
"^node_modules",
"^\\.yarn/cache",
"node_modules/", // ^node_modules should work, but doesn't - on _planet yarn_. .yarn/cache/ or .yarn/berry/cache/ don't work either anymore, although it's where they're _actualy_ located. So we're stuck with this for now.
"^os$",
"^path$",
"^path/posix$",
Expand All @@ -82,8 +80,7 @@
"to": {
"pathNot": [
"$1",
"^node_modules",
"^\\.yarn/cache",
"node_modules/", // ^node_modules should work, but doesn't - on _planet yarn_. .yarn/cache/ or .yarn/berry/cache/ don't work either anymore, although it's where they're _actualy_ located. So we're stuck with this for now.
"^(path|path/posix|fs|module|os)$",
"^src/meta\\.js$",
"^types/",
Expand All @@ -109,8 +106,7 @@
"to": {
"pathNot": [
"^src/cli",
"^node_modules",
"^\\.yarn/cache",
"node_modules/", // ^node_modules should work, but doesn't - on _planet yarn_. .yarn/cache/ or .yarn/berry/cache/ don't work either anymore, although it's where they're _actualy_ located. So we're stuck with this for now.
"^src/meta\\.js$",
"^os$"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require("node:path");
const figures = require("figures");
import * as path from "node:path";
import figures from "figures";

const TEMPLATE = `
<html>
Expand Down Expand Up @@ -75,13 +75,13 @@ function formatFileName(pFileName) {
}
function formatDependency(pFrom, pTo) {
return `${formatFileName(pFrom)} ${figures.arrowRight}</br>${formatFileName(
pTo,
pTo
)}`;
}

/**
*
* @param {import('../..').ICruiseResult} pCruiseResult
* @param {import('../../types/dependency-cruiser').ICruiseResult} pCruiseResult
*/
function render3DThing(pCruiseResult) {
const lNodes = pCruiseResult.modules.map((pModule) => {
Expand All @@ -100,28 +100,28 @@ 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)
);
}

/**
* Sample plugin: 3d representation
*
* @param {import('../..').ICruiseResult} pCruiseResult -
* @param {import('../../types/dependency-cruiser').ICruiseResult} pCruiseResult -
* the output of a dependency-cruise adhering to dependency-cruiser's
* cruise result schema
* @return {import('../..').IReporterOutput} -
* @return {import('../../types/dependency-cruiser').IReporterOutput} -
* output: a string
* exitCode: 0
*/
module.exports = (pCruiseResult) => ({
export default (pCruiseResult) => ({
output: render3DThing(pCruiseResult),
exitCode: 0,
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function doMagic(pCruiseResult) {
* returns an object with some stats from the ICruiseResult pCruiseResult it
* got passed
*
* @param {import('../..').ICruiseResult} pCruiseResult - a result from a cruise.
* @param {import('../../types/dependency-cruiser').ICruiseResult} pCruiseResult - a result from a cruise.
* @return {string} an object with some stats
*/
function samplePluginReporter(pCruiseResult) {
Expand Down Expand Up @@ -65,18 +65,18 @@ function samplePluginReporter(pCruiseResult) {
/**
* Sample plugin
*
* @param {import('../..').ICruiseResult} pCruiseResult -
* @param {import('../../types/dependency-cruiser').ICruiseResult} pCruiseResult -
* the output of a dependency-cruise adhering to dependency-cruiser's
* cruise result schema
* @return {import('../..').IReporterOutput} -
* @return {import('../../types/dependency-cruiser').IReporterOutput} -
* output: some stats on modules and dependencies in json format
* exitCode: 0
*/
module.exports = (pCruiseResult) => ({
export default (pCruiseResult) => ({
output: JSON.stringify(
samplePluginReporter(pCruiseResult),
null,
DEFAULT_JSON_INDENT,
DEFAULT_JSON_INDENT
),
exitCode: 0,
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"import": "./src/config-utl/extract-webpack-resolve-config.mjs",
"types": "./types/extract-webpack-resolve-config.d.ts"
},
"./sample-reporter-plugin": "./configs/plugins/stats-reporter-plugin.js",
"./sample-3d-reporter-plugin": "./configs/plugins/3d-reporter-plugin.js",
"./sample-reporter-plugin": "./configs/plugins/stats-reporter-plugin.mjs",
"./sample-3d-reporter-plugin": "./configs/plugins/3d-reporter-plugin.mjs",
"./mermaid-reporter-plugin": "./src/report/mermaid.mjs"
},
"types": "types/dependency-cruiser.d.ts",
Expand Down

0 comments on commit a442703

Please sign in to comment.