Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore(*): Use new createContentDigest helper #13000

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
747ab8f
:recycle: Update gatsby-source-hacker-news to use createContentDigest…
frinyvonnick Apr 1, 2019
19615ba
:recycle: Update gatsby-transformer-excel to use createContentDigest …
frinyvonnick Apr 1, 2019
cc74c5e
:recycle: Update gatsby-source-wikipedia to use createContentDigest h…
frinyvonnick Apr 2, 2019
a7b96d3
:recycle: Update gatsby-source-wordpress to use createContentDigest h…
frinyvonnick Apr 2, 2019
20aa065
:pencil2: Fix typo in function name
frinyvonnick Apr 2, 2019
6745677
:recycle: Update gatsby-transformer-javascript-frontmatter to use cre…
frinyvonnick Apr 2, 2019
8e2b081
:recycle: Update gatsby-source-graphql to use createContentDigest helper
frinyvonnick Apr 2, 2019
f0ad713
:rewind: Revert ":recycle: Update gatsby-transformer-javascript-front…
frinyvonnick Apr 2, 2019
59c24ad
:recycle: Update gatsby-transformer-javascript-frontmatter to use cre…
frinyvonnick Apr 2, 2019
b49ee2e
:recycle: Update gatsby-transformer-hjson to use createContentDigest …
frinyvonnick Apr 2, 2019
3cfd574
:recycle: Update gatsby-source-npm-package-search to use createConten…
frinyvonnick Apr 2, 2019
4d8cf40
:recycle: Update gatsby-source-lever to use createContentDigest helper
frinyvonnick Apr 3, 2019
72a6626
:recycle: Update gatsby-transformer-javascript-static-exports to use …
frinyvonnick Apr 3, 2019
0c17f36
:recycle: Update gatsby-transformer-react-docgen to use createContent…
frinyvonnick Apr 3, 2019
8075605
:twisted_rightwards_arrows: Merge remote-tracking branch 'upstream/ma…
frinyvonnick Apr 3, 2019
22be38f
:white_check_mark: Fix merge error
frinyvonnick Apr 5, 2019
f6a71b2
:ok_hand: Take care of @muescha review
frinyvonnick Apr 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gatsby-source-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
16 changes: 9 additions & 7 deletions packages/gatsby-source-graphql/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const crypto = require(`crypto`)
const uuidv4 = require(`uuid/v4`)
const { buildSchema, printSchema } = require(`graphql`)
const {
Expand Down Expand Up @@ -29,6 +28,7 @@ exports.sourceNodes = async (
createLink,
createSchema,
refetchInterval,
createContentDigest,
} = options

invariant(
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-hacker-news/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 3 additions & 11 deletions packages/gatsby-source-hacker-news/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const axios = require(`axios`)
const crypto = require(`crypto`)
const url = require(`url`)
const _ = require(`lodash`)

Expand All @@ -13,6 +12,7 @@ exports.sourceNodes = async ({
getNode,
createNodeId,
hasNodeChanged,
createContentDigest,
}) => {
const { createNode } = actions

Expand Down Expand Up @@ -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)

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-lever/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion packages/gatsby-source-lever/src/__tests__/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down
8 changes: 6 additions & 2 deletions packages/gatsby-source-lever/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
8 changes: 6 additions & 2 deletions packages/gatsby-source-lever/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -142,7 +146,7 @@ exports.createNodesFromEntities = ({ entities, createNode }) => {
children: [],
internal: {
type: `lever`,
contentDigest: digest(JSON.stringify(entity)),
contentDigest: createContentDigest(entity),
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
},
}
createNode(node)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-npm-package-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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__",
Expand Down
9 changes: 1 addition & 8 deletions packages/gatsby-source-npm-package-search/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -22,7 +15,7 @@ function browse({ index, ...params }) {
}

exports.sourceNodes = async (
{ boundActionCreators, createNodeId },
{ boundActionCreators, createNodeId, createContentDigest },
{ keywords }
) => {
const { createNode } = boundActionCreators
Expand Down
10 changes: 5 additions & 5 deletions packages/gatsby-source-wikipedia/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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 =>
Expand All @@ -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)
})
)
Expand Down
Loading