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

Function instantiateAddons

lib/models/instantiate-addons.js:25–95  ·  view source on GitHub ↗

* Create instances of a set of "child" addons for a parent addon or project. * * @method instantiateAddons * @param {Object} parent an Addon or Project that is the direct containing object of the list * of children defined in addonPackages. * @param {Project} project the project that contains

(parent, project, addonPackages)

Source from the content-addressed store, hash-verified

23 * 'pkg' object for that addon's package.json). These are what is turned into addons.
24 */
25function instantiateAddons(parent, project, addonPackages) {
26 // depending on whether this is really a project or an addon, the 'name' property may be a getter.
27 let parentName = typeof parent.name === 'function' ? parent.name() : parent.name;
28
29 logger.info('instantiateAddons for: ', parentName);
30
31 let addonNames = Object.keys(addonPackages || {});
32
33 if (addonNames.length === 0) {
34 logger.info(' no addons');
35 return [];
36 } else {
37 logger.info(' addon names are:', addonNames);
38 }
39
40 let initializeAddonsToken = heimdall.start(`${parentName}: initializeAddons`);
41 let graph = new DAGMap();
42 let addonInfo, emberAddonConfig;
43
44 addonNames.forEach((name) => {
45 addonInfo = addonPackages[name];
46 emberAddonConfig = addonInfo.pkg['ember-addon'];
47
48 graph.add(name, addonInfo, emberAddonConfig.before, emberAddonConfig.after);
49 });
50
51 let addons = [];
52 let timings = new Map();
53
54 graph.each((key, value) => {
55 let addonInfo = value;
56 if (addonInfo) {
57 let initializeAddonToken = heimdall.start({
58 name: `initialize ${addonInfo.name}`,
59 addonName: addonInfo.name,
60 addonInitializationNode: true,
61 });
62
63 let start = Date.now();
64
65 let pkgInfo = parent.packageInfoCache.getEntry(addonInfo.path);
66
67 if (!pkgInfo || !pkgInfo.valid) {
68 throw new SilentError(
69 `The \`${addonInfo.pkg.name}\` addon could not be found at \`${addonInfo.path}\` or was otherwise invalid.`
70 );
71 }
72
73 // get an instance of the addon. If that fails it will throw.
74 let addon = pkgInfo.getAddonInstance(parent, project);
75
76 timings.set(addon, Date.now() - start);
77
78 initializeAddonToken.stop();
79
80 addons.push(addon);
81 }
82 });

Callers 2

initializeAddonsMethod · 0.85
initializeAddonsFunction · 0.85

Calls 5

getEntryMethod · 0.80
getMethod · 0.80
nameMethod · 0.45
startMethod · 0.45
getAddonInstanceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…