From 324e79dfbcca4f6ec2be8a7649df3db62b51f9bc Mon Sep 17 00:00:00 2001 From: sverweij Date: Sat, 28 Oct 2023 19:05:15 +0200 Subject: [PATCH] refactor(configs): makes the 2 sample reporter plugins ESM --- .dependency-cruiser.json | 6 +++--- ...orter-plugin.js => 3d-reporter-plugin.mjs} | 20 +++++++++---------- ...er-plugin.js => stats-reporter-plugin.mjs} | 10 +++++----- package.json | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) rename configs/plugins/{3d-reporter-plugin.js => 3d-reporter-plugin.mjs} (89%) rename configs/plugins/{stats-reporter-plugin.js => stats-reporter-plugin.mjs} (87%) diff --git a/.dependency-cruiser.json b/.dependency-cruiser.json index 4402f4cb1..02c90ad14 100644 --- a/.dependency-cruiser.json +++ b/.dependency-cruiser.json @@ -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", @@ -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$", @@ -63,6 +62,7 @@ "$1", "^node_modules", "^\\.yarn/cache", + "^\\.yarn/berry/cache", "^os$", "^path$", "^path/posix$", diff --git a/configs/plugins/3d-reporter-plugin.js b/configs/plugins/3d-reporter-plugin.mjs similarity index 89% rename from configs/plugins/3d-reporter-plugin.js rename to configs/plugins/3d-reporter-plugin.mjs index f6f587db2..1553d74a2 100644 --- a/configs/plugins/3d-reporter-plugin.js +++ b/configs/plugins/3d-reporter-plugin.mjs @@ -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 = ` @@ -75,13 +75,13 @@ function formatFileName(pFileName) { } function formatDependency(pFrom, pTo) { return `${formatFileName(pFrom)} ${figures.arrowRight}
${formatFileName( - pTo, + pTo )}`; } /** * - * @param {import('../..').ICruiseResult} pCruiseResult + * @param {import('../../types/dependency-cruiser').ICruiseResult} pCruiseResult */ function render3DThing(pCruiseResult) { const lNodes = pCruiseResult.modules.map((pModule) => { @@ -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, }); diff --git a/configs/plugins/stats-reporter-plugin.js b/configs/plugins/stats-reporter-plugin.mjs similarity index 87% rename from configs/plugins/stats-reporter-plugin.js rename to configs/plugins/stats-reporter-plugin.mjs index b615d40a3..f61f513ee 100644 --- a/configs/plugins/stats-reporter-plugin.js +++ b/configs/plugins/stats-reporter-plugin.mjs @@ -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) { @@ -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, }); diff --git a/package.json b/package.json index 11755125e..fbd05846c 100644 --- a/package.json +++ b/package.json @@ -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",