@@ -7,8 +7,6 @@ import { createRequire } from "node:module";
77
88import { chalk , prettyPath } from "@react-native-node-api/cli-utils" ;
99
10- import { findDuplicates } from "./duplicates" ;
11-
1210// TODO: Change to .apple.node
1311export const PLATFORMS = [ "android" , "apple" ] as const ;
1412export type PlatformName = "android" | "apple" ;
@@ -267,32 +265,33 @@ export function resolvePackageRoot(
267265 }
268266}
269267
270- export function logModulePaths (
271- modulePaths : string [ ] ,
272- // TODO: Default to iterating and printing for all supported naming strategies
273- naming : NamingStrategy ,
274- ) {
275- const pathsPerName = new Map < string , string [ ] > ( ) ;
268+ /**
269+ * Module paths per library name.
270+ */
271+ export type LibraryMap = Map < string , string [ ] > ;
272+
273+ export function getLibraryMap ( modulePaths : string [ ] , naming : NamingStrategy ) {
274+ const result = new Map < string , string [ ] > ( ) ;
276275 for ( const modulePath of modulePaths ) {
277276 const libraryName = getLibraryName ( modulePath , naming ) ;
278- const existingPaths = pathsPerName . get ( libraryName ) ?? [ ] ;
277+ const existingPaths = result . get ( libraryName ) ?? [ ] ;
279278 existingPaths . push ( modulePath ) ;
280- pathsPerName . set ( libraryName , existingPaths ) ;
279+ result . set ( libraryName , existingPaths ) ;
281280 }
281+ return result ;
282+ }
282283
283- const allModulePaths = modulePaths . map ( ( modulePath ) => modulePath ) ;
284- const duplicatePaths = findDuplicates ( allModulePaths ) ;
285- for ( const [ libraryName , modulePaths ] of pathsPerName ) {
286- console . log (
284+ export function visualizeLibraryMap ( libraryMap : LibraryMap ) {
285+ const result = [ ] ;
286+ for ( const [ libraryName , modulePaths ] of libraryMap ) {
287+ result . push (
287288 chalk . greenBright ( `${ libraryName } ` ) ,
288289 ...modulePaths . flatMap ( ( modulePath ) => {
289- const line = duplicatePaths . has ( modulePath )
290- ? chalk . redBright ( prettyPath ( modulePath ) )
291- : prettyPath ( modulePath ) ;
292- return `\n ↳ ${ line } ` ;
290+ return ` ↳ ${ prettyPath ( modulePath ) } ` ;
293291 } ) ,
294292 ) ;
295293 }
294+ return result . join ( "\n" ) ;
296295}
297296
298297/**
0 commit comments