Skip to content

Commit

Permalink
Revert "chore(*): Use new createContentDigest helper (gatsbyjs#8992)" (
Browse files Browse the repository at this point in the history
…gatsbyjs#13568)

This reverts commit c91d110.
  • Loading branch information
KyleAMathews authored and pieh committed Apr 23, 2019
1 parent 7793803 commit b800945
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 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 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 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

0 comments on commit b800945

Please sign in to comment.