Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/gatsby/src/bootstrap/load-plugins/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -192,7 +200,7 @@ export function loadPlugins(
}
}

const info = resolvePlugin(plugin.resolve, plugin.parentDir || rootDir)
const info = resolvePlugin(plugin, rootDir)

return {
...info,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/bootstrap/load-plugins/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down