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

Revert "chore(*): Use new createContentDigest helper (#8992)" #13568

Merged
merged 1 commit into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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-filesystem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
],
"license": "MIT",
"peerDependencies": {
"gatsby": "^2.0.15"
"gatsby": "^2.0.0"
},
"repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-filesystem",
"scripts": {
Expand Down
12 changes: 7 additions & 5 deletions packages/gatsby-source-filesystem/src/create-file-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const mime = require(`mime`)
const prettyBytes = require(`pretty-bytes`)

const md5File = require(`bluebird`).promisify(require(`md5-file`))
const { createContentDigest } = require(`gatsby/utils`)
const crypto = require(`crypto`)

exports.createFileNode = async (
pathToFile,
Expand All @@ -27,10 +27,12 @@ exports.createFileNode = async (
const stats = await fs.stat(slashedFile.absolutePath)
let internal
if (stats.isDirectory()) {
const contentDigest = createContentDigest({
stats: stats,
absolutePath: slashedFile.absolutePath,
})
const contentDigest = crypto
.createHash(`md5`)
.update(
JSON.stringify({ stats: stats, absolutePath: slashedFile.absolutePath })
)
.digest(`hex`)
internal = {
contentDigest,
type: `Directory`,
Expand Down
22 changes: 20 additions & 2 deletions packages/gatsby-source-filesystem/src/create-remote-file-node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require(`fs-extra`)
const got = require(`got`)
const { createContentDigest } = require(`gatsby/utils`)
const crypto = require(`crypto`)
const path = require(`path`)
const { isWebUri } = require(`valid-url`)
const Queue = require(`better-queue`)
Expand Down Expand Up @@ -53,6 +53,24 @@ const bar = new ProgressBar(
* @param {Auth} [options.auth]
*/

/*********
* utils *
*********/

/**
* createHash
* --
*
* Create an md5 hash of the given str
* @param {Stringq} str
* @return {String}
*/
const createHash = str =>
crypto
.createHash(`md5`)
.update(str)
.digest(`hex`)

const CACHE_DIR = `.cache`
const FS_PLUGIN_DIR = `gatsby-source-filesystem`

Expand Down Expand Up @@ -197,7 +215,7 @@ async function processRemoteNode({
}

// Create the temp and permanent file names for the url.
const digest = createContentDigest(url)
const digest = createHash(url)
if (!name) {
name = getRemoteFileName(url)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { graphql } = require(`gatsby/graphql`)
const { onCreateNode } = require(`../gatsby-node`)
const extendNodeType = require(`../extend-node-type`)
const { createContentDigest } = require(`gatsby/utils`)

// given a set of nodes and a query, return the result of the query
async function queryResult(
Expand Down Expand Up @@ -105,7 +104,6 @@ const bootstrapTest = (
loadNodeContent,
actions,
createNodeId,
createContentDigest,
},
{ ...additionalParameters, ...pluginOptions }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const _ = require(`lodash`)
const onCreateNode = require(`../on-node-create`)
const { graphql } = require(`gatsby/graphql`)

const { createContentDigest } = require(`gatsby/utils`)

let node
let actions
let createNodeId
Expand Down Expand Up @@ -40,7 +38,6 @@ Where oh where is my little pony?
loadNodeContent,
actions,
createNodeId,
createContentDigest,
}).then(() => {
expect(actions.createNode.mock.calls).toMatchSnapshot()
expect(
Expand Down Expand Up @@ -78,7 +75,6 @@ Sed bibendum sem iaculis, pellentesque leo sed, imperdiet ante. Sed consequat ma
loadNodeContent,
actions,
createNodeId,
createContentDigest,
},
{ excerpt_separator: `<!-- end -->` }
).then(() => {
Expand Down Expand Up @@ -110,7 +106,6 @@ yadda yadda
actions,
createNodeId,
loadNodeContent,
createContentDigest,
})

expect(parsed.frontmatter.date).toEqual(new Date(date).toJSON())
Expand Down Expand Up @@ -212,7 +207,6 @@ In quis lectus sed eros efficitur luctus. Morbi tempor, nisl eget feugiat tincid
loadNodeContent,
actions,
createNodeId,
createContentDigest,
},
{ excerpt_separator: `<!-- end -->` }
)
Expand Down Expand Up @@ -267,7 +261,6 @@ Sed bibendum sem iaculis, pellentesque leo sed, imperdiet ante. Sed consequat ma
loadNodeContent,
actions,
createNodeId,
createContentDigest,
})
})
})
Expand Down
15 changes: 6 additions & 9 deletions packages/gatsby-transformer-remark/src/on-node-create.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
const grayMatter = require(`gray-matter`)
const crypto = require(`crypto`)
const _ = require(`lodash`)

module.exports = async function onCreateNode(
{
node,
loadNodeContent,
actions,
createNodeId,
reporter,
createContentDigest,
},
{ node, loadNodeContent, actions, createNodeId, reporter },
pluginOptions
) {
const { createNode, createParentChildLink } = actions
Expand Down Expand Up @@ -59,7 +53,10 @@ module.exports = async function onCreateNode(
markdownNode.fileAbsolutePath = node.absolutePath
}

markdownNode.internal.contentDigest = createContentDigest(markdownNode)
markdownNode.internal.contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(markdownNode))
.digest(`hex`)

createNode(markdownNode)
createParentChildLink({ parent: node, child: markdownNode })
Expand Down
1 change: 0 additions & 1 deletion packages/gatsby/utils.js

This file was deleted.