Skip to content

Commit 300d331

Browse files
piehsidharthachatterjee
authored andcommitted
fix(themes): normalize plugin entries before merging plugin ar… (#15307)
1 parent 188da93 commit 300d331

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

packages/gatsby/src/utils/merge-gatsby-config.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ module.exports = (a, b) => {
2525
// return the fully merged config
2626
return mergedConfig
2727
}
28+
29+
/**
30+
* Normalize plugin spec before comparing so
31+
* - `gatsby-plugin-name`
32+
* - { resolve: `gatsby-plugin-name` }
33+
* - { resolve: `gatsby-plugin-name`, options: {} }
34+
* are all considered equal
35+
*/
36+
const normalizePluginEntry = entry =>
37+
_.isString(entry)
38+
? { resolve: entry, options: {} }
39+
: _.isObject(entry)
40+
? { options: {}, ...entry }
41+
: entry
42+
2843
const howToMerge = {
2944
/**
3045
* pick a truthy value by default.
@@ -34,6 +49,9 @@ const howToMerge = {
3449
byDefault: (a, b) => b || a,
3550
siteMetadata: (objA, objB) => _.merge({}, objA, objB),
3651
// plugins are concatenated and uniq'd, so we don't get two of the same plugin value
37-
plugins: (a = [], b = []) => _.uniqWith(a.concat(b), _.isEqual),
52+
plugins: (a = [], b = []) =>
53+
_.uniqWith(a.concat(b), (a, b) =>
54+
_.isEqual(normalizePluginEntry(a), normalizePluginEntry(b))
55+
),
3856
mapping: (objA, objB) => _.merge({}, objA, objB),
3957
}

0 commit comments

Comments
 (0)