Skip to content

Commit 9b5e005

Browse files
authored
handle plugin parentDir resolution in resolvePlugin() (#30812)
1 parent e351588 commit 9b5e005

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/gatsby/src/bootstrap/load-plugins/load.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,25 @@ const createPluginId = (
4747
)
4848

4949
/**
50-
* @param pluginName
51-
* This can be a name of a local plugin, the name of a plugin located in
52-
* node_modules, or a Gatsby internal plugin. In the last case the pluginName
53-
* will be an absolute path.
50+
* @param plugin
51+
* This should be a plugin spec object where possible but can also be the
52+
* name of a plugin.
53+
*
54+
* When it is a name, it can be a name of a local plugin, the name of a plugin
55+
* located in node_modules, or a Gatsby internal plugin. In the last case the
56+
* plugin will be an absolute path.
5457
* @param rootDir
5558
* This is the project location, from which are found the plugins
5659
*/
5760
export function resolvePlugin(
58-
pluginName: string,
61+
plugin: PluginRef,
5962
rootDir: string | null
6063
): IPluginInfo {
64+
const pluginName = _.isString(plugin) ? plugin : plugin.resolve
65+
66+
// Respect the directory that the plugin was sourced from initially
67+
rootDir = (!_.isString(plugin) && plugin.parentDir) || rootDir
68+
6169
// Only find plugins when we're not given an absolute path
6270
if (!existsSync(pluginName)) {
6371
// Find the plugin in the local plugins folder
@@ -192,7 +200,7 @@ export function loadPlugins(
192200
}
193201
}
194202

195-
const info = resolvePlugin(plugin.resolve, plugin.parentDir || rootDir)
203+
const info = resolvePlugin(plugin, rootDir)
196204

197205
return {
198206
...info,

packages/gatsby/src/bootstrap/load-plugins/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ async function validatePluginsOptions(
189189
plugins.map(async plugin => {
190190
let gatsbyNode
191191
try {
192-
const resolvedPlugin = resolvePlugin(plugin.resolve, rootDir)
192+
const resolvedPlugin = resolvePlugin(plugin, rootDir)
193193
gatsbyNode = require(`${resolvedPlugin.resolve}/gatsby-node`)
194194
} catch (err) {
195195
gatsbyNode = {}

0 commit comments

Comments
 (0)