MCPcopy
hub / github.com/ember-cli/ember-cli / getHostAddonInfo

Method getHostAddonInfo

lib/models/host-info-cache.js:196–268  ·  view source on GitHub ↗

* This function intends to return a common host for a bundle host (lazy engine). The root * package info should be the starting point (i.e., the project's package info). We do this * by performing a breadth-first traversal until we find the intended lazy engine (represented * as a package-i

(packageInfoForLazyEngine)

Source from the content-addressed store, hash-verified

194 * @return {{ hostPackageInfo: PackageInfo, hostAndAncestorBundledPackageInfos: Set<PackageInfo> }}
195 */
196 getHostAddonInfo(packageInfoForLazyEngine) {
197 const cacheKey = `${this.project._packageInfo.realPath}-${packageInfoForLazyEngine.realPath}`;
198
199 let hostInfoCacheEntry = this._hostAddonInfoCache.get(cacheKey);
200
201 if (hostInfoCacheEntry) {
202 return hostInfoCacheEntry;
203 }
204
205 if (!packageInfoForLazyEngine.isForEngine()) {
206 throw new Error(
207 `[ember-cli] \`${packageInfoForLazyEngine.name}\` is not an engine; \`getHostAddonInfo\` should only be used to find host information about engines`
208 );
209 }
210
211 const queue = [{ pkgInfo: this.project._packageInfo, path: [] }];
212 const visited = new Set();
213 const foundPaths = [];
214
215 while (queue.length) {
216 const { pkgInfo: currentPackageInfo, path } = queue.shift();
217
218 const {
219 addonMainPath,
220 inRepoAddons = [],
221 dependencyPackages = {},
222 devDependencyPackages = {},
223 } = currentPackageInfo;
224
225 const isCurrentPackageInfoProject = this.project._packageInfo === currentPackageInfo;
226
227 // don't process non-ember addons
228 if (!isCurrentPackageInfoProject && typeof addonMainPath !== 'string') {
229 continue;
230 }
231
232 // store found paths
233 if (currentPackageInfo === packageInfoForLazyEngine) {
234 foundPaths.push([...path]);
235 }
236
237 // don't process a given `PackageInfo` object more than once
238 if (!visited.has(currentPackageInfo)) {
239 visited.add(currentPackageInfo);
240
241 // add current package info to current path
242 path.push(currentPackageInfo);
243
244 queue.push(
245 ...[...inRepoAddons, ...Object.values(dependencyPackages), ...Object.values(devDependencyPackages)].map(
246 (pkgInfo) => ({ pkgInfo, path: [...path] })
247 )
248 );
249 }
250 }
251
252 const [hostPackageInfo, foundPath] = this._findNearestBundleHost(foundPaths, packageInfoForLazyEngine);
253

Callers 4

findLCAHostMethod · 0.95
findBundleOwnerMethod · 0.80

Calls 7

getMethod · 0.80
isForEngineMethod · 0.80
filterMethod · 0.80
isForBundleHostMethod · 0.80
hasMethod · 0.45

Tested by

no test coverage detected