(loadQueue, skip)
| 101 | }; |
| 102 | |
| 103 | function createGraphHelpers(loadQueue, skip) { |
| 104 | const modules = new Map([[null, createParentModule()]]); |
| 105 | |
| 106 | function collect( |
| 107 | path = null, |
| 108 | serialized = {entryModules: [], modules: []}, |
| 109 | seen = new Set(), |
| 110 | ) { |
| 111 | const module = modules.get(path); |
| 112 | if (module == null || seen.has(path)) { |
| 113 | return serialized; |
| 114 | } |
| 115 | |
| 116 | const {dependencies} = module; |
| 117 | if (path === null) { |
| 118 | serialized.entryModules = |
| 119 | dependencies.map(dep => nullthrows(modules.get(dep.path))); |
| 120 | } else { |
| 121 | serialized.modules.push(module); |
| 122 | seen.add(path); |
| 123 | } |
| 124 | |
| 125 | for (const dependency of dependencies) { |
| 126 | collect(dependency.path, serialized, seen); |
| 127 | } |
| 128 | |
| 129 | return serialized; |
| 130 | } |
| 131 | |
| 132 | function loadModule(id, parent, parentDepIndex) { |
| 133 | loadQueue.push( |
| 134 | {id, parent}, |
| 135 | (error, file, dependencyIDs) => |
| 136 | onFileLoaded(error, file, dependencyIDs, id, parent, parentDepIndex), |
| 137 | ); |
| 138 | } |
| 139 | |
| 140 | function onFileLoaded( |
| 141 | error, |
| 142 | file, |
| 143 | dependencyIDs, |
| 144 | id, |
| 145 | parent, |
| 146 | parentDependencyIndex, |
| 147 | ) { |
| 148 | if (error) { |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | const {path} = nullthrows(file); |
| 153 | dependencyIDs = nullthrows(dependencyIDs); |
| 154 | |
| 155 | const parentModule = modules.get(parent); |
| 156 | invariant(parentModule, 'Invalid parent module: ' + String(parent)); |
| 157 | parentModule.dependencies[parentDependencyIndex] = {id, path}; |
| 158 | |
| 159 | if ((!skip || !skip.has(path)) && !modules.has(path)) { |
| 160 | const module = { |
no test coverage detected
searching dependent graphs…