Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add specific label & icon for NodeJS internals #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/app/components/DepGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ const DepGraph: FC<Props> = ({ 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),
}),
);

Expand Down
30 changes: 17 additions & 13 deletions src/app/utils/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Module, ModuleDeps, ModuleImportMap } from './types';

export function parseModuleDeps(result: ICruiseResult): ModuleDeps {
const localModules = new Set<string>();
const nodeBuiltInModules = new Set<string>();
const aliases = new Map<string, string>();
const npmPackageNames = new Map<string, string>();
const sourceDeps = new Map<
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/app/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type Module = {
source: string;
alias?: string;
isLocal: boolean;
isNodeBuiltIn: boolean;
};

export type ModuleDeps = {
Expand Down