Skip to content

Commit 3260b1a

Browse files
authoredSep 7, 2021
feat(gatsby-transformer-remark): use subplugin annotation to use automatic subplugin module loading (#33039)
1 parent 9b40fc4 commit 3260b1a

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed
 

‎packages/gatsby-transformer-remark/src/create-schema-customization.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ module.exports = (nodeApiArgs, pluginOptions = {}) => {
4040
// to customize the GraphQL schema. This makes it possible for subplugins to
4141
// modify types owned by `gatsby-transformer-remark`.
4242
plugins.forEach(plugin => {
43-
const resolvedPlugin = require(plugin.resolve)
43+
const resolvedPlugin =
44+
_CFLAGS_.GATSBY_MAJOR === `4` ? plugin.module : require(plugin.resolve)
45+
4446
if (typeof resolvedPlugin.createSchemaCustomization === `function`) {
4547
resolvedPlugin.createSchemaCustomization(
4648
nodeApiArgs,

‎packages/gatsby-transformer-remark/src/extend-node-type.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ module.exports = function remarkExtendNodeType(
123123
}
124124

125125
for (const plugin of pluginOptions.plugins) {
126-
const requiredPlugin = require(plugin.resolve)
126+
const requiredPlugin =
127+
_CFLAGS_.GATSBY_MAJOR === `4` ? plugin.module : require(plugin.resolve)
127128
if (_.isFunction(requiredPlugin.setParserPlugins)) {
128129
for (const parserPlugin of requiredPlugin.setParserPlugins(
129130
plugin.pluginOptions
@@ -201,7 +202,10 @@ module.exports = function remarkExtendNodeType(
201202
}
202203
// Use a for loop to run remark plugins serially.
203204
for (const plugin of pluginOptions.plugins) {
204-
const requiredPlugin = require(plugin.resolve)
205+
const requiredPlugin =
206+
_CFLAGS_.GATSBY_MAJOR === `4`
207+
? plugin.module
208+
: require(plugin.resolve)
205209
// Allow both exports = function(), and exports.default = function()
206210
const defaultFunction = _.isFunction(requiredPlugin)
207211
? requiredPlugin
@@ -242,7 +246,10 @@ module.exports = function remarkExtendNodeType(
242246
//
243247
// Use for loop to run remark plugins serially.
244248
for (const plugin of pluginOptions.plugins) {
245-
const requiredPlugin = require(plugin.resolve)
249+
const requiredPlugin =
250+
_CFLAGS_.GATSBY_MAJOR === `4`
251+
? plugin.module
252+
: require(plugin.resolve)
246253
if (typeof requiredPlugin.mutateSource === `function`) {
247254
await requiredPlugin.mutateSource(
248255
{

‎packages/gatsby-transformer-remark/src/gatsby-node.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@ exports.pluginOptionsSchema = function ({ Joi }) {
2222
excerpt_separator: Joi.string().description(
2323
`If your Markdown file contains HTML, excerpt will not return a value. In that case, you can set an excerpt_separator to an HTML tag. Edit your Markdown files to include that HTML tag after the text you’d like to appear in the excerpt.`
2424
),
25-
plugins: Joi.array()
26-
.items(
27-
Joi.string(),
28-
Joi.object({
29-
resolve: Joi.string(),
30-
options: Joi.object({}).unknown(true),
31-
})
32-
)
33-
.description(
34-
`A list of remark plugins. See also: https://github.com/gatsbyjs/gatsby/tree/master/examples/using-remark for examples`
35-
),
25+
plugins:
26+
_CFLAGS_.GATSBY_MAJOR === `4`
27+
? Joi.subPlugins({ entry: `index` }).description(
28+
`A list of remark plugins. See also: https://github.com/gatsbyjs/gatsby/tree/master/examples/using-remark for examples`
29+
)
30+
: Joi.array()
31+
.items(
32+
Joi.string(),
33+
Joi.object({
34+
resolve: Joi.string(),
35+
options: Joi.object({}).unknown(true),
36+
})
37+
)
38+
.default([])
39+
.description(
40+
`A list of remark plugins. See also: https://github.com/gatsbyjs/gatsby/tree/master/examples/using-remark for examples`
41+
),
3642
})
3743
}

0 commit comments

Comments
 (0)
Please sign in to comment.