Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): Allow overriding options for default instance of gatsby-plugin-page-creator #17420

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -427,3 +427,239 @@ Array [
},
]
`;

exports[`Load plugins Overrides the options for gatsby-plugin-page-creator 1`] = `
Array [
Object {
"browserAPIs": Array [],
"id": "",
"name": "dev-404-page",
"nodeAPIs": Array [
"createPagesStatefully",
],
"pluginOptions": Object {
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "load-babel-config",
"nodeAPIs": Array [
"onPreBootstrap",
],
"pluginOptions": Object {
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "internal-data-bridge",
"nodeAPIs": Array [
"sourceNodes",
"onCreatePage",
],
"pluginOptions": Object {
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "prod-404",
"nodeAPIs": Array [
"onCreatePage",
],
"pluginOptions": Object {
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "webpack-theme-component-shadowing",
"nodeAPIs": Array [
"onCreateWebpackConfig",
],
"pluginOptions": Object {
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "gatsby-plugin-page-creator",
"nodeAPIs": Array [
"createPagesStatefully",
],
"pluginOptions": Object {
"ignore": Array [
"___Test___.(js|ts)?(x)",
],
"path": "___TEST___/src/pages",
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "default-site-plugin",
"nodeAPIs": Array [],
"pluginOptions": Object {
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "gatsby-plugin-page-creator",
"nodeAPIs": Array [
"createPagesStatefully",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/dev-404-page/src/pages",
"pathCheck": false,
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "gatsby-plugin-page-creator",
"nodeAPIs": Array [
"createPagesStatefully",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/load-babel-config/src/pages",
"pathCheck": false,
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "gatsby-plugin-page-creator",
"nodeAPIs": Array [
"createPagesStatefully",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/internal-data-bridge/src/pages",
"pathCheck": false,
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "gatsby-plugin-page-creator",
"nodeAPIs": Array [
"createPagesStatefully",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/prod-404/src/pages",
"pathCheck": false,
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "gatsby-plugin-page-creator",
"nodeAPIs": Array [
"createPagesStatefully",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/src/pages",
"pathCheck": false,
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "gatsby-plugin-page-creator",
"nodeAPIs": Array [
"createPagesStatefully",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby-plugin-page-creator/src/pages",
"pathCheck": false,
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "gatsby-plugin-page-creator",
"nodeAPIs": Array [
"createPagesStatefully",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/src/pages",
"pathCheck": false,
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
Object {
"browserAPIs": Array [],
"id": "",
"name": "gatsby-plugin-page-creator",
"nodeAPIs": Array [
"createPagesStatefully",
],
"pluginOptions": Object {
"ignore": Array [
"___Test___.(js|ts)?(x)",
],
"path": "___TEST___/src/pages",
"plugins": Array [],
},
"resolve": "",
"ssrAPIs": Array [],
"version": "1.0.0",
},
]
`;
Expand Up @@ -51,4 +51,24 @@ describe(`Load plugins`, () => {

expect(plugins).toMatchSnapshot()
})

it(`Overrides the options for gatsby-plugin-page-creator`, async () => {
const config = {
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `___TEST___/src/pages`,
ignore: [`___Test___.(js|ts)?(x)`],
},
},
],
}

let plugins = await loadPlugins(config)

plugins = replaceFieldsThatCanVary(plugins)

expect(plugins).toMatchSnapshot()
})
})
24 changes: 20 additions & 4 deletions packages/gatsby/src/bootstrap/load-plugins/load.js
Expand Up @@ -211,13 +211,29 @@ module.exports = (config = {}, rootDir = null) => {
)
})
const program = store.getState().program

// default options for gatsby-plugin-page-creator
let pageCreatorOptions = {
path: slash(path.join(program.directory, `src/pages`)),
pathCheck: false,
}

if (config.plugins) {
const pageCreatorPlugin = config.plugins.find(
plugin =>
plugin.resolve === `gatsby-plugin-page-creator` &&
plugin.options.path.match(/src\/pages$/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not match only the last chars but the full path, because all path for this plugin are full path

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be also ${__dirname}/myguides/src/pages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the condition to override the defaults only if the path matches <program.directory>/src/pages

)
if (pageCreatorPlugin) {
// override the options if there are any user specified options
pageCreatorOptions = pageCreatorPlugin.options
}
}

plugins.push(
processPlugin({
resolve: require.resolve(`gatsby-plugin-page-creator`),
options: {
path: slash(path.join(program.directory, `src/pages`)),
pathCheck: false,
},
options: pageCreatorOptions,
})
)

Expand Down