From 9bb29dc2b717cb94575b2861399e07a6a29a2474 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Tue, 23 Apr 2024 18:30:03 +0200 Subject: [PATCH] feature: add `AtlasModuleRef` type for `module.imports` and `module.importedBy` --- src/data/MetroGraphSource.ts | 11 +++++++---- src/data/types.ts | 8 +++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/data/MetroGraphSource.ts b/src/data/MetroGraphSource.ts index 3d38351..3d7c291 100644 --- a/src/data/MetroGraphSource.ts +++ b/src/data/MetroGraphSource.ts @@ -178,10 +178,13 @@ export function convertModule( path: module.path, package: getPackageNameFromPath(module.path), size: module.output.reduce((bytes, output) => bytes + Buffer.byteLength(output.data.code), 0), - imports: Array.from(module.dependencies.values()).map((module) => module.absolutePath), - importedBy: Array.from(module.inverseDependencies).filter((dependecy) => - options.graph.dependencies.has(dependecy) - ), + imports: Array.from(module.dependencies.values()).map((module) => ({ + path: module.absolutePath, + package: getPackageNameFromPath(module.absolutePath), + })), + importedBy: Array.from(module.inverseDependencies) + .filter((path) => options.graph.dependencies.has(path)) + .map((path) => ({ path, package: getPackageNameFromPath(path) })), source: getModuleSourceContent(options, module), output: module.output.map((output) => ({ type: output.type, diff --git a/src/data/types.ts b/src/data/types.ts index 9ef917b..fb68b01 100644 --- a/src/data/types.ts +++ b/src/data/types.ts @@ -54,11 +54,13 @@ export type AtlasModule = { /** The original module size, in bytes */ size: number; /** Absolute file paths of modules imported inside this module */ - imports: string[]; - /** Absolute file paths of modules importing this module */ - importedBy: string[]; + imports: AtlasModuleRef[]; + /** All modules importing this module */ + importedBy: AtlasModuleRef[]; /** The original source code, as a buffer or string */ source?: string; /** The transformed output source code */ output?: MixedOutput[]; }; + +export type AtlasModuleRef = Pick;