Skip to content

Commit

Permalink
feature: add AtlasModuleRef type for module.imports and `module.i…
Browse files Browse the repository at this point in the history
…mportedBy`
  • Loading branch information
byCedric committed Apr 23, 2024
1 parent fe29c38 commit 9bb29dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/data/MetroGraphSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions src/data/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AtlasModule, 'path' | 'package'>;

0 comments on commit 9bb29dc

Please sign in to comment.