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: [],