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

Method findLCAHost

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

* This returns the LCA host for a given engine; we use the associated package info * to compute this (see `getHostAddonInfo` above); this finds the lowest common ancestor * that is considered a host amongst _all_ engines by the same name in the project. This * function is intended to replac

(engineInstance)

Source from the content-addressed store, hash-verified

282 * @return {EngineAddon|EmberApp}
283 */
284 findLCAHost(engineInstance) {
285 // only compute once for a given engine
286 // we're using the engine name as the cache key here because regardless of its
287 // version, lazy engines will always get output to: `engines-dist/${engineName}`
288 let lcaHost = this._lcaHostCache.get(engineInstance.name);
289
290 if (lcaHost) {
291 return lcaHost;
292 }
293
294 if (!engineInstance._packageInfo.isForEngine()) {
295 throw new Error(
296 `[ember-cli] \`findLCAHost\` should only be used for engines; \`${engineInstance.name}\` is not an engine`
297 );
298 }
299
300 const { hostPackageInfo } = this.getHostAddonInfo(engineInstance._packageInfo);
301
302 let curr = engineInstance;
303
304 while (curr && curr.parent) {
305 if (curr.app) {
306 lcaHost = curr.app;
307 break;
308 }
309
310 if (curr._packageInfo === hostPackageInfo) {
311 lcaHost = curr;
312 break;
313 }
314
315 curr = curr.parent;
316 }
317
318 if (lcaHost) {
319 this._lcaHostCache.set(engineInstance.name, lcaHost);
320 return lcaHost;
321 }
322
323 // this should _never_ be triggered
324 throw new Error(
325 `[ember-cli] Could not find an LCA host for: \`${engineInstance.name}\` (located at \`${
326 engineInstance.packageRoot || engineInstance.root
327 }\`)`
328 );
329 }
330}
331
332module.exports = HostInfoCache;

Callers 1

Calls 3

getHostAddonInfoMethod · 0.95
getMethod · 0.80
isForEngineMethod · 0.80

Tested by

no test coverage detected