diff --git a/packages/gatsby/src/bootstrap/load-plugins/load.ts b/packages/gatsby/src/bootstrap/load-plugins/load.ts index 10a3ae0ad7d5c..4204b6bd1c21c 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/load.ts +++ b/packages/gatsby/src/bootstrap/load-plugins/load.ts @@ -47,17 +47,25 @@ const createPluginId = ( ) /** - * @param pluginName - * This can be a name of a local plugin, the name of a plugin located in - * node_modules, or a Gatsby internal plugin. In the last case the pluginName - * will be an absolute path. + * @param plugin + * This should be a plugin spec object where possible but can also be the + * name of a plugin. + * + * When it is a name, it can be a name of a local plugin, the name of a plugin + * located in node_modules, or a Gatsby internal plugin. In the last case the + * plugin will be an absolute path. * @param rootDir * This is the project location, from which are found the plugins */ export function resolvePlugin( - pluginName: string, + plugin: PluginRef, rootDir: string | null ): IPluginInfo { + const pluginName = _.isString(plugin) ? plugin : plugin.resolve + + // Respect the directory that the plugin was sourced from initially + rootDir = (!_.isString(plugin) && plugin.parentDir) || rootDir + // Only find plugins when we're not given an absolute path if (!existsSync(pluginName)) { // Find the plugin in the local plugins folder @@ -192,7 +200,7 @@ export function loadPlugins( } } - const info = resolvePlugin(plugin.resolve, plugin.parentDir || rootDir) + const info = resolvePlugin(plugin, rootDir) return { ...info, diff --git a/packages/gatsby/src/bootstrap/load-plugins/validate.ts b/packages/gatsby/src/bootstrap/load-plugins/validate.ts index 4f0ee893a0cbb..37e6c05ecca5d 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/validate.ts +++ b/packages/gatsby/src/bootstrap/load-plugins/validate.ts @@ -189,7 +189,7 @@ async function validatePluginsOptions( plugins.map(async plugin => { let gatsbyNode try { - const resolvedPlugin = resolvePlugin(plugin.resolve, rootDir) + const resolvedPlugin = resolvePlugin(plugin, rootDir) gatsbyNode = require(`${resolvedPlugin.resolve}/gatsby-node`) } catch (err) { gatsbyNode = {}