Skip to content

Commit

Permalink
chore: Use createContentDigest helper (gatsbyjs#20239)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthachatterjee committed Jan 8, 2020
1 parent 5bbad52 commit ead08cc
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 29 deletions.
8 changes: 2 additions & 6 deletions packages/gatsby-plugin-mdx/gatsby/on-create-node.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
const fs = require(`fs`)
const path = require(`path`)
const crypto = require(`crypto`)
const babel = require(`@babel/core`)
const { createContentDigest } = require(`gatsby-core-utils`)

const defaultOptions = require(`../utils/default-options`)
const createMDXNode = require(`../utils/create-mdx-node`)
const { MDX_SCOPES_LOCATION } = require(`../constants`)
const genMDX = require(`../utils/gen-mdx`)

const contentDigest = val =>
crypto
.createHash(`md5`)
.update(val)
.digest(`hex`)
const contentDigest = val => createContentDigest(val)

module.exports = async (
{
Expand Down
14 changes: 5 additions & 9 deletions packages/gatsby-plugin-mdx/utils/create-fake-file-node.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { slash } = require(`gatsby-core-utils`)
const { slash, createContentDigest } = require(`gatsby-core-utils`)
const path = require(`path`)
const fs = require(`fs`)
const mime = require(`mime`)
const prettyBytes = require(`pretty-bytes`)
const crypto = require(`crypto`)
const md5File = require(`md5-file`)

exports.createFileNode = async (
Expand All @@ -26,14 +25,11 @@ exports.createFileNode = async (
const stats = fs.statSync(slashedFile.absolutePath)
let internal
if (stats.isDirectory()) {
const contentDigest = crypto
.createHash(`md5`)
.update(
JSON.stringify({ stats: stats, absolutePath: slashedFile.absolutePath })
)
.digest(`hex`)
internal = {
contentDigest,
contentDigest: createContentDigest({
stats: stats,
absolutePath: slashedFile.absolutePath,
}),
type: `Directory`,
description: `Directory "${path.relative(process.cwd(), slashed)}"`,
}
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-source-contentful/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"contentful": "^6.1.3",
"deep-map": "^1.5.0",
"fs-extra": "^8.1.0",
"gatsby-core-utils": "^1.0.25",
"gatsby-plugin-sharp": "^2.3.10",
"gatsby-source-filesystem": "^2.1.43",
"is-online": "^8.2.1",
Expand Down
8 changes: 2 additions & 6 deletions packages/gatsby-source-contentful/src/normalize.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const _ = require(`lodash`)
const crypto = require(`crypto`)
const stringify = require(`json-stringify-safe`)
const { createContentDigest } = require(`gatsby-core-utils`)

const digest = str =>
crypto
.createHash(`md5`)
.update(str)
.digest(`hex`)
const digest = str => createContentDigest(str)
const typePrefix = `Contentful`
const makeTypeName = type => _.upperFirst(_.camelCase(`${typePrefix} ${type}`))

Expand Down
8 changes: 2 additions & 6 deletions packages/gatsby-theme-blog-core/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const fs = require(`fs`)
const path = require(`path`)
const mkdirp = require(`mkdirp`)
const crypto = require(`crypto`)
const Debug = require(`debug`)
const { createFilePath } = require(`gatsby-source-filesystem`)
const { urlResolve } = require(`gatsby-core-utils`)
const { urlResolve, createContentDigest } = require(`gatsby-core-utils`)

const debug = Debug(`gatsby-theme-blog-core`)
const withDefaults = require(`./utils/default-options`)
Expand Down Expand Up @@ -148,10 +147,7 @@ exports.onCreateNode = async (
children: [],
internal: {
type: `MdxBlogPost`,
contentDigest: crypto
.createHash(`md5`)
.update(JSON.stringify(fieldData))
.digest(`hex`),
contentDigest: createContentDigest(fieldData),
content: JSON.stringify(fieldData),
description: `Mdx implementation of the BlogPost interface`,
},
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-theme-blog-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"@mdx-js/mdx": "^1.5.1",
"gatsby-core-utils": "^1.0.25",
"gatsby-plugin-mdx": "^1.0.64",
"gatsby-plugin-sharp": "^2.3.10",
"gatsby-remark-copy-linked-files": "^2.1.33",
Expand Down
23 changes: 21 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21936,7 +21936,7 @@ type-of@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/type-of/-/type-of-2.0.1.tgz#e72a1741896568e9f628378d816d6912f7f23972"

typedarray-to-buffer@~3.1.5:
typedarray-to-buffer@^3.1.5, typedarray-to-buffer@~3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"
integrity sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==
Expand Down Expand Up @@ -23371,7 +23371,7 @@ wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"

write-file-atomic@2.4.1, write-file-atomic@^2.0.0, write-file-atomic@^2.3.0, write-file-atomic@^2.4.2, write-file-atomic@^3.0.0:
write-file-atomic@2.4.1, write-file-atomic@^2.0.0, write-file-atomic@^2.3.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-2.4.1.tgz#d0b05463c188ae804396fd5ab2a370062af87529"
integrity sha512-TGHFeZEZMnv+gBFRfjAcxL5bPHrsGKtnb4qsFAws7/vlh+QfwAaySIw4AXP9ZskTTh5GWu3FLuJhsWVdiJPGvg==
Expand All @@ -23380,6 +23380,25 @@ write-file-atomic@2.4.1, write-file-atomic@^2.0.0, write-file-atomic@^2.3.0, wri
imurmurhash "^0.1.4"
signal-exit "^3.0.2"

write-file-atomic@^2.4.2:
version "2.4.3"
resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-2.4.3.tgz#1fd2e9ae1df3e75b8d8c367443c692d4ca81f481"
integrity sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==
dependencies:
graceful-fs "^4.1.11"
imurmurhash "^0.1.4"
signal-exit "^3.0.2"

write-file-atomic@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-3.0.1.tgz#558328352e673b5bb192cf86500d60b230667d4b"
integrity sha512-JPStrIyyVJ6oCSz/691fAjFtefZ6q+fP6tm+OS4Qw6o+TGQxNp1ziY2PgS+X/m0V8OWhZiO/m4xSj+Pr4RrZvw==
dependencies:
imurmurhash "^0.1.4"
is-typedarray "^1.0.0"
signal-exit "^3.0.2"
typedarray-to-buffer "^3.1.5"

write-file-stdout@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/write-file-stdout/-/write-file-stdout-0.0.2.tgz#c252d7c7c5b1b402897630e3453c7bfe690d9ca1"
Expand Down

0 comments on commit ead08cc

Please sign in to comment.