From a46df62a49f9a1eb1446c3959bba5dc2cb7d326a Mon Sep 17 00:00:00 2001 From: Laurie Date: Tue, 9 Feb 2021 09:29:07 -0500 Subject: [PATCH 01/10] Address todos for major release --- packages/babel-preset-gatsby/src/index.js | 3 +-- .../gatsby-plugin-feed/src/gatsby-node.js | 20 +------------------ .../src/gatsby-node.js | 8 +++++--- 3 files changed, 7 insertions(+), 24 deletions(-) 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/gatsby-node.js b/packages/gatsby-plugin-feed/src/gatsby-node.js index 8b2fab7277f1d..ccf9a6d399413 100644 --- a/packages/gatsby-plugin-feed/src/gatsby-node.js +++ b/packages/gatsby-plugin-feed/src/gatsby-node.js @@ -10,19 +10,6 @@ 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) => { /* * Run the site settings query to gather context, then @@ -47,12 +34,7 @@ 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) => { + const rssFeed = (await feed.serialize(locals)).reduce((merged, item) => { merged.item(item) return merged }, new RSS(setup(locals))) 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( From ddee647de8cc18d9afe16594be77378ff45b7f13 Mon Sep 17 00:00:00 2001 From: Laurie Date: Tue, 9 Feb 2021 10:05:27 -0500 Subject: [PATCH 02/10] fix tests --- .../src/__tests__/gatsby-node.js | 20 ++++++++++++++++++- .../load-plugins/__tests__/load-plugins.ts | 11 ++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js index a669f5f662d79..225dd0be87997 100644 --- a/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js @@ -42,7 +42,19 @@ describe(`Test plugin feed`, () => { }, }, }) - await onPostBuild({ graphql }, {}) + const options = { + feeds: [ + { + serialize: ({ query: { allMarkdownRemark } }) => + allMarkdownRemark.edges.map(edge => { + return { + ...edge.node.frontmatter, + } + }), + }, + ], + } + await onPostBuild({ graphql }, options) const [filePath, contents] = fs.writeFile.mock.calls[0] expect(filePath).toEqual(path.join(`public`, `rss.xml`)) expect(contents).toMatchSnapshot() @@ -243,6 +255,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/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", From b9aa282dde6b20f19911d93c5cb1482bcb08a7bf Mon Sep 17 00:00:00 2001 From: Laurie Date: Tue, 9 Feb 2021 10:23:50 -0500 Subject: [PATCH 03/10] remove default test since we've removed defaults --- .../src/__tests__/gatsby-node.js | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js index 225dd0be87997..f560026bcbc30 100644 --- a/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js @@ -15,51 +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`, - }, - }, - ], - }, - }, - }) - const options = { - feeds: [ - { - serialize: ({ query: { allMarkdownRemark } }) => - allMarkdownRemark.edges.map(edge => { - return { - ...edge.node.frontmatter, - } - }), - }, - ], - } - await onPostBuild({ graphql }, options) - 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) From 03b30fa87300ef81e69b6de504f4bc3ef41d99d4 Mon Sep 17 00:00:00 2001 From: Laurie Date: Tue, 9 Feb 2021 10:49:51 -0500 Subject: [PATCH 04/10] another trackingId test fix --- .../src/bootstrap/load-plugins/__tests__/load-plugins.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 35360ae610f5d..3f69a7f57e804 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.ts +++ b/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.ts @@ -235,11 +235,11 @@ describe(`Load plugins`, () => { "label": "trackingId", "value": 123, }, - "message": "\\"trackingId\\" must be a string", + "message": "\\"trackingId\\" is required", "path": Array [ "trackingId", ], - "type": "string.base", + "type": "any.required", }, Object { "context": Object { From f9f5e1cf03bc1ea10306b058a308c69b3cea57ad Mon Sep 17 00:00:00 2001 From: Laurie Date: Wed, 10 Feb 2021 08:22:01 -0500 Subject: [PATCH 05/10] changed the wrong test --- .../src/bootstrap/load-plugins/__tests__/load-plugins.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 3f69a7f57e804..35360ae610f5d 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.ts +++ b/packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.ts @@ -235,11 +235,11 @@ describe(`Load plugins`, () => { "label": "trackingId", "value": 123, }, - "message": "\\"trackingId\\" is required", + "message": "\\"trackingId\\" must be a string", "path": Array [ "trackingId", ], - "type": "any.required", + "type": "string.base", }, Object { "context": Object { From 2fc1048eb0956b6986a3c7fabca519248505edc3 Mon Sep 17 00:00:00 2001 From: Laurie Date: Wed, 10 Feb 2021 08:27:05 -0500 Subject: [PATCH 06/10] remove obsolete snapshot --- .../build-headers-program.js.snap | 90 ------------------- 1 file changed, 90 deletions(-) diff --git a/packages/gatsby-plugin-netlify/src/__tests__/__snapshots__/build-headers-program.js.snap b/packages/gatsby-plugin-netlify/src/__tests__/__snapshots__/build-headers-program.js.snap index 9b6fbb96789ef..109968fd2cc3a 100644 --- a/packages/gatsby-plugin-netlify/src/__tests__/__snapshots__/build-headers-program.js.snap +++ b/packages/gatsby-plugin-netlify/src/__tests__/__snapshots__/build-headers-program.js.snap @@ -1,95 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`build-headers-program with badly headers configuration 1`] = ` -"## Created with gatsby-plugin-netlify - -/* - X-Frame-Options: DENY - X-XSS-Protection: 1; mode=block - X-Content-Type-Options: nosniff - Referrer-Policy: same-origin -X-Frame-Options - sameorigin -/component---node-modules-gatsby-plugin-offline-app-shell-js-78f9e4dea04737fa062d.js - Cache-Control: public, max-age=31536000, immutable -/0-0180cd94ef2497ac7db8.js - Cache-Control: public, max-age=31536000, immutable -/component---src-templates-blog-post-js-517987eae96e75cddbe7.js - Cache-Control: public, max-age=31536000, immutable -/component---src-pages-404-js-53e6c51a5a7e73090f50.js - Cache-Control: public, max-age=31536000, immutable -/component---src-pages-index-js-0bdd01c77ee09ef0224c.js - Cache-Control: public, max-age=31536000, immutable -/webpack-runtime-acaa8994f1f704475e21.js - Cache-Control: public, max-age=31536000, immutable -/styles.1025963f4f2ec7abbad4.css - Cache-Control: public, max-age=31536000, immutable -/styles-565f081c8374bbda155f.js - Cache-Control: public, max-age=31536000, immutable -/app-f33c13590352da20930f.js - Cache-Control: public, max-age=31536000, immutable -/static/* - Cache-Control: public, max-age=31536000, immutable -/sw.js - Cache-Control: no-cache -/offline-plugin-app-shell-fallback/ - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=fetch; crossorigin - Link: ; rel=preload; as=fetch; crossorigin -/hi-folks/ - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=fetch; crossorigin - Link: ; rel=preload; as=fetch; crossorigin -/my-second-post/ - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=fetch; crossorigin - Link: ; rel=preload; as=fetch; crossorigin -/hello-world/ - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=fetch; crossorigin - Link: ; rel=preload; as=fetch; crossorigin -/404/ - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=fetch; crossorigin - Link: ; rel=preload; as=fetch; crossorigin -/ - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=fetch; crossorigin - Link: ; rel=preload; as=fetch; crossorigin -/404.html - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=script - Link: ; rel=preload; as=fetch; crossorigin - Link: ; rel=preload; as=fetch; crossorigin -" -`; - exports[`build-headers-program with caching headers 1`] = ` "## Created with gatsby-plugin-netlify From 46066f9b891799418f97ccad932d3f017d0b257f Mon Sep 17 00:00:00 2001 From: Laurie Date: Wed, 10 Feb 2021 08:30:09 -0500 Subject: [PATCH 07/10] undo --- .../build-headers-program.js.snap | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/packages/gatsby-plugin-netlify/src/__tests__/__snapshots__/build-headers-program.js.snap b/packages/gatsby-plugin-netlify/src/__tests__/__snapshots__/build-headers-program.js.snap index 109968fd2cc3a..9b6fbb96789ef 100644 --- a/packages/gatsby-plugin-netlify/src/__tests__/__snapshots__/build-headers-program.js.snap +++ b/packages/gatsby-plugin-netlify/src/__tests__/__snapshots__/build-headers-program.js.snap @@ -1,5 +1,95 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`build-headers-program with badly headers configuration 1`] = ` +"## Created with gatsby-plugin-netlify + +/* + X-Frame-Options: DENY + X-XSS-Protection: 1; mode=block + X-Content-Type-Options: nosniff + Referrer-Policy: same-origin +X-Frame-Options + sameorigin +/component---node-modules-gatsby-plugin-offline-app-shell-js-78f9e4dea04737fa062d.js + Cache-Control: public, max-age=31536000, immutable +/0-0180cd94ef2497ac7db8.js + Cache-Control: public, max-age=31536000, immutable +/component---src-templates-blog-post-js-517987eae96e75cddbe7.js + Cache-Control: public, max-age=31536000, immutable +/component---src-pages-404-js-53e6c51a5a7e73090f50.js + Cache-Control: public, max-age=31536000, immutable +/component---src-pages-index-js-0bdd01c77ee09ef0224c.js + Cache-Control: public, max-age=31536000, immutable +/webpack-runtime-acaa8994f1f704475e21.js + Cache-Control: public, max-age=31536000, immutable +/styles.1025963f4f2ec7abbad4.css + Cache-Control: public, max-age=31536000, immutable +/styles-565f081c8374bbda155f.js + Cache-Control: public, max-age=31536000, immutable +/app-f33c13590352da20930f.js + Cache-Control: public, max-age=31536000, immutable +/static/* + Cache-Control: public, max-age=31536000, immutable +/sw.js + Cache-Control: no-cache +/offline-plugin-app-shell-fallback/ + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=fetch; crossorigin + Link: ; rel=preload; as=fetch; crossorigin +/hi-folks/ + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=fetch; crossorigin + Link: ; rel=preload; as=fetch; crossorigin +/my-second-post/ + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=fetch; crossorigin + Link: ; rel=preload; as=fetch; crossorigin +/hello-world/ + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=fetch; crossorigin + Link: ; rel=preload; as=fetch; crossorigin +/404/ + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=fetch; crossorigin + Link: ; rel=preload; as=fetch; crossorigin +/ + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=fetch; crossorigin + Link: ; rel=preload; as=fetch; crossorigin +/404.html + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=script + Link: ; rel=preload; as=fetch; crossorigin + Link: ; rel=preload; as=fetch; crossorigin +" +`; + exports[`build-headers-program with caching headers 1`] = ` "## Created with gatsby-plugin-netlify From 82cf4f8ae6199d4c460698ef9ced45db0744b974 Mon Sep 17 00:00:00 2001 From: Laurie Date: Wed, 10 Feb 2021 08:46:36 -0500 Subject: [PATCH 08/10] remove obsolete test, the right one this time --- .../src/__tests__/__snapshots__/gatsby-node.js.snap | 1 - 1 file changed, 1 deletion(-) 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`] = `"<![CDATA[my feed]]>http://github.com/dylang/node-rssGatsbyJSMon, 01 Jan 2018 00:00:00 GMT<![CDATA[No title]]>http://dummy.url/a-custom-pathhttp://dummy.url/a-custom-path<![CDATA[No title]]>http://dummy.url/another-custom-pathhttp://dummy.url/another-custom-path"`; -exports[`Test plugin feed default settings work properly 1`] = `"<![CDATA[a sample title]]>http://github.com/dylang/node-rssGatsbyJSMon, 01 Jan 2018 00:00:00 GMT<![CDATA[No title]]>http://dummy.url/a-slughttp://dummy.url/a-slug"`; From 219c1a87b89e2a2dce8c7eedf8021d065f3778a8 Mon Sep 17 00:00:00 2001 From: Laurie Date: Wed, 10 Feb 2021 10:04:13 -0500 Subject: [PATCH 09/10] add warn --- .../gatsby-plugin-feed/src/gatsby-node.js | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/gatsby-plugin-feed/src/gatsby-node.js b/packages/gatsby-plugin-feed/src/gatsby-node.js index ccf9a6d399413..1d5b39c6ecbba 100644 --- a/packages/gatsby-plugin-feed/src/gatsby-node.js +++ b/packages/gatsby-plugin-feed/src/gatsby-node.js @@ -10,7 +10,7 @@ const publicPath = `./public` exports.pluginOptionsSchema = pluginOptionsSchema -exports.onPostBuild = async ({ graphql }, pluginOptions) => { +exports.onPostBuild = async ({ graphql }, pluginOptions, reporter) => { /* * Run the site settings query to gather context, then * then run the corresponding feed for each query. @@ -34,16 +34,22 @@ exports.onPostBuild = async ({ graphql }, pluginOptions) => { ...feed, } - 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) + 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()) } } From 3d46de34effe95b63aaa047faffa73f032d86b31 Mon Sep 17 00:00:00 2001 From: Laurie Date: Wed, 10 Feb 2021 12:54:02 -0500 Subject: [PATCH 10/10] no comment --- packages/gatsby-plugin-feed/src/gatsby-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-plugin-feed/src/gatsby-node.js b/packages/gatsby-plugin-feed/src/gatsby-node.js index 1d5b39c6ecbba..916cd2d53ac33 100644 --- a/packages/gatsby-plugin-feed/src/gatsby-node.js +++ b/packages/gatsby-plugin-feed/src/gatsby-node.js @@ -10,7 +10,7 @@ const publicPath = `./public` exports.pluginOptionsSchema = pluginOptionsSchema -exports.onPostBuild = async ({ graphql }, pluginOptions, reporter) => { +exports.onPostBuild = async ({ graphql, reporter }, pluginOptions) => { /* * Run the site settings query to gather context, then * then run the corresponding feed for each query.