@@ -5,21 +5,28 @@ import * as registries from "./module-registries.ts";
55
66export class ModuleMap {
77 modules = new Map < string , CodeModule > ( ) ;
8- mainModule : CodeModule | null = null ;
9- mainFile : string | null = null ;
8+ mainModule : CodeModule ;
9+ registryOpts : registries . RegistryOpts ;
1010
1111 constructor (
1212 public args : URLSearchParams ,
1313 public redirects : Record < string , string > ,
14+ public rootNode : DenoModule ,
1415 ) {
15- this . isolateStd = this . args . get ( 'std' ) === 'isolate' ;
16+ this . registryOpts = {
17+ mainModule : rootNode . specifier ,
18+ isolateStd : this . args . get ( 'std' ) === 'isolate' ,
19+ }
20+
21+ this . mainModule = this . grabModFor (
22+ rootNode . specifier ,
23+ rootNode . error ? '#error' : undefined ) ;
1624 }
17- isolateStd : boolean ;
1825
1926 grabModFor ( url : string , fragment : string = '' ) {
2027 const wireUrl = url . split ( '#' ) [ 0 ] ;
2128 const actualUrl = this . redirects [ wireUrl ] || wireUrl ;
22- const base = registries . determineModuleBase ( actualUrl , this . isolateStd ) ;
29+ const base = registries . determineModuleBase ( actualUrl , this . registryOpts ) ;
2330 let moduleInfo = this . modules . get ( base + fragment ) ;
2431 if ( ! moduleInfo ) {
2532 moduleInfo = {
@@ -79,7 +86,7 @@ export class ModuleMap {
7986 for ( const module of this . modules . values ( ) ) {
8087 modules [ module . base + module . fragment ] = {
8188 moduleDeps : Array . from ( module . deps ) . map ( x => x . base + x . fragment ) ,
82- labelText : registries . determineModuleLabel ( module , this . isolateStd ) ,
89+ labelText : registries . determineModuleLabel ( module , this . registryOpts ) ,
8390 totalSize : module . totalSize ,
8491 fileCount : module . files . length ,
8592 errors : module . errors ,
@@ -96,7 +103,7 @@ export class ModuleMap {
96103 for ( const module of this . modules . values ( ) ) {
97104 // console.log(module.base, Array.from(module.deps.values()).map(x => x.base));
98105
99- const labels = registries . determineModuleLabel ( module , this . isolateStd ) ;
106+ const labels = registries . determineModuleLabel ( module , this . registryOpts ) ;
100107 if ( module . errors ) {
101108 labels . unshift ( `${ module . errors . length } FAILED IMPORTS FROM:` ) ;
102109 for ( const err of module . errors ) {
@@ -171,17 +178,13 @@ export class ModuleMap {
171178}
172179
173180export function processDenoInfo ( data : DenoInfo , args ?: URLSearchParams ) {
174- const map = new ModuleMap ( args ?? new URLSearchParams , data . redirects ) ;
175-
176181 // TODO: when are there multiple roots?
177182 const roots = data . roots . map ( x => data . redirects [ x ] || x ) ;
178183 const rootNode = data . modules . find ( x => roots . includes ( x . specifier ) ) ;
179184 if ( ! rootNode ) throw new Error (
180185 `I didn't find a root node in the Deno graph! This is a module-visualizer bug.` ) ;
181186
182- map . mainModule = map . grabModFor ( rootNode . specifier , rootNode . error ? '#error' : undefined ) ;
183- map . mainFile = rootNode . specifier ;
184-
187+ const map = new ModuleMap ( args ?? new URLSearchParams , data . redirects , rootNode ) ;
185188 for ( const info of data . modules ) {
186189 map . addFile ( info . specifier , info , data ) ;
187190 }
0 commit comments