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 createContentDigest helper #20239

Merged
merged 9 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
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
9 changes: 3 additions & 6 deletions packages/gatsby-source-contentful/src/normalize.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
const _ = require(`lodash`)
const crypto = require(`crypto`)
const stringify = require(`json-stringify-safe`)
const deepMap = require(`deep-map`)
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