diff --git a/packages/babel-preset-gatsby/src/index.js b/packages/babel-preset-gatsby/src/index.js
index aca29a0d2dff1..e87620ff21a04 100644
--- a/packages/babel-preset-gatsby/src/index.js
+++ b/packages/babel-preset-gatsby/src/index.js
@@ -32,8 +32,7 @@ export function loadCachedConfig() {
export default function preset(_, options = {}) {
let { targets = null } = options
- // TODO(v3): Remove process.env.GATSBY_BUILD_STAGE, needs to be passed as an option
- const stage = options.stage || process.env.GATSBY_BUILD_STAGE || `test`
+ const stage = options.stage || `test`
const pluginBabelConfig = loadCachedConfig()
let isBrowser
// unused because of cloud builds
diff --git a/packages/gatsby-plugin-feed/src/__tests__/__snapshots__/gatsby-node.js.snap b/packages/gatsby-plugin-feed/src/__tests__/__snapshots__/gatsby-node.js.snap
index f3119e341c259..baf768d2cd3a9 100644
--- a/packages/gatsby-plugin-feed/src/__tests__/__snapshots__/gatsby-node.js.snap
+++ b/packages/gatsby-plugin-feed/src/__tests__/__snapshots__/gatsby-node.js.snap
@@ -4,4 +4,3 @@ exports[`Test plugin feed custom properties work properly 1`] = `"http://github.com/dylang/node-rssGatsbyJSMon, 01 Jan 2018 00:00:00 GMT- http://dummy.url/a-custom-pathhttp://dummy.url/a-custom-path
- http://dummy.url/another-custom-pathhttp://dummy.url/another-custom-path
"`;
-exports[`Test plugin feed default settings work properly 1`] = `"http://github.com/dylang/node-rssGatsbyJSMon, 01 Jan 2018 00:00:00 GMT- http://dummy.url/a-slughttp://dummy.url/a-slug
"`;
diff --git a/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js
index a669f5f662d79..f560026bcbc30 100644
--- a/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js
+++ b/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js
@@ -15,39 +15,6 @@ describe(`Test plugin feed`, () => {
fs.mkdirp = jest.fn().mockResolvedValue()
})
- it(`default settings work properly`, async () => {
- fs.writeFile = jest.fn()
- fs.writeFile.mockResolvedValue(true)
- const graphql = jest.fn()
- graphql.mockResolvedValue({
- data: {
- site: {
- siteMetadata: {
- title: `a sample title`,
- description: `a description`,
- siteUrl: `http://dummy.url/`,
- },
- },
- allMarkdownRemark: {
- edges: [
- {
- node: {
- fields: {
- slug: `a-slug`,
- },
- excerpt: `post description`,
- },
- },
- ],
- },
- },
- })
- await onPostBuild({ graphql }, {})
- const [filePath, contents] = fs.writeFile.mock.calls[0]
- expect(filePath).toEqual(path.join(`public`, `rss.xml`))
- expect(contents).toMatchSnapshot()
- })
-
it(`custom properties work properly`, async () => {
fs.writeFile = jest.fn()
fs.writeFile.mockResolvedValue(true)
@@ -243,6 +210,12 @@ describe(`Test plugin feed`, () => {
{
output: `rss.xml`,
query: `{ firstMarkdownQuery }`,
+ serialize: ({ query: { allMarkdownRemark } }) =>
+ allMarkdownRemark.edges.map(edge => {
+ return {
+ ...edge.node.frontmatter,
+ }
+ }),
},
],
}
diff --git a/packages/gatsby-plugin-feed/src/gatsby-node.js b/packages/gatsby-plugin-feed/src/gatsby-node.js
index 8b2fab7277f1d..916cd2d53ac33 100644
--- a/packages/gatsby-plugin-feed/src/gatsby-node.js
+++ b/packages/gatsby-plugin-feed/src/gatsby-node.js
@@ -10,20 +10,7 @@ const publicPath = `./public`
exports.pluginOptionsSchema = pluginOptionsSchema
-// TODO: remove in the next major release
-// A default function to transform query data into feed entries.
-const serialize = ({ query: { site, allMarkdownRemark } }) =>
- allMarkdownRemark.edges.map(edge => {
- return {
- ...edge.node.frontmatter,
- description: edge.node.excerpt,
- url: site.siteMetadata.siteUrl + edge.node.fields.slug,
- guid: site.siteMetadata.siteUrl + edge.node.fields.slug,
- custom_elements: [{ "content:encoded": edge.node.html }],
- }
- })
-
-exports.onPostBuild = async ({ graphql }, pluginOptions) => {
+exports.onPostBuild = async ({ graphql, reporter }, pluginOptions) => {
/*
* Run the site settings query to gather context, then
* then run the corresponding feed for each query.
@@ -47,21 +34,22 @@ exports.onPostBuild = async ({ graphql }, pluginOptions) => {
...feed,
}
- const serializer =
- feed.serialize && typeof feed.serialize === `function`
- ? feed.serialize
- : serialize
-
- const rssFeed = (await serializer(locals)).reduce((merged, item) => {
- merged.item(item)
- return merged
- }, new RSS(setup(locals)))
-
- const outputPath = path.join(publicPath, feed.output)
- const outputDir = path.dirname(outputPath)
- if (!(await fs.exists(outputDir))) {
- await fs.mkdirp(outputDir)
+ if (!feed.serialize || typeof feed.serialize !== `function`) {
+ reporter.warn(
+ `You did not pass in a valid serialize function. Your feed will not be generated.`
+ )
+ } else {
+ const rssFeed = (await feed.serialize(locals)).reduce((merged, item) => {
+ merged.item(item)
+ return merged
+ }, new RSS(setup(locals)))
+
+ const outputPath = path.join(publicPath, feed.output)
+ const outputDir = path.dirname(outputPath)
+ if (!(await fs.exists(outputDir))) {
+ await fs.mkdirp(outputDir)
+ }
+ await fs.writeFile(outputPath, rssFeed.xml())
}
- await fs.writeFile(outputPath, rssFeed.xml())
}
}
diff --git a/packages/gatsby-plugin-google-analytics/src/gatsby-node.js b/packages/gatsby-plugin-google-analytics/src/gatsby-node.js
index 0abe991e072ae..bbc57071e63f6 100644
--- a/packages/gatsby-plugin-google-analytics/src/gatsby-node.js
+++ b/packages/gatsby-plugin-google-analytics/src/gatsby-node.js
@@ -1,9 +1,11 @@
exports.pluginOptionsSchema = ({ Joi }) =>
// TODO: make sure that trackingId gets required() when releasing a major version
Joi.object({
- trackingId: Joi.string().description(
- `The property ID; the tracking code won't be generated without it`
- ),
+ trackingId: Joi.string()
+ .description(
+ `The property ID; the tracking code won't be generated without it`
+ )
+ .required(),
head: Joi.boolean()
.default(false)
.description(
diff --git a/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.ts b/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.ts
index 76c7552d58e57..35360ae610f5d 100644
--- a/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.ts
+++ b/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.ts
@@ -267,6 +267,17 @@ describe(`Load plugins`, () => {
"configDir": null,
"pluginName": "gatsby-plugin-google-analytics",
"validationErrors": Array [
+ Object {
+ "context": Object {
+ "key": "trackingId",
+ "label": "trackingId",
+ },
+ "message": "\\"trackingId\\" is required",
+ "path": Array [
+ "trackingId",
+ ],
+ "type": "any.required",
+ },
Object {
"context": Object {
"key": "anonymize",