From 747ab8fb5c427c5b99099698880291559f583c19 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Mon, 1 Apr 2019 22:17:27 +0200 Subject: [PATCH 01/16] :recycle: Update gatsby-source-hacker-news to use createContentDigest helper --- packages/gatsby-source-hacker-news/package.json | 2 +- .../gatsby-source-hacker-news/src/gatsby-node.js | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/gatsby-source-hacker-news/package.json b/packages/gatsby-source-hacker-news/package.json index 89bdae7fd3ffc..88900ad70bf2c 100644 --- a/packages/gatsby-source-hacker-news/package.json +++ b/packages/gatsby-source-hacker-news/package.json @@ -25,7 +25,7 @@ ], "license": "MIT", "peerDependencies": { - "gatsby": "^2.0.0" + "gatsby": "^2.0.15" }, "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-hacker-news", "scripts": { diff --git a/packages/gatsby-source-hacker-news/src/gatsby-node.js b/packages/gatsby-source-hacker-news/src/gatsby-node.js index e53b2e2b06a9e..e275818710b24 100644 --- a/packages/gatsby-source-hacker-news/src/gatsby-node.js +++ b/packages/gatsby-source-hacker-news/src/gatsby-node.js @@ -1,5 +1,4 @@ const axios = require(`axios`) -const crypto = require(`crypto`) const url = require(`url`) const _ = require(`lodash`) @@ -13,6 +12,7 @@ exports.sourceNodes = async ({ getNode, createNodeId, hasNodeChanged, + createContentDigest, }) => { const { createNode } = actions @@ -117,11 +117,7 @@ fragment commentsFragment on HackerNewsItem { storyNode.by = storyNode.by.id // Get content digest of node. - const contentDigest = crypto - .createHash(`md5`) - .update(JSON.stringify(storyNode)) - .digest(`hex`) - + const contentDigest = createContentDigest(storyNode) storyNode.internal.contentDigest = contentDigest createNode(storyNode) @@ -147,11 +143,7 @@ fragment commentsFragment on HackerNewsItem { const nodeStr = JSON.stringify(commentNode) // Get content digest of comment node. - const contentDigest = crypto - .createHash(`md5`) - .update(nodeStr) - .digest(`hex`) - + const contentDigest = createContentDigest(nodeStr) commentNode.internal.contentDigest = contentDigest commentNode.internal.content = nodeStr From 19615ba47454308ee240ec8a9bf4ee817e0d60ed Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Mon, 1 Apr 2019 22:42:30 +0200 Subject: [PATCH 02/16] :recycle: Update gatsby-transformer-excel to use createContentDigest helper --- .../gatsby-transformer-excel/package.json | 2 +- .../__snapshots__/gatsby-node.js.snap | 36 +++++++++---------- .../src/__tests__/gatsby-node.js | 9 +++++ .../src/gatsby-node.js | 17 ++------- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/packages/gatsby-transformer-excel/package.json b/packages/gatsby-transformer-excel/package.json index d9336c3ac4e92..a8a802d4525f2 100644 --- a/packages/gatsby-transformer-excel/package.json +++ b/packages/gatsby-transformer-excel/package.json @@ -25,7 +25,7 @@ "license": "MIT", "main": "index.js", "peerDependencies": { - "gatsby": "^2.0.0" + "gatsby": "^2.0.15" }, "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-excel", "scripts": { diff --git a/packages/gatsby-transformer-excel/src/__tests__/__snapshots__/gatsby-node.js.snap b/packages/gatsby-transformer-excel/src/__tests__/__snapshots__/gatsby-node.js.snap index 5c31be92a58dd..19d5474d07bfe 100644 --- a/packages/gatsby-transformer-excel/src/__tests__/__snapshots__/gatsby-node.js.snap +++ b/packages/gatsby-transformer-excel/src/__tests__/__snapshots__/gatsby-node.js.snap @@ -9,7 +9,7 @@ Array [ "funny": "yup", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "73901821b17d5aa9dd6026181f73b64c", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -22,7 +22,7 @@ Array [ "funny": "nope", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "f624311d932d73dcd416d2a8bea2b67d", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -33,7 +33,7 @@ Array [ "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "10c867561d207bc7dae0455d3cccad5b", + "contentDigest": "contentDigest", "type": "TestCsv", }, "parent": "whatever", @@ -52,7 +52,7 @@ Array [ "funny": "yup", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "73901821b17d5aa9dd6026181f73b64c", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -82,7 +82,7 @@ FALSE,nope "funny": "nope", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "f624311d932d73dcd416d2a8bea2b67d", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -110,7 +110,7 @@ FALSE,nope "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "10c867561d207bc7dae0455d3cccad5b", + "contentDigest": "contentDigest", "type": "TestCsv", }, "parent": "whatever", @@ -142,7 +142,7 @@ Array [ "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "c685d551c99950924e4b7a78a267a993", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -155,7 +155,7 @@ Array [ "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "f197dfd371325c9aa0693a4c406f6cff", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -168,7 +168,7 @@ Array [ "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "10c867561d207bc7dae0455d3cccad5b", + "contentDigest": "contentDigest", "type": "TestCsv", }, "parent": "whatever", @@ -185,7 +185,7 @@ Array [ "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "c685d551c99950924e4b7a78a267a993", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -215,7 +215,7 @@ FALSE,nada "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "f197dfd371325c9aa0693a4c406f6cff", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -245,7 +245,7 @@ FALSE,nada "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "10c867561d207bc7dae0455d3cccad5b", + "contentDigest": "contentDigest", "type": "TestCsv", }, "parent": "whatever", @@ -277,7 +277,7 @@ Array [ "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "c685d551c99950924e4b7a78a267a993", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -290,7 +290,7 @@ Array [ "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "f197dfd371325c9aa0693a4c406f6cff", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -303,7 +303,7 @@ Array [ "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "10c867561d207bc7dae0455d3cccad5b", + "contentDigest": "contentDigest", "type": "TestCsv", }, "parent": "whatever", @@ -320,7 +320,7 @@ Array [ "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "c685d551c99950924e4b7a78a267a993", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -350,7 +350,7 @@ FALSE,nada "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "f197dfd371325c9aa0693a4c406f6cff", + "contentDigest": "contentDigest", "type": "TestCsv__Sheet1", }, "parent": "whatever", @@ -380,7 +380,7 @@ FALSE,nada "children": Array [], "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "10c867561d207bc7dae0455d3cccad5b", + "contentDigest": "contentDigest", "type": "TestCsv", }, "parent": "whatever", diff --git a/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js b/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js index 00ccf2b0e50ce..ae51ff027a3b4 100644 --- a/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js +++ b/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js @@ -29,17 +29,20 @@ describe(`Process nodes correctly`, () => { const actions = { createNode, createParentChildLink } const createNodeId = jest.fn() createNodeId.mockReturnValue(`uuid-from-gatsby`) + const createDigestContent = jest.fn().mockReturnValue(`contentDigest`) await onCreateNode({ node, loadNodeContent, actions, createNodeId, + createDigestContent, }).then(() => { expect(createNode.mock.calls).toMatchSnapshot() expect(createParentChildLink.mock.calls).toMatchSnapshot() expect(createNode).toHaveBeenCalledTimes(2 + 1) expect(createParentChildLink).toHaveBeenCalledTimes(2 + 1) + expect(createDigestContent).toHaveBeenCalledTimes(2 + 1) }) }) @@ -53,6 +56,7 @@ describe(`Process nodes correctly`, () => { const actions = { createNode, createParentChildLink } const createNodeId = jest.fn() createNodeId.mockReturnValue(`uuid-from-gatsby`) + const createDigestContent = jest.fn().mockReturnValue(`contentDigest`) await onCreateNode( { @@ -60,6 +64,7 @@ describe(`Process nodes correctly`, () => { loadNodeContent, actions, createNodeId, + createDigestContent, }, { raw: false } ).then(() => { @@ -67,6 +72,7 @@ describe(`Process nodes correctly`, () => { expect(createParentChildLink.mock.calls).toMatchSnapshot() expect(createNode).toHaveBeenCalledTimes(2 + 1) expect(createParentChildLink).toHaveBeenCalledTimes(2 + 1) + expect(createDigestContent).toHaveBeenCalledTimes(2 + 1) }) }) @@ -80,6 +86,7 @@ describe(`Process nodes correctly`, () => { const actions = { createNode, createParentChildLink } const createNodeId = jest.fn() createNodeId.mockReturnValue(`uuid-from-gatsby`) + const createDigestContent = jest.fn().mockReturnValue(`contentDigest`) await onCreateNode( { @@ -87,6 +94,7 @@ describe(`Process nodes correctly`, () => { loadNodeContent, actions, createNodeId, + createDigestContent, }, { rawOutput: false } ).then(() => { @@ -94,6 +102,7 @@ describe(`Process nodes correctly`, () => { expect(createParentChildLink.mock.calls).toMatchSnapshot() expect(createNode).toHaveBeenCalledTimes(2 + 1) expect(createParentChildLink).toHaveBeenCalledTimes(2 + 1) + expect(createDigestContent).toHaveBeenCalledTimes(2 + 1) }) }) }) diff --git a/packages/gatsby-transformer-excel/src/gatsby-node.js b/packages/gatsby-transformer-excel/src/gatsby-node.js index eb537e6e24719..cb36ecae5cc7e 100644 --- a/packages/gatsby-transformer-excel/src/gatsby-node.js +++ b/packages/gatsby-transformer-excel/src/gatsby-node.js @@ -1,7 +1,6 @@ const XLSX = require(`xlsx`) const fs = require(`fs-extra`) const _ = require(`lodash`) -const crypto = require(`crypto`) // read files as `binary` from file system function _loadNodeContent(fileNode, fallback) { @@ -11,7 +10,7 @@ function _loadNodeContent(fileNode, fallback) { } async function onCreateNode( - { node, actions, loadNodeContent, createNodeId }, + { node, actions, loadNodeContent, createNodeId, createDigestContent }, options = {} ) { const { createNode, createParentChildLink } = actions @@ -45,12 +44,7 @@ async function onCreateNode( if (_.isArray(parsedContent)) { const csvArray = parsedContent.map((obj, i) => { - const objStr = JSON.stringify(obj) - const contentDigest = crypto - .createHash(`md5`) - .update(objStr) - .digest(`hex`) - + const contentDigest = createDigestContent(obj) return { ...obj, id: obj.id @@ -74,12 +68,7 @@ async function onCreateNode( }) const shObj = { name: n, idx: idx } - const shStr = JSON.stringify(shObj) - const contentDigest = crypto - .createHash(`md5`) - .update(shStr) - .digest(`hex`) - + const contentDigest = createDigestContent(shObj) const z = { id: createNodeId(`${node.id} [${idx}] >>> ${node.extension}`), children: [], From cc74c5e83a268024b9b8efc6b27969ee3a9bb807 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Tue, 2 Apr 2019 10:10:22 +0200 Subject: [PATCH 03/16] :recycle: Update gatsby-source-wikipedia to use createContentDigest helper --- packages/gatsby-source-wikipedia/src/gatsby-node.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/gatsby-source-wikipedia/src/gatsby-node.js b/packages/gatsby-source-wikipedia/src/gatsby-node.js index bfb311ceaef65..29e11fc088d0d 100644 --- a/packages/gatsby-source-wikipedia/src/gatsby-node.js +++ b/packages/gatsby-source-wikipedia/src/gatsby-node.js @@ -1,7 +1,10 @@ const Promise = require(`bluebird`) const { fetchNodesFromSearch } = require(`./fetch`) -exports.sourceNodes = ({ actions, createNodeId }, pluginOptions) => { +exports.sourceNodes = ( + { actions, createNodeId, createContentDigest }, + pluginOptions +) => { const { createNode } = actions return Promise.map(pluginOptions.queries, ({ query, limit }) => fetchNodesFromSearch({ query, limit }).then(results => @@ -17,10 +20,7 @@ exports.sourceNodes = ({ actions, createNodeId }, pluginOptions) => { type: `WikipediaArticle`, }, } - node.internal.contentDigest = require(`crypto`) - .createHash(`md5`) - .update(JSON.stringify(node)) - .digest(`hex`) + node.internal.contentDigest = createContentDigest(node) createNode(node) }) ) From a7b96d3d3250bbdbaec51ff8a63516f28922efb0 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Tue, 2 Apr 2019 14:49:28 +0200 Subject: [PATCH 04/16] :recycle: Update gatsby-source-wordpress to use createContentDigest helper --- packages/gatsby-source-wordpress/package.json | 2 +- .../__tests__/__snapshots__/normalize.js.snap | 2 +- .../src/__tests__/normalize.js | 7 ++++- .../src/gatsby-node.js | 8 +++-- .../gatsby-source-wordpress/src/normalize.js | 31 ++++++++----------- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/packages/gatsby-source-wordpress/package.json b/packages/gatsby-source-wordpress/package.json index 33b2541432e76..2c4f4aa53d452 100644 --- a/packages/gatsby-source-wordpress/package.json +++ b/packages/gatsby-source-wordpress/package.json @@ -35,7 +35,7 @@ ], "license": "MIT", "peerDependencies": { - "gatsby": "^2.0.0" + "gatsby": "^2.0.15" }, "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-wordpress", "scripts": { diff --git a/packages/gatsby-source-wordpress/src/__tests__/__snapshots__/normalize.js.snap b/packages/gatsby-source-wordpress/src/__tests__/__snapshots__/normalize.js.snap index f0c76364ea351..cf9ccee320660 100644 --- a/packages/gatsby-source-wordpress/src/__tests__/__snapshots__/normalize.js.snap +++ b/packages/gatsby-source-wordpress/src/__tests__/__snapshots__/normalize.js.snap @@ -15915,7 +15915,7 @@ Array [ Object { "children": Array [], "internal": Object { - "contentDigest": "14d9a406858cbf66499eb9f810894428", + "contentDigest": "contentDigest", "type": "wordpress__PAGE", }, "link": "/packages/gatsby-source-wordpress/", diff --git a/packages/gatsby-source-wordpress/src/__tests__/normalize.js b/packages/gatsby-source-wordpress/src/__tests__/normalize.js index f04077581c9bc..27858c6d3a9aa 100644 --- a/packages/gatsby-source-wordpress/src/__tests__/normalize.js +++ b/packages/gatsby-source-wordpress/src/__tests__/normalize.js @@ -116,7 +116,12 @@ describe(`Process WordPress data`, () => { it(`creates nodes for each entry`, () => { const createNode = jest.fn() - normalize.createNodesFromEntities({ entities, createNode }) + const createContentDigest = jest.fn().mockReturnValue(`contentDigest`) + normalize.createNodesFromEntities({ + entities, + createNode, + createContentDigest, + }) expect(createNode.mock.calls).toMatchSnapshot() }) }) diff --git a/packages/gatsby-source-wordpress/src/gatsby-node.js b/packages/gatsby-source-wordpress/src/gatsby-node.js index 8e63e671572d1..1028c4b438ac8 100644 --- a/packages/gatsby-source-wordpress/src/gatsby-node.js +++ b/packages/gatsby-source-wordpress/src/gatsby-node.js @@ -24,7 +24,7 @@ let _excludedRoutes let _normalizer exports.sourceNodes = async ( - { actions, getNode, store, cache, createNodeId }, + { actions, getNode, store, cache, createNodeId, createContentDigest }, { baseUrl, protocol, @@ -162,7 +162,11 @@ exports.sourceNodes = async ( } // creates nodes for each entry - normalize.createNodesFromEntities({ entities, createNode }) + normalize.createNodesFromEntities({ + entities, + createNode, + createContentDigest, + }) return } diff --git a/packages/gatsby-source-wordpress/src/normalize.js b/packages/gatsby-source-wordpress/src/normalize.js index a3928d0039d58..b660e945e3558 100644 --- a/packages/gatsby-source-wordpress/src/normalize.js +++ b/packages/gatsby-source-wordpress/src/normalize.js @@ -1,4 +1,3 @@ -const crypto = require(`crypto`) const deepMapKeys = require(`deep-map-keys`) const _ = require(`lodash`) const { createRemoteFileNode } = require(`gatsby-source-filesystem`) @@ -9,17 +8,6 @@ const conflictFieldPrefix = `wordpress_` // restrictedNodeFields from here https://www.gatsbyjs.org/docs/node-interface/ const restrictedNodeFields = [`id`, `children`, `parent`, `fields`, `internal`] -/** - * Encrypts a String using md5 hash of hexadecimal digest. - * - * @param {any} str - */ -const digest = str => - crypto - .createHash(`md5`) - .update(str) - .digest(`hex`) - /** * Validate the GraphQL naming convetions & protect specific fields. * @@ -536,7 +524,8 @@ const prepareACFChildNodes = ( topLevelIndex, type, children, - childrenNodes + childrenNodes, + createContentDigest ) => { // Replace any child arrays with pointers to nodes _.each(obj, (value, key) => { @@ -549,7 +538,8 @@ const prepareACFChildNodes = ( topLevelIndex, type + key, children, - childrenNodes + childrenNodes, + createContentDigest ).id ) delete obj[key] @@ -561,7 +551,7 @@ const prepareACFChildNodes = ( id: entityId + topLevelIndex + type, parent: entityId, children: [], - internal: { type, contentDigest: digest(JSON.stringify(obj)) }, + internal: { type, contentDigest: createContentDigest(obj) }, } children.push(acfChildNode.id) @@ -574,7 +564,11 @@ const prepareACFChildNodes = ( return acfChildNode } -exports.createNodesFromEntities = ({ entities, createNode }) => { +exports.createNodesFromEntities = ({ + entities, + createNode, + createContentDigest, +}) => { entities.forEach(e => { // Create subnodes for ACF Flexible layouts let { __type, ...entity } = e // eslint-disable-line no-unused-vars @@ -594,7 +588,8 @@ exports.createNodesFromEntities = ({ entities, createNode }) => { key, type, children, - childrenNodes + childrenNodes, + createContentDigest ) return acfChildNode.id @@ -612,7 +607,7 @@ exports.createNodesFromEntities = ({ entities, createNode }) => { parent: null, internal: { type: e.__type, - contentDigest: digest(JSON.stringify(entity)), + contentDigest: createContentDigest(entity), }, } createNode(node) From 20aa0656ebe94b125c99d32d8c5e9b4e6656db0f Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Tue, 2 Apr 2019 14:50:46 +0200 Subject: [PATCH 05/16] :pencil2: Fix typo in function name --- .../src/__tests__/gatsby-node.js | 18 +++++++++--------- .../src/gatsby-node.js | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js b/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js index ae51ff027a3b4..2f8b4c33478e8 100644 --- a/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js +++ b/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js @@ -29,20 +29,20 @@ describe(`Process nodes correctly`, () => { const actions = { createNode, createParentChildLink } const createNodeId = jest.fn() createNodeId.mockReturnValue(`uuid-from-gatsby`) - const createDigestContent = jest.fn().mockReturnValue(`contentDigest`) + const createContentDigest = jest.fn().mockReturnValue(`contentDigest`) await onCreateNode({ node, loadNodeContent, actions, createNodeId, - createDigestContent, + createContentDigest, }).then(() => { expect(createNode.mock.calls).toMatchSnapshot() expect(createParentChildLink.mock.calls).toMatchSnapshot() expect(createNode).toHaveBeenCalledTimes(2 + 1) expect(createParentChildLink).toHaveBeenCalledTimes(2 + 1) - expect(createDigestContent).toHaveBeenCalledTimes(2 + 1) + expect(createContentDigest).toHaveBeenCalledTimes(2 + 1) }) }) @@ -56,7 +56,7 @@ describe(`Process nodes correctly`, () => { const actions = { createNode, createParentChildLink } const createNodeId = jest.fn() createNodeId.mockReturnValue(`uuid-from-gatsby`) - const createDigestContent = jest.fn().mockReturnValue(`contentDigest`) + const createContentDigest = jest.fn().mockReturnValue(`contentDigest`) await onCreateNode( { @@ -64,7 +64,7 @@ describe(`Process nodes correctly`, () => { loadNodeContent, actions, createNodeId, - createDigestContent, + createContentDigest, }, { raw: false } ).then(() => { @@ -72,7 +72,7 @@ describe(`Process nodes correctly`, () => { expect(createParentChildLink.mock.calls).toMatchSnapshot() expect(createNode).toHaveBeenCalledTimes(2 + 1) expect(createParentChildLink).toHaveBeenCalledTimes(2 + 1) - expect(createDigestContent).toHaveBeenCalledTimes(2 + 1) + expect(createContentDigest).toHaveBeenCalledTimes(2 + 1) }) }) @@ -86,7 +86,7 @@ describe(`Process nodes correctly`, () => { const actions = { createNode, createParentChildLink } const createNodeId = jest.fn() createNodeId.mockReturnValue(`uuid-from-gatsby`) - const createDigestContent = jest.fn().mockReturnValue(`contentDigest`) + const createContentDigest = jest.fn().mockReturnValue(`contentDigest`) await onCreateNode( { @@ -94,7 +94,7 @@ describe(`Process nodes correctly`, () => { loadNodeContent, actions, createNodeId, - createDigestContent, + createContentDigest, }, { rawOutput: false } ).then(() => { @@ -102,7 +102,7 @@ describe(`Process nodes correctly`, () => { expect(createParentChildLink.mock.calls).toMatchSnapshot() expect(createNode).toHaveBeenCalledTimes(2 + 1) expect(createParentChildLink).toHaveBeenCalledTimes(2 + 1) - expect(createDigestContent).toHaveBeenCalledTimes(2 + 1) + expect(createContentDigest).toHaveBeenCalledTimes(2 + 1) }) }) }) diff --git a/packages/gatsby-transformer-excel/src/gatsby-node.js b/packages/gatsby-transformer-excel/src/gatsby-node.js index cb36ecae5cc7e..d85b7b2b91984 100644 --- a/packages/gatsby-transformer-excel/src/gatsby-node.js +++ b/packages/gatsby-transformer-excel/src/gatsby-node.js @@ -10,7 +10,7 @@ function _loadNodeContent(fileNode, fallback) { } async function onCreateNode( - { node, actions, loadNodeContent, createNodeId, createDigestContent }, + { node, actions, loadNodeContent, createNodeId, createContentDigest }, options = {} ) { const { createNode, createParentChildLink } = actions @@ -44,7 +44,7 @@ async function onCreateNode( if (_.isArray(parsedContent)) { const csvArray = parsedContent.map((obj, i) => { - const contentDigest = createDigestContent(obj) + const contentDigest = createContentDigest(obj) return { ...obj, id: obj.id @@ -68,7 +68,7 @@ async function onCreateNode( }) const shObj = { name: n, idx: idx } - const contentDigest = createDigestContent(shObj) + const contentDigest = createContentDigest(shObj) const z = { id: createNodeId(`${node.id} [${idx}] >>> ${node.extension}`), children: [], From 674567701db99e3f269d375890135de0906bf705 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Tue, 2 Apr 2019 20:09:15 +0200 Subject: [PATCH 06/16] :recycle: Update gatsby-transformer-javascript-frontmatter to use createContentDigest helper --- .../package.json | 2 +- .../src/gatsby-node.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/gatsby-transformer-javascript-frontmatter/package.json b/packages/gatsby-transformer-javascript-frontmatter/package.json index a70fecf36c3fc..997d43e0eaa68 100644 --- a/packages/gatsby-transformer-javascript-frontmatter/package.json +++ b/packages/gatsby-transformer-javascript-frontmatter/package.json @@ -22,7 +22,7 @@ ], "license": "MIT", "peerDependencies": { - "gatsby": "^2.0.0", + "gatsby": "^2.0.15", "gatsby-source-filesystem": "^2.0.3" }, "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-javascript-frontmatter", diff --git a/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js b/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js index cb762e81aaa4a..9c7e25882bff0 100644 --- a/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js +++ b/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js @@ -1,9 +1,14 @@ const _ = require(`lodash`) -const crypto = require(`crypto`) const babylon = require(`@babel/parser`) const traverse = require(`@babel/traverse`).default -async function onCreateNode({ node, getNode, actions, loadNodeContent }) { +async function onCreateNode({ + node, + getNode, + actions, + loadNodeContent, + createContentDigest, +}) { const { createNode, createParentChildLink } = actions const fileExtsToProcess = [`js`, `jsx`, `ts`, `tsx`] @@ -107,12 +112,7 @@ async function onCreateNode({ node, getNode, actions, loadNodeContent }) { error: error, } - const objStr = JSON.stringify(node) - const contentDigest = crypto - .createHash(`md5`) - .update(objStr) - .digest(`hex`) - + const contentDigest = createContentDigest(node) const nodeData = { id: `${node.id} >>> JavascriptFrontmatter`, children: [], From 8e2b081ea500bb560eae19dbfb32272866358be4 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Tue, 2 Apr 2019 20:13:32 +0200 Subject: [PATCH 07/16] :recycle: Update gatsby-source-graphql to use createContentDigest helper --- packages/gatsby-source-graphql/package.json | 2 +- .../gatsby-source-graphql/src/gatsby-node.js | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/gatsby-source-graphql/package.json b/packages/gatsby-source-graphql/package.json index a980bc7288e5e..916ad83b40688 100644 --- a/packages/gatsby-source-graphql/package.json +++ b/packages/gatsby-source-graphql/package.json @@ -29,7 +29,7 @@ ], "license": "MIT", "peerDependencies": { - "gatsby": "^2.0.0" + "gatsby": "^2.0.15" }, "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-graphql", "scripts": { diff --git a/packages/gatsby-source-graphql/src/gatsby-node.js b/packages/gatsby-source-graphql/src/gatsby-node.js index 904f672be7577..b7fdec499d1b1 100644 --- a/packages/gatsby-source-graphql/src/gatsby-node.js +++ b/packages/gatsby-source-graphql/src/gatsby-node.js @@ -1,4 +1,3 @@ -const crypto = require(`crypto`) const uuidv4 = require(`uuid/v4`) const { buildSchema, printSchema } = require(`graphql`) const { @@ -29,6 +28,7 @@ exports.sourceNodes = async ( createLink, createSchema, refetchInterval, + createContentDigest, } = options invariant( @@ -80,7 +80,12 @@ exports.sourceNodes = async ( }) const nodeId = createNodeId(`gatsby-source-graphql-${typeName}`) - const node = createSchemaNode({ id: nodeId, typeName, fieldName }) + const node = createSchemaNode({ + id: nodeId, + typeName, + fieldName, + createContentDigest, + }) createNode(node) const resolver = (parent, args, context) => { @@ -112,12 +117,9 @@ exports.sourceNodes = async ( } } -function createSchemaNode({ id, typeName, fieldName }) { +function createSchemaNode({ id, typeName, fieldName, createContentDigest }) { const nodeContent = uuidv4() - const nodeContentDigest = crypto - .createHash(`md5`) - .update(nodeContent) - .digest(`hex`) + const nodeContentDigest = createContentDigest(nodeContent) return { id, typeName: typeName, From f0ad71304ad19a69035fe8b153421f8727bbaaef Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Tue, 2 Apr 2019 20:15:34 +0200 Subject: [PATCH 08/16] :rewind: Revert ":recycle: Update gatsby-transformer-javascript-frontmatter to use createContentDigest helper" This reverts commit 674567701db99e3f269d375890135de0906bf705. --- .../package.json | 2 +- .../src/gatsby-node.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/gatsby-transformer-javascript-frontmatter/package.json b/packages/gatsby-transformer-javascript-frontmatter/package.json index 997d43e0eaa68..a70fecf36c3fc 100644 --- a/packages/gatsby-transformer-javascript-frontmatter/package.json +++ b/packages/gatsby-transformer-javascript-frontmatter/package.json @@ -22,7 +22,7 @@ ], "license": "MIT", "peerDependencies": { - "gatsby": "^2.0.15", + "gatsby": "^2.0.0", "gatsby-source-filesystem": "^2.0.3" }, "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-javascript-frontmatter", diff --git a/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js b/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js index 9c7e25882bff0..cb762e81aaa4a 100644 --- a/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js +++ b/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js @@ -1,14 +1,9 @@ const _ = require(`lodash`) +const crypto = require(`crypto`) const babylon = require(`@babel/parser`) const traverse = require(`@babel/traverse`).default -async function onCreateNode({ - node, - getNode, - actions, - loadNodeContent, - createContentDigest, -}) { +async function onCreateNode({ node, getNode, actions, loadNodeContent }) { const { createNode, createParentChildLink } = actions const fileExtsToProcess = [`js`, `jsx`, `ts`, `tsx`] @@ -112,7 +107,12 @@ async function onCreateNode({ error: error, } - const contentDigest = createContentDigest(node) + const objStr = JSON.stringify(node) + const contentDigest = crypto + .createHash(`md5`) + .update(objStr) + .digest(`hex`) + const nodeData = { id: `${node.id} >>> JavascriptFrontmatter`, children: [], From 59c24ad72670f7d377bbebd3dee4bf2c0ba622d5 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Tue, 2 Apr 2019 21:25:54 +0200 Subject: [PATCH 09/16] :recycle: Update gatsby-transformer-javascript-frontmatter to use createContentDigest helper --- .../package.json | 2 +- .../src/gatsby-node.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/gatsby-transformer-javascript-frontmatter/package.json b/packages/gatsby-transformer-javascript-frontmatter/package.json index a70fecf36c3fc..997d43e0eaa68 100644 --- a/packages/gatsby-transformer-javascript-frontmatter/package.json +++ b/packages/gatsby-transformer-javascript-frontmatter/package.json @@ -22,7 +22,7 @@ ], "license": "MIT", "peerDependencies": { - "gatsby": "^2.0.0", + "gatsby": "^2.0.15", "gatsby-source-filesystem": "^2.0.3" }, "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-javascript-frontmatter", diff --git a/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js b/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js index cb762e81aaa4a..9c7e25882bff0 100644 --- a/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js +++ b/packages/gatsby-transformer-javascript-frontmatter/src/gatsby-node.js @@ -1,9 +1,14 @@ const _ = require(`lodash`) -const crypto = require(`crypto`) const babylon = require(`@babel/parser`) const traverse = require(`@babel/traverse`).default -async function onCreateNode({ node, getNode, actions, loadNodeContent }) { +async function onCreateNode({ + node, + getNode, + actions, + loadNodeContent, + createContentDigest, +}) { const { createNode, createParentChildLink } = actions const fileExtsToProcess = [`js`, `jsx`, `ts`, `tsx`] @@ -107,12 +112,7 @@ async function onCreateNode({ node, getNode, actions, loadNodeContent }) { error: error, } - const objStr = JSON.stringify(node) - const contentDigest = crypto - .createHash(`md5`) - .update(objStr) - .digest(`hex`) - + const contentDigest = createContentDigest(node) const nodeData = { id: `${node.id} >>> JavascriptFrontmatter`, children: [], From b49ee2e01c2cda988f1343c6b82a9307f91bc898 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Tue, 2 Apr 2019 21:47:21 +0200 Subject: [PATCH 10/16] :recycle: Update gatsby-transformer-hjson to use createContentDigest helper --- packages/gatsby-transformer-hjson/package.json | 2 +- .../__tests__/__snapshots__/gatsby-node.js.snap | 12 ++++++------ .../src/__tests__/gatsby-node.js | 4 ++++ .../gatsby-transformer-hjson/src/gatsby-node.js | 15 ++++++++------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/gatsby-transformer-hjson/package.json b/packages/gatsby-transformer-hjson/package.json index 36d5516c3639f..28361fede523a 100644 --- a/packages/gatsby-transformer-hjson/package.json +++ b/packages/gatsby-transformer-hjson/package.json @@ -25,7 +25,7 @@ ], "license": "MIT", "peerDependencies": { - "gatsby": "^2.0.0" + "gatsby": "^2.0.15" }, "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-hjson", "scripts": { diff --git a/packages/gatsby-transformer-hjson/src/__tests__/__snapshots__/gatsby-node.js.snap b/packages/gatsby-transformer-hjson/src/__tests__/__snapshots__/gatsby-node.js.snap index a10b0dc1966cb..c33e479579cc8 100644 --- a/packages/gatsby-transformer-hjson/src/__tests__/__snapshots__/gatsby-node.js.snap +++ b/packages/gatsby-transformer-hjson/src/__tests__/__snapshots__/gatsby-node.js.snap @@ -9,7 +9,7 @@ Array [ "funny": "yup", "id": "foo", "internal": Object { - "contentDigest": "8838e569ae02d98806532310fb2a577a", + "contentDigest": "contentDigest", "type": "FooHJson", }, "parent": "whatever", @@ -28,7 +28,7 @@ Array [ "funny": "yup", "id": "foo", "internal": Object { - "contentDigest": "8838e569ae02d98806532310fb2a577a", + "contentDigest": "contentDigest", "type": "FooHJson", }, "parent": "whatever", @@ -64,7 +64,7 @@ Array [ "funny": "yup", "id": "foo", "internal": Object { - "contentDigest": "8838e569ae02d98806532310fb2a577a", + "contentDigest": "contentDigest", "type": "NodeNameHJson", }, "parent": "whatever", @@ -77,7 +77,7 @@ Array [ "funny": "nope", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "f624311d932d73dcd416d2a8bea2b67d", + "contentDigest": "contentDigest", "type": "NodeNameHJson", }, "parent": "whatever", @@ -96,7 +96,7 @@ Array [ "funny": "yup", "id": "foo", "internal": Object { - "contentDigest": "8838e569ae02d98806532310fb2a577a", + "contentDigest": "contentDigest", "type": "NodeNameHJson", }, "parent": "whatever", @@ -133,7 +133,7 @@ Array [ "funny": "nope", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "f624311d932d73dcd416d2a8bea2b67d", + "contentDigest": "contentDigest", "type": "NodeNameHJson", }, "parent": "whatever", diff --git a/packages/gatsby-transformer-hjson/src/__tests__/gatsby-node.js b/packages/gatsby-transformer-hjson/src/__tests__/gatsby-node.js index 4fff3357b6c3c..c6668c6ca9668 100644 --- a/packages/gatsby-transformer-hjson/src/__tests__/gatsby-node.js +++ b/packages/gatsby-transformer-hjson/src/__tests__/gatsby-node.js @@ -32,12 +32,14 @@ describe(`Process HJSON nodes correctly`, () => { const actions = { createNode, createParentChildLink } const createNodeId = jest.fn() createNodeId.mockReturnValue(`uuid-from-gatsby`) + const createContentDigest = jest.fn().mockReturnValue(`contentDigest`) await onCreateNode({ node, loadNodeContent, actions, createNodeId, + createContentDigest, }).then(() => { expect(createNode.mock.calls).toMatchSnapshot() expect(createParentChildLink.mock.calls).toMatchSnapshot() @@ -56,12 +58,14 @@ describe(`Process HJSON nodes correctly`, () => { const actions = { createNode, createParentChildLink } const createNodeId = jest.fn() createNodeId.mockReturnValue(`uuid-from-gatsby`) + const createContentDigest = jest.fn().mockReturnValue(`contentDigest`) await onCreateNode({ node, loadNodeContent, actions, createNodeId, + createContentDigest, }).then(() => { expect(createNode.mock.calls).toMatchSnapshot() expect(createParentChildLink.mock.calls).toMatchSnapshot() diff --git a/packages/gatsby-transformer-hjson/src/gatsby-node.js b/packages/gatsby-transformer-hjson/src/gatsby-node.js index b300604449e04..ab009bc55b551 100644 --- a/packages/gatsby-transformer-hjson/src/gatsby-node.js +++ b/packages/gatsby-transformer-hjson/src/gatsby-node.js @@ -1,17 +1,18 @@ const _ = require(`lodash`) -const crypto = require(`crypto`) const path = require(`path`) const HJSON = require(`hjson`) -async function onCreateNode({ node, actions, loadNodeContent, createNodeId }) { +async function onCreateNode({ + node, + actions, + loadNodeContent, + createNodeId, + createContentDigest, +}) { const { createNode, createParentChildLink } = actions function transformObject(obj, id, type) { - const objStr = JSON.stringify(obj) - const contentDigest = crypto - .createHash(`md5`) - .update(objStr) - .digest(`hex`) + const contentDigest = createContentDigest(obj) const jsonNode = { ...obj, id, From 3cfd5742b9d40c69adaa26984e04a9170e70ecb2 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Tue, 2 Apr 2019 22:15:32 +0200 Subject: [PATCH 11/16] :recycle: Update gatsby-source-npm-package-search to use createContentDigest helper --- packages/gatsby-source-npm-package-search/package.json | 2 +- .../gatsby-source-npm-package-search/src/gatsby-node.js | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/gatsby-source-npm-package-search/package.json b/packages/gatsby-source-npm-package-search/package.json index 2ee78b971214f..f6b270fa37977 100644 --- a/packages/gatsby-source-npm-package-search/package.json +++ b/packages/gatsby-source-npm-package-search/package.json @@ -20,7 +20,7 @@ "license": "MIT", "main": "index.js", "peerDependencies": { - "gatsby": "^2.0.0" + "gatsby": "^2.0.15" }, "scripts": { "build": "babel src --out-dir . --ignore **/__tests__", diff --git a/packages/gatsby-source-npm-package-search/src/gatsby-node.js b/packages/gatsby-source-npm-package-search/src/gatsby-node.js index 13606aef3a41b..590a55fc154c1 100644 --- a/packages/gatsby-source-npm-package-search/src/gatsby-node.js +++ b/packages/gatsby-source-npm-package-search/src/gatsby-node.js @@ -1,15 +1,8 @@ const algoliasearch = require(`algoliasearch`) -const crypto = require(`crypto`) const client = algoliasearch(`OFCNCOG2CU`, `6fbcaeafced8913bf0e4d39f0b541957`) var index = client.initIndex(`npm-search`) -const createContentDigest = obj => - crypto - .createHash(`md5`) - .update(JSON.stringify(obj)) - .digest(`hex`) - function browse({ index, ...params }) { let hits = [] const browser = index.browseAll(params) @@ -22,7 +15,7 @@ function browse({ index, ...params }) { } exports.sourceNodes = async ( - { boundActionCreators, createNodeId }, + { boundActionCreators, createNodeId, createContentDigest }, { keywords } ) => { const { createNode } = boundActionCreators From 4d8cf40bcfbfbb13df0f95ff0d190c4529b1dfb3 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Wed, 3 Apr 2019 13:49:20 +0200 Subject: [PATCH 12/16] :recycle: Update gatsby-source-lever to use createContentDigest helper --- packages/gatsby-source-lever/package.json | 2 +- .../__tests__/__snapshots__/normalize.js.snap | 38 +++++++++---------- .../src/__tests__/normalize.js | 7 +++- .../gatsby-source-lever/src/gatsby-node.js | 8 +++- packages/gatsby-source-lever/src/normalize.js | 8 +++- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/packages/gatsby-source-lever/package.json b/packages/gatsby-source-lever/package.json index 70d43edeb0ff2..10b7b8da16199 100644 --- a/packages/gatsby-source-lever/package.json +++ b/packages/gatsby-source-lever/package.json @@ -31,7 +31,7 @@ ], "license": "MIT", "peerDependencies": { - "gatsby": "^2.0.0" + "gatsby": "^2.0.15" }, "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-lever", "scripts": { diff --git a/packages/gatsby-source-lever/src/__tests__/__snapshots__/normalize.js.snap b/packages/gatsby-source-lever/src/__tests__/__snapshots__/normalize.js.snap index ff278de7ac887..77fc3d34daedc 100644 --- a/packages/gatsby-source-lever/src/__tests__/__snapshots__/normalize.js.snap +++ b/packages/gatsby-source-lever/src/__tests__/__snapshots__/normalize.js.snap @@ -2749,7 +2749,7 @@ Lever’s Sales organization is a tight-knit team with diverse backgrounds--we "hostedUrl": "https://jobs.lever.co/lever/4432ed35-6f71-4ea4-b802-f99af29d71b6", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "6afa157457057c1a22bdec0e27495a3b", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "4432ed35-6f71-4ea4-b802-f99af29d71b6", @@ -2798,7 +2798,7 @@ JavaScript, Node.js, MongoDB, Redis, Elasticsearch, DerbyJS, ShareDB, IMAP, SMTP "hostedUrl": "https://jobs.lever.co/lever/7ab138b0-b5c8-425d-93ae-2fc2b051bc0e", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "9aa12a00f412e84623d60e8e3c9a892b", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "7ab138b0-b5c8-425d-93ae-2fc2b051bc0e", @@ -2859,7 +2859,7 @@ Lever’s Sales organization is a tight-knit team with diverse backgrounds--we "hostedUrl": "https://jobs.lever.co/lever/182706ef-d98a-46ad-92bb-b7cddeb58419", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "6b8dea31eee4d6d49b08bddeb2ecbba0", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "182706ef-d98a-46ad-92bb-b7cddeb58419", @@ -2921,7 +2921,7 @@ Please note, this role is on-site and located in San Francisco, California. "hostedUrl": "https://jobs.lever.co/lever/8ef9f55b-1ca0-4c2b-b85d-56613d397098", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "ba7357d3b7205aab95fea87f486a0b8b", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "8ef9f55b-1ca0-4c2b-b85d-56613d397098", @@ -2978,7 +2978,7 @@ Our next coworker is hands-on, collaborative, self-motivated, analytical, and pa "hostedUrl": "https://jobs.lever.co/lever/b8093a5d-46e5-4470-be07-16759ccaae14", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "0211574c85e985208d118544e4921e69", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "b8093a5d-46e5-4470-be07-16759ccaae14", @@ -3031,7 +3031,7 @@ You’re a fantastic listener, solutions oriented, and a problem-solver at heart "hostedUrl": "https://jobs.lever.co/lever/4d23b480-37c7-4f87-890e-13bde50c52a2", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "84aab21e7d760d53bed9de4433698945", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "4d23b480-37c7-4f87-890e-13bde50c52a2", @@ -3087,7 +3087,7 @@ As an engineering manager, you’ll lead a team of product developers as they bu "hostedUrl": "https://jobs.lever.co/lever/37c2fb0d-03ef-4c7d-a6b0-cac02488f53b", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "a89df3d73afb0f6f65a6f690ae30c777", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "37c2fb0d-03ef-4c7d-a6b0-cac02488f53b", @@ -3146,7 +3146,7 @@ Lever’s Sales team is a tight-knit and rapidly growing team with diverse backg "hostedUrl": "https://jobs.lever.co/lever/6e55f2fc-7a4e-42c9-ab5e-775fbc7b126a", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "f6fb7d85df782b4eff5085a7496bbe4e", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "6e55f2fc-7a4e-42c9-ab5e-775fbc7b126a", @@ -3191,7 +3191,7 @@ This role is perfect for someone that enjoys challenging tasks, working on many "hostedUrl": "https://jobs.lever.co/lever/62fbd830-e891-45fc-a8d6-8849a888b697", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "cbe4c334650ce99b5813094d6e80a006", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "62fbd830-e891-45fc-a8d6-8849a888b697", @@ -3246,7 +3246,7 @@ Lever’s Sales team is a tight-knit team with diverse backgrounds--we’re seas "hostedUrl": "https://jobs.lever.co/lever/4c5c5337-6a44-4c7c-80ae-3aeceb4603a0", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "c4d6b23a78da7bbe549ecec92e8459d4", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "4c5c5337-6a44-4c7c-80ae-3aeceb4603a0", @@ -3312,7 +3312,7 @@ Learn more about Lever’s interview process and read about what our engineering "hostedUrl": "https://jobs.lever.co/lever/befa0df5-da1f-4c11-adc2-d3eb2fa189da", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "68a44303a59c8e2e6296c959af1e314a", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "befa0df5-da1f-4c11-adc2-d3eb2fa189da", @@ -3368,7 +3368,7 @@ This is an opportunity for someone who wants to be part of something big and tra "hostedUrl": "https://jobs.lever.co/lever/f366f610-1af4-43c1-9213-9c39830a715f", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "96729eb3a7c40a9a30137fe1adbab65a", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "f366f610-1af4-43c1-9213-9c39830a715f", @@ -3429,7 +3429,7 @@ Lever’s Sales team is a tight-knit and rapidly growing team with diverse backg "hostedUrl": "https://jobs.lever.co/lever/0a28373c-4b92-4c6e-a6d1-d4654a89329e", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "f912357bbad60de2ca4a4dbfb4302263", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "0a28373c-4b92-4c6e-a6d1-d4654a89329e", @@ -3475,7 +3475,7 @@ We’re building a world-class product-first organization and assembling the rig "hostedUrl": "https://jobs.lever.co/lever/85df11e0-5aad-4fa4-9238-d07b506f9a07", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "ca1af348b856a922e3938df88d11575f", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "85df11e0-5aad-4fa4-9238-d07b506f9a07", @@ -3534,7 +3534,7 @@ From day one as a Leveroo, you'll be an active contributor to the Lever culture "hostedUrl": "https://jobs.lever.co/lever/c4b1635e-b308-4c8b-b2ca-1b536a7726ad", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "d674452420791401cd90cc2e44675dd3", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "c4b1635e-b308-4c8b-b2ca-1b536a7726ad", @@ -3596,7 +3596,7 @@ Lever’s Sales Development team is a tight-knit team with diverse backgrounds-- "hostedUrl": "https://jobs.lever.co/lever/bc6bd95d-262a-460c-b6dc-6b4d46cf6927", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "9a856a9d4a078a3fef16bf2af5df66ba", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "bc6bd95d-262a-460c-b6dc-6b4d46cf6927", @@ -3646,7 +3646,7 @@ Lever’s Sales Development team is a tight-knit team with diverse backgrounds-- "hostedUrl": "https://jobs.lever.co/lever/ba77c5e6-2f6c-4ee7-b37b-09dc02b3395f", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "b0445f8ba1213c5f845587958da3545a", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "ba77c5e6-2f6c-4ee7-b37b-09dc02b3395f", @@ -3695,7 +3695,7 @@ In terms of what we’re looking for, past tenure at a hyper-growth startup is i "hostedUrl": "https://jobs.lever.co/lever/7f673706-37a2-4386-bee5-bd2892bc0cfc", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "f8b43fa0ad69c3201c5ab2b1669999f5", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "7f673706-37a2-4386-bee5-bd2892bc0cfc", @@ -3749,7 +3749,7 @@ We’re looking for you to be as maniacal about Finance as we are about hiring ( "hostedUrl": "https://jobs.lever.co/lever/0a47a57c-a05a-48b3-90ec-2caca6d2807b", "id": "uuid-from-gatsby", "internal": Object { - "contentDigest": "6a0ba5304335497cd7056fdcd0bc568d", + "contentDigest": "contentDigest", "type": "lever", }, "lever_id": "0a47a57c-a05a-48b3-90ec-2caca6d2807b", diff --git a/packages/gatsby-source-lever/src/__tests__/normalize.js b/packages/gatsby-source-lever/src/__tests__/normalize.js index aa976b2abade5..4d8e5c3cec8df 100644 --- a/packages/gatsby-source-lever/src/__tests__/normalize.js +++ b/packages/gatsby-source-lever/src/__tests__/normalize.js @@ -22,7 +22,12 @@ describe(`Process Lever data`, () => { }) it(`creates nodes for each entry`, () => { const createNode = jest.fn() - normalize.createNodesFromEntities({ entities, createNode }) + const createContentDigest = jest.fn().mockReturnValue(`contentDigest`) + normalize.createNodesFromEntities({ + entities, + createNode, + createContentDigest, + }) expect(createNode.mock.calls).toMatchSnapshot() }) }) diff --git a/packages/gatsby-source-lever/src/gatsby-node.js b/packages/gatsby-source-lever/src/gatsby-node.js index afac68c621408..ce6a70b8d2add 100644 --- a/packages/gatsby-source-lever/src/gatsby-node.js +++ b/packages/gatsby-source-lever/src/gatsby-node.js @@ -4,7 +4,7 @@ const normalize = require(`./normalize`) const typePrefix = `lever__` exports.sourceNodes = async ( - { actions, getNode, store, cache, createNodeId }, + { actions, getNode, store, cache, createNodeId, createContentDigest }, { site, verboseOutput } ) => { const { createNode } = actions @@ -30,7 +30,11 @@ exports.sourceNodes = async ( entities = normalize.createGatsbyIds(createNodeId, entities) // creates nodes for each entry - normalize.createNodesFromEntities({ entities, createNode }) + normalize.createNodesFromEntities({ + entities, + createNode, + createContentDigest, + }) return } diff --git a/packages/gatsby-source-lever/src/normalize.js b/packages/gatsby-source-lever/src/normalize.js index b9aaa4cb58b9a..41dd83dd9263b 100644 --- a/packages/gatsby-source-lever/src/normalize.js +++ b/packages/gatsby-source-lever/src/normalize.js @@ -133,7 +133,11 @@ exports.createGatsbyIds = (createNodeId, entities) => return e }) -exports.createNodesFromEntities = ({ entities, createNode }) => { +exports.createNodesFromEntities = ({ + entities, + createNode, + createContentDigest, +}) => { entities.forEach(e => { let { ...entity } = e let node = { @@ -142,7 +146,7 @@ exports.createNodesFromEntities = ({ entities, createNode }) => { children: [], internal: { type: `lever`, - contentDigest: digest(JSON.stringify(entity)), + contentDigest: createContentDigest(entity), }, } createNode(node) From 72a66261e21a88f2172aeb1ecb682a15d4880948 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Wed, 3 Apr 2019 14:23:34 +0200 Subject: [PATCH 13/16] :recycle: Update gatsby-transformer-javascript-static-exports to use createContentDigest helper --- .../package.json | 2 +- .../src/gatsby-node.js | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/gatsby-transformer-javascript-static-exports/package.json b/packages/gatsby-transformer-javascript-static-exports/package.json index 6694c86e36bf8..a3599812f6a9f 100644 --- a/packages/gatsby-transformer-javascript-static-exports/package.json +++ b/packages/gatsby-transformer-javascript-static-exports/package.json @@ -26,7 +26,7 @@ ], "license": "MIT", "peerDependencies": { - "gatsby": "^2.0.0" + "gatsby": "^2.0.15" }, "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-javascript-static-exports", "scripts": { diff --git a/packages/gatsby-transformer-javascript-static-exports/src/gatsby-node.js b/packages/gatsby-transformer-javascript-static-exports/src/gatsby-node.js index 41532df6b4a7d..3ff8d86825258 100644 --- a/packages/gatsby-transformer-javascript-static-exports/src/gatsby-node.js +++ b/packages/gatsby-transformer-javascript-static-exports/src/gatsby-node.js @@ -1,5 +1,4 @@ const _ = require(`lodash`) -const crypto = require(`crypto`) const babylon = require(`@babel/parser`) const traverse = require(`@babel/traverse`).default @@ -9,6 +8,7 @@ async function onCreateNode({ actions, loadNodeContent, createNodeId, + createContentDigest, }) { const { createNode, createParentChildLink } = actions @@ -126,12 +126,7 @@ async function onCreateNode({ }, } } finally { - const objStr = JSON.stringify(node) - const contentDigest = crypto - .createHash(`md5`) - .update(objStr) - .digest(`hex`) - + const contentDigest = createContentDigest(node) const nodeData = { id: createNodeId(`${node.id} >>> JSFrontmatter`), children: [], From 0c17f36167c38139290e5ed95793f385c27d27c8 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Wed, 3 Apr 2019 14:42:32 +0200 Subject: [PATCH 14/16] :recycle: Update gatsby-transformer-react-docgen to use createContentDigest helper --- .../package.json | 2 +- .../src/__tests__/on-node-create.js | 7 ++- .../src/on-node-create.js | 52 +++++++++++++------ 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/packages/gatsby-transformer-react-docgen/package.json b/packages/gatsby-transformer-react-docgen/package.json index f2b5370f2c143..577321278712d 100644 --- a/packages/gatsby-transformer-react-docgen/package.json +++ b/packages/gatsby-transformer-react-docgen/package.json @@ -31,7 +31,7 @@ "license": "MIT", "main": "index.js", "peerDependencies": { - "gatsby": "^2.0.0" + "gatsby": "^2.0.15" }, "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-react-docgen", "scripts": { diff --git a/packages/gatsby-transformer-react-docgen/src/__tests__/on-node-create.js b/packages/gatsby-transformer-react-docgen/src/__tests__/on-node-create.js index ac7e574523ee6..10e43a88003ff 100644 --- a/packages/gatsby-transformer-react-docgen/src/__tests__/on-node-create.js +++ b/packages/gatsby-transformer-react-docgen/src/__tests__/on-node-create.js @@ -16,17 +16,20 @@ describe(`transformer-react-doc-gen: onCreateNode`, () => { let loadNodeContent, actions, node, createdNodes, updatedNodes const createNodeId = jest.fn() createNodeId.mockReturnValue(`uuid-from-gatsby`) - let run = (node, opts = {}) => - onCreateNode( + let run = (node, opts = {}) => { + const createContentDigest = jest.fn().mockReturnValue(`contentDigest`) + return onCreateNode( { node, loadNodeContent, actions, createNodeId, reporter: { error: console.error }, + createContentDigest, }, opts ) + } let consoleError beforeEach(() => { diff --git a/packages/gatsby-transformer-react-docgen/src/on-node-create.js b/packages/gatsby-transformer-react-docgen/src/on-node-create.js index 782b5f581bc74..5fd67f91ecd68 100644 --- a/packages/gatsby-transformer-react-docgen/src/on-node-create.js +++ b/packages/gatsby-transformer-react-docgen/src/on-node-create.js @@ -1,12 +1,5 @@ -import crypto from "crypto" import parseMetadata from "./parse" -const digest = str => - crypto - .createHash(`md5`) - .update(str) - .digest(`hex`) - const propsId = (parentId, name) => `${parentId}--ComponentProp-${name}` const descId = parentId => `${parentId}--ComponentDescription` @@ -23,7 +16,13 @@ function canParse(node) { ) } -function createDescriptionNode(node, entry, actions, createNodeId) { +function createDescriptionNode( + node, + entry, + actions, + createNodeId, + createContentDigest +) { if (!entry.description) return node const { createNode } = actions @@ -36,7 +35,7 @@ function createDescriptionNode(node, entry, actions, createNodeId) { type: `ComponentDescription`, mediaType: `text/markdown`, content: entry.description, - contentDigest: digest(entry.description), + contentDigest: createContentDigest(entry.description), }, } @@ -47,7 +46,13 @@ function createDescriptionNode(node, entry, actions, createNodeId) { return node } -function createPropNodes(node, component, actions, createNodeId) { +function createPropNodes( + node, + component, + actions, + createNodeId, + createContentDigest +) { const { createNode } = actions let children = new Array(component.props.length) @@ -63,11 +68,17 @@ function createPropNodes(node, component, actions, createNodeId) { parentType: prop.type, internal: { type: `ComponentProp`, - contentDigest: digest(content), + contentDigest: createContentDigest(content), }, } children[i] = propNode.id - propNode = createDescriptionNode(propNode, prop, actions, createNodeId) + propNode = createDescriptionNode( + propNode, + prop, + actions, + createNodeId, + createContentDigest + ) createNode(propNode) }) @@ -77,7 +88,14 @@ function createPropNodes(node, component, actions, createNodeId) { } export default async function onCreateNode( - { node, loadNodeContent, actions, createNodeId, reporter }, + { + node, + loadNodeContent, + actions, + createNodeId, + reporter, + createContentDigest, + }, pluginOptions ) { const { createNode, createParentChildLink } = actions @@ -101,7 +119,7 @@ export default async function onCreateNode( components.forEach(component => { const strContent = JSON.stringify(component) - const contentDigest = digest(strContent) + const contentDigest = createContentDigest(strContent) const nodeId = `${node.id}--${component.displayName}--ComponentMetadata` let metadataNode = { @@ -121,13 +139,15 @@ export default async function onCreateNode( metadataNode, component, actions, - createNodeId + createNodeId, + createContentDigest ) metadataNode = createDescriptionNode( metadataNode, component, actions, - createNodeId + createNodeId, + createContentDigest ) createNode(metadataNode) }) From 22be38fc6288d3fd011631ace06eb20f92f7abed Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Fri, 5 Apr 2019 14:25:45 +0200 Subject: [PATCH 15/16] :white_check_mark: Fix merge error --- .../src/__tests__/on-node-create.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-transformer-react-docgen/src/__tests__/on-node-create.js b/packages/gatsby-transformer-react-docgen/src/__tests__/on-node-create.js index 7650e0bc0b48e..b4f0ce780b623 100644 --- a/packages/gatsby-transformer-react-docgen/src/__tests__/on-node-create.js +++ b/packages/gatsby-transformer-react-docgen/src/__tests__/on-node-create.js @@ -17,9 +17,9 @@ describe(`transformer-react-doc-gen: onCreateNode`, () => { const createNodeId = jest.fn() createNodeId.mockReturnValue(`uuid-from-gatsby`) - let run = (node, opts) => { + let run = (node, opts = {}) => { const createContentDigest = jest.fn().mockReturnValue(`contentDigest`) - onCreateNode( + return onCreateNode( { node, loadNodeContent, From f6a71b2e4189cc2ad22fdda622a60b0a63de2ba6 Mon Sep 17 00:00:00 2001 From: FRIN Yvonnick Date: Fri, 5 Apr 2019 14:30:18 +0200 Subject: [PATCH 16/16] :ok_hand: Take care of @muescha review --- packages/gatsby-source-lever/src/normalize.js | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/packages/gatsby-source-lever/src/normalize.js b/packages/gatsby-source-lever/src/normalize.js index 41dd83dd9263b..80d59e1d80c82 100644 --- a/packages/gatsby-source-lever/src/normalize.js +++ b/packages/gatsby-source-lever/src/normalize.js @@ -1,22 +1,9 @@ -const crypto = require(`crypto`) const deepMapKeys = require(`deep-map-keys`) -const stringify = require(`json-stringify-safe`) const conflictFieldPrefix = `lever_` // restrictedNodeFields from here https://www.gatsbyjs.org/docs/node-interface/ const restrictedNodeFields = [`id`, `children`, `parent`, `fields`, `internal`] -/** - * Encrypts a String using md5 hash of hexadecimal digest. - * - * @param {any} str - */ -const digest = str => - crypto - .createHash(`md5`) - .update(str) - .digest(`hex`) - /** * Create the Graph QL Node * @@ -24,7 +11,14 @@ const digest = str => * @param {any} type * @param {any} createNode */ -async function createGraphQLNode(ent, type, createNode, store, cache) { +async function createGraphQLNode( + ent, + type, + createNode, + store, + cache, + createContentDigest +) { let id = !ent.id ? (!ent.ID ? 0 : ent.ID) : ent.id let node = { id: `${type}_${id.toString()}`, @@ -36,7 +30,7 @@ async function createGraphQLNode(ent, type, createNode, store, cache) { } node = recursiveAddFields(ent, node) node.internal.content = JSON.stringify(node) - node.internal.contentDigest = digest(stringify(node)) + node.internal.contentDigest = createContentDigest(node) createNode(node) } exports.createGraphQLNode = createGraphQLNode