@@ -5,21 +5,28 @@ import * as registries from "./module-registries.ts";
5
5
6
6
export class ModuleMap {
7
7
modules = new Map < string , CodeModule > ( ) ;
8
- mainModule : CodeModule | null = null ;
9
- mainFile : string | null = null ;
8
+ mainModule : CodeModule ;
9
+ registryOpts : registries . RegistryOpts ;
10
10
11
11
constructor (
12
12
public args : URLSearchParams ,
13
13
public redirects : Record < string , string > ,
14
+ public rootNode : DenoModule ,
14
15
) {
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 ) ;
16
24
}
17
- isolateStd : boolean ;
18
25
19
26
grabModFor ( url : string , fragment : string = '' ) {
20
27
const wireUrl = url . split ( '#' ) [ 0 ] ;
21
28
const actualUrl = this . redirects [ wireUrl ] || wireUrl ;
22
- const base = registries . determineModuleBase ( actualUrl , this . isolateStd ) ;
29
+ const base = registries . determineModuleBase ( actualUrl , this . registryOpts ) ;
23
30
let moduleInfo = this . modules . get ( base + fragment ) ;
24
31
if ( ! moduleInfo ) {
25
32
moduleInfo = {
@@ -79,7 +86,7 @@ export class ModuleMap {
79
86
for ( const module of this . modules . values ( ) ) {
80
87
modules [ module . base + module . fragment ] = {
81
88
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 ) ,
83
90
totalSize : module . totalSize ,
84
91
fileCount : module . files . length ,
85
92
errors : module . errors ,
@@ -96,7 +103,7 @@ export class ModuleMap {
96
103
for ( const module of this . modules . values ( ) ) {
97
104
// console.log(module.base, Array.from(module.deps.values()).map(x => x.base));
98
105
99
- const labels = registries . determineModuleLabel ( module , this . isolateStd ) ;
106
+ const labels = registries . determineModuleLabel ( module , this . registryOpts ) ;
100
107
if ( module . errors ) {
101
108
labels . unshift ( `${ module . errors . length } FAILED IMPORTS FROM:` ) ;
102
109
for ( const err of module . errors ) {
@@ -171,17 +178,13 @@ export class ModuleMap {
171
178
}
172
179
173
180
export function processDenoInfo ( data : DenoInfo , args ?: URLSearchParams ) {
174
- const map = new ModuleMap ( args ?? new URLSearchParams , data . redirects ) ;
175
-
176
181
// TODO: when are there multiple roots?
177
182
const roots = data . roots . map ( x => data . redirects [ x ] || x ) ;
178
183
const rootNode = data . modules . find ( x => roots . includes ( x . specifier ) ) ;
179
184
if ( ! rootNode ) throw new Error (
180
185
`I didn't find a root node in the Deno graph! This is a module-visualizer bug.` ) ;
181
186
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 ) ;
185
188
for ( const info of data . modules ) {
186
189
map . addFile ( info . specifier , info , data ) ;
187
190
}
0 commit comments