MCPcopy Index your code
hub / github.com/ember-cli/ember-cli / _findNearestBundleHost

Method _findNearestBundleHost

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

* Given a path (calculated as part of `getHostAddonInfo`), return the correct * "bundle host". A bundle host is considered the project or lazy engine. * * For example, given the following package structure: * * --Project-- * / \ * / \ * Lazy Engine

(paths, pkgInfoForLazyEngine)

Source from the content-addressed store, hash-verified

62 * @private
63 */
64 _findNearestBundleHost(paths, pkgInfoForLazyEngine) {
65 // building an engine in isolation (it's considered the project, but it's
66 // also added as a dependency to the project by `ember-cli`)
67 if (this.project._packageInfo === pkgInfoForLazyEngine) {
68 return [this.project._packageInfo, [this.project._packageInfo]];
69 }
70
71 const shortestPath = paths.reduce(
72 (acc, pathToLazyEngine) => Math.min(acc, pathToLazyEngine.length),
73 Number.POSITIVE_INFINITY
74 );
75
76 const pathsEqualToShortest = paths.filter((pathToLazyEngine) => pathToLazyEngine.length === shortestPath);
77 const [firstPath] = pathsEqualToShortest;
78
79 for (let i = firstPath.length - 1; i >= 0; i--) {
80 const pkgInfo = firstPath[i];
81
82 if (pkgInfo.isForBundleHost() && allPkgInfosEqualAtIndex(pathsEqualToShortest, i)) {
83 return [pkgInfo, firstPath.slice(0, i + 1)];
84 }
85 }
86
87 // this should _never_ be triggered
88 throw new Error(
89 `[ember-cli] Could not find a common host for: \`${pkgInfoForLazyEngine.name}\` (located at \`${pkgInfoForLazyEngine.realPath}\`)`
90 );
91 }
92
93 /**
94 * Returns a `Set` of package-info objects that a given bundle host is

Callers 1

getHostAddonInfoMethod · 0.95

Calls 3

allPkgInfosEqualAtIndexFunction · 0.85
filterMethod · 0.80
isForBundleHostMethod · 0.80

Tested by

no test coverage detected