diff --git a/index.js b/index.js index 3285f5a9..25804a23 100644 --- a/index.js +++ b/index.js @@ -23,12 +23,15 @@ const fastifyAutoload = async function autoload (fastify, options) { } async function loadPlugins ({ pluginTree, options, opts, fastify }) { + const nodes = [] + const pluginsMeta = {} for (const key in pluginTree) { const node = { ...pluginTree[key], - pluginsMeta: {}, + pluginsMeta, hooksMeta: {} } + nodes.push(node) await Promise.all(node.plugins.map(({ file, type, prefix }) => { return loadPlugin({ file, type, directoryPrefix: prefix, options: opts, log: fastify.log }) @@ -55,7 +58,9 @@ async function loadPlugins ({ pluginTree, options, opts, fastify }) { throw enrichError(err) }) })) + } + for (const node of nodes) { registerNode(node, fastify) } } diff --git a/test/commonjs/dependency/plugins/plugin-d.js b/test/commonjs/dependency/plugins/deep/plugin-d.js similarity index 100% rename from test/commonjs/dependency/plugins/plugin-d.js rename to test/commonjs/dependency/plugins/deep/plugin-d.js