From d4b30f91b5efa1f3f526eb391d0f8c19fc144dea Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Fri, 20 Dec 2019 15:40:38 +0530 Subject: [PATCH 1/7] Use createContentDigest helper --- packages/gatsby-theme-blog-core/gatsby-node.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/gatsby-theme-blog-core/gatsby-node.js b/packages/gatsby-theme-blog-core/gatsby-node.js index 0b4f1e88c34c2..2c8f5fd116344 100644 --- a/packages/gatsby-theme-blog-core/gatsby-node.js +++ b/packages/gatsby-theme-blog-core/gatsby-node.js @@ -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`) @@ -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`, }, From 31e1fd2437df39f8c9949404ed7cb9a30064cab1 Mon Sep 17 00:00:00 2001 From: kindavishal Date: Fri, 20 Dec 2019 23:41:11 +0530 Subject: [PATCH 2/7] Use createContentDigest helper --- packages/gatsby-source-contentful/src/normalize.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/gatsby-source-contentful/src/normalize.js b/packages/gatsby-source-contentful/src/normalize.js index 585706b862385..82221090391bc 100644 --- a/packages/gatsby-source-contentful/src/normalize.js +++ b/packages/gatsby-source-contentful/src/normalize.js @@ -1,13 +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}`)) From 5c2d4c9f99578b1e1b3dd2491d99f68dfb802464 Mon Sep 17 00:00:00 2001 From: kindavishal Date: Sat, 21 Dec 2019 00:20:56 +0530 Subject: [PATCH 3/7] Use createContentDigest helper --- packages/gatsby-plugin-mdx/gatsby/on-create-node.js | 8 ++------ .../gatsby-plugin-mdx/utils/create-fake-file-node.js | 11 ++--------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/packages/gatsby-plugin-mdx/gatsby/on-create-node.js b/packages/gatsby-plugin-mdx/gatsby/on-create-node.js index f495acdc2040e..0c3c99c2a10e8 100644 --- a/packages/gatsby-plugin-mdx/gatsby/on-create-node.js +++ b/packages/gatsby-plugin-mdx/gatsby/on-create-node.js @@ -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 ( { diff --git a/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js b/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js index 5538b8b2cf789..1055441c02689 100644 --- a/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js +++ b/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js @@ -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 ( @@ -26,14 +25,8 @@ 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(obj), type: `Directory`, description: `Directory "${path.relative(process.cwd(), slashed)}"`, } From 8335edfeda7200070b6907a503b2e5ce2d02f0e8 Mon Sep 17 00:00:00 2001 From: kindavishal Date: Mon, 6 Jan 2020 11:10:15 +0530 Subject: [PATCH 4/7] Use createContentDigest helper --- packages/gatsby-plugin-mdx/utils/create-fake-file-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js b/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js index 1055441c02689..16bd762660ac4 100644 --- a/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js +++ b/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js @@ -26,7 +26,7 @@ exports.createFileNode = async ( let internal if (stats.isDirectory()) { internal = { - contentDigest : createContentDigest(obj), + contentDigest : createContentDigest({ stats: stats, absolutePath: slashedFile.absolutePath }), type: `Directory`, description: `Directory "${path.relative(process.cwd(), slashed)}"`, } From ce0e0dbcae1480093a40e1b76e920b5f4da1223a Mon Sep 17 00:00:00 2001 From: gatsbybot Date: Mon, 6 Jan 2020 08:13:29 +0000 Subject: [PATCH 5/7] chore: format --- packages/gatsby-plugin-mdx/utils/create-fake-file-node.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js b/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js index 16bd762660ac4..a05e7467e471d 100644 --- a/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js +++ b/packages/gatsby-plugin-mdx/utils/create-fake-file-node.js @@ -26,7 +26,10 @@ exports.createFileNode = async ( let internal if (stats.isDirectory()) { internal = { - contentDigest : createContentDigest({ stats: stats, absolutePath: slashedFile.absolutePath }), + contentDigest: createContentDigest({ + stats: stats, + absolutePath: slashedFile.absolutePath, + }), type: `Directory`, description: `Directory "${path.relative(process.cwd(), slashed)}"`, } From a82d4c45216038fded6ddd11a7ec00b8034eeae1 Mon Sep 17 00:00:00 2001 From: kindavishal Date: Wed, 8 Jan 2020 15:28:17 +0530 Subject: [PATCH 6/7] Removed deepMap --- packages/gatsby-source-contentful/src/normalize.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/gatsby-source-contentful/src/normalize.js b/packages/gatsby-source-contentful/src/normalize.js index 82221090391bc..0f64e3c761065 100644 --- a/packages/gatsby-source-contentful/src/normalize.js +++ b/packages/gatsby-source-contentful/src/normalize.js @@ -1,6 +1,5 @@ const _ = require(`lodash`) const stringify = require(`json-stringify-safe`) -const deepMap = require(`deep-map`) const { createContentDigest } = require(`gatsby-core-utils`) const digest = str => createContentDigest(str) From 03df8b125ada3dfb284a6fd895a6a23d0180b4fa Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Wed, 8 Jan 2020 17:55:01 +0530 Subject: [PATCH 7/7] Add deps --- .../gatsby-source-contentful/package.json | 1 + packages/gatsby-theme-blog-core/package.json | 1 + yarn.lock | 23 +++++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-contentful/package.json b/packages/gatsby-source-contentful/package.json index f6e33a483e74e..d4fa5f2372c89 100644 --- a/packages/gatsby-source-contentful/package.json +++ b/packages/gatsby-source-contentful/package.json @@ -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", diff --git a/packages/gatsby-theme-blog-core/package.json b/packages/gatsby-theme-blog-core/package.json index 2496fef8fdd68..7ab8c7fe7f3b9 100644 --- a/packages/gatsby-theme-blog-core/package.json +++ b/packages/gatsby-theme-blog-core/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 3fc6ca013a9ee..432eb1c6e1db5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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== @@ -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== @@ -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"