diff --git a/packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.js.snap b/packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.js.snap index 3a9a00fb3947b..046eb857acd58 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.js.snap +++ b/packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.js.snap @@ -87,7 +87,7 @@ Array [ }, Object { "browserAPIs": Array [], - "id": "d5fb39bc-5b13-5925-86de-f0e18549d272", + "id": "cc2293db-7635-5675-bb5e-05c41ff28688", "name": "gatsby-plugin-page-creator", "nodeAPIs": Array [ "createPagesStatefully", @@ -179,6 +179,7 @@ Array [ }, Object { "browserAPIs": Array [], + "id": "c731052f-1e62-5905-9fb3-edc9057be8f1", "name": "TEST", "nodeAPIs": Array [], "pluginOptions": Object { @@ -202,7 +203,7 @@ Array [ }, Object { "browserAPIs": Array [], - "id": "d5fb39bc-5b13-5925-86de-f0e18549d272", + "id": "cc2293db-7635-5675-bb5e-05c41ff28688", "name": "gatsby-plugin-page-creator", "nodeAPIs": Array [ "createPagesStatefully", diff --git a/packages/gatsby/src/bootstrap/load-plugins/load.js b/packages/gatsby/src/bootstrap/load-plugins/load.js index c220b5bdc7d8b..6d52861c6f073 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/load.js +++ b/packages/gatsby/src/bootstrap/load-plugins/load.js @@ -19,6 +19,19 @@ function createFileContentHash(root, globPattern) { return hash.digest(`hex`) } +/** + * Make sure key is unique to plugin options. E.g there could + * be multiple source-filesystem plugins, with different names + * (docs, blogs). + * @param {*} name Name of the plugin + * @param {*} pluginObject + */ +const createPluginId = (name, pluginObject = null) => + createNodeId( + name + (pluginObject ? JSON.stringify(pluginObject.options) : ``), + `Plugin` + ) + /** * @typedef {Object} PluginInfo * @property {string} resolve The absolute path to the plugin @@ -49,7 +62,7 @@ function resolvePlugin(pluginName) { return { resolve: resolvedPath, name, - id: createNodeId(name, `Plugin`), + id: createPluginId(name), version: packageJSON.version || createFileContentHash(resolvedPath, `**`), } @@ -73,7 +86,7 @@ function resolvePlugin(pluginName) { return { resolve: resolvedPath, - id: createNodeId(packageJSON.name, `Plugin`), + id: createPluginId(packageJSON.name), name: packageJSON.name, version: packageJSON.version, } @@ -102,9 +115,11 @@ module.exports = (config = {}) => { }, } } else { + plugin.options = plugin.options || {} + // Plugins can have plugins. const subplugins = [] - if (plugin.options && plugin.options.plugins) { + if (plugin.options.plugins) { plugin.options.plugins.forEach(p => { subplugins.push(processPlugin(p)) }) @@ -115,8 +130,11 @@ module.exports = (config = {}) => { // Add some default values for tests as we don't actually // want to try to load anything during tests. if (plugin.resolve === `___TEST___`) { + const name = `TEST` + return { - name: `TEST`, + id: createPluginId(name, plugin), + name, pluginOptions: { plugins: [], }, @@ -127,15 +145,7 @@ module.exports = (config = {}) => { return { ...info, - // Make sure key is unique to plugin options. E.g there could - // be multiple source-filesystem plugins, with different names - // (docs, blogs). - id: createNodeId( - plugin.options - ? plugin.name + JSON.stringify(plugin.options) - : plugin.name, - `Plugin` - ), + id: createPluginId(info.name, plugin), pluginOptions: _.merge({ plugins: [] }, plugin.options), } } @@ -164,7 +174,7 @@ module.exports = (config = {}) => { // Add the site's default "plugin" i.e. gatsby-x files in root of site. plugins.push({ resolve: slash(process.cwd()), - id: createNodeId(`default-site-plugin`, `Plugin`), + id: createPluginId(`default-site-plugin`), name: `default-site-plugin`, version: createFileContentHash(process.cwd(), `gatsby-*`), pluginOptions: {