From 33fd82d3bcba614bae8fec4c87b689c552a80890 Mon Sep 17 00:00:00 2001 From: Alexandre Germain Date: Thu, 5 Dec 2024 21:59:49 +0100 Subject: [PATCH] feat: add specific label & icon for NodeJS internals --- src/app/components/DepGraph.tsx | 12 +++++++++--- src/app/utils/parsers.ts | 30 +++++++++++++++++------------- src/app/utils/types.ts | 1 + 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/app/components/DepGraph.tsx b/src/app/components/DepGraph.tsx index 258bf92..923ab0c 100644 --- a/src/app/components/DepGraph.tsx +++ b/src/app/components/DepGraph.tsx @@ -41,13 +41,19 @@ const DepGraph: FC = ({ moduleDeps, filters }) => { useEffect(() => { if (containerRef.current && graph != null) { const nodes = graph.modules.map( - ({ path, isLocal }): Node => ({ + ({ path, isLocal, isNodeBuiltIn }): Node => ({ id: path, - label: isLocal ? filenameFromPath(path) : path, + label: isLocal + ? filenameFromPath(path) + : isNodeBuiltIn + ? `node:${path}` + : path, title: path, image: isLocal ? getIconUrlForFilePath(path, ICONS_URL) - : getIconUrlByName('npm', ICONS_URL), + : isNodeBuiltIn + ? getIconUrlByName('nodejs', ICONS_URL) + : getIconUrlByName('npm', ICONS_URL), }), ); diff --git a/src/app/utils/parsers.ts b/src/app/utils/parsers.ts index 53004e9..4c75200 100644 --- a/src/app/utils/parsers.ts +++ b/src/app/utils/parsers.ts @@ -3,6 +3,7 @@ import { Module, ModuleDeps, ModuleImportMap } from './types'; export function parseModuleDeps(result: ICruiseResult): ModuleDeps { const localModules = new Set(); + const nodeBuiltInModules = new Set(); const aliases = new Map(); const npmPackageNames = new Map(); const sourceDeps = new Map< @@ -32,6 +33,9 @@ export function parseModuleDeps(result: ICruiseResult): ModuleDeps { if (dependency.dependencyTypes.includes('local')) { localModules.add(dependency.resolved); } + if (dependency.dependencyTypes.includes('core')) { + nodeBuiltInModules.add(dependency.resolved); + } if (dependency.dependencyTypes.includes('aliased')) { aliases.set(dependency.resolved, dependency.module); localModules.add(dependency.resolved); @@ -44,19 +48,19 @@ export function parseModuleDeps(result: ICruiseResult): ModuleDeps { }); const allModules = result.modules - .map( - (module): Module => { - const npmPackageName = npmPackageNames.get(module.source); - const alias = aliases.get(module.source); - const isLocal = localModules.has(module.source); - return { - path: npmPackageName ?? module.source, - source: module.source, - isLocal, - ...(alias && { alias }), - }; - }, - ) + .map((module): Module => { + const npmPackageName = npmPackageNames.get(module.source); + const alias = aliases.get(module.source); + const isLocal = localModules.has(module.source); + const isNodeBuiltIn = nodeBuiltInModules.has(module.source); + return { + path: npmPackageName ?? module.source, + source: module.source, + isLocal, + isNodeBuiltIn, + ...(alias && { alias }), + }; + }) .filter( (item, index, array) => array.findIndex(({ path }) => path === item.path) === index, diff --git a/src/app/utils/types.ts b/src/app/utils/types.ts index 4118307..05ba393 100644 --- a/src/app/utils/types.ts +++ b/src/app/utils/types.ts @@ -3,6 +3,7 @@ export type Module = { source: string; alias?: string; isLocal: boolean; + isNodeBuiltIn: boolean; }; export type ModuleDeps = {