From 59bc2b022f4c2eac2595daa7312f97701e5b67fc Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Mon, 18 Mar 2019 08:05:15 +0100 Subject: [PATCH] Revert "fix(gatsby-transformer-remark): wait for async subplugins (#12578)" This reverts commit af87e96e570441ee63d8dc7b714846ca3601bef1. --- .../src/__tests__/utils.js | 24 ------------------- .../src/extend-node-type.js | 14 ++++++++++- .../gatsby-transformer-remark/src/utils.js | 12 ---------- 3 files changed, 13 insertions(+), 37 deletions(-) delete mode 100644 packages/gatsby-transformer-remark/src/__tests__/utils.js delete mode 100644 packages/gatsby-transformer-remark/src/utils.js diff --git a/packages/gatsby-transformer-remark/src/__tests__/utils.js b/packages/gatsby-transformer-remark/src/__tests__/utils.js deleted file mode 100644 index 909bf72ad3f0a..0000000000000 --- a/packages/gatsby-transformer-remark/src/__tests__/utils.js +++ /dev/null @@ -1,24 +0,0 @@ -const { eachPromise } = require(`../utils`) - -test(`eachPromise`, async () => { - const args = [`foo`, `bar`, `baz`] - - const cb = jest.fn() - - await eachPromise(args, arg => { - cb(`Start`, arg) - return new Promise(resolve => { - setTimeout(() => { - cb(`Finish`, arg) - resolve() - }, 200) - }) - }) - - expect(cb).toHaveBeenNthCalledWith(1, `Start`, `foo`) - expect(cb).toHaveBeenNthCalledWith(2, `Finish`, `foo`) - expect(cb).toHaveBeenNthCalledWith(3, `Start`, `bar`) - expect(cb).toHaveBeenNthCalledWith(4, `Finish`, `bar`) - expect(cb).toHaveBeenNthCalledWith(5, `Start`, `baz`) - expect(cb).toHaveBeenNthCalledWith(6, `Finish`, `baz`) -}) diff --git a/packages/gatsby-transformer-remark/src/extend-node-type.js b/packages/gatsby-transformer-remark/src/extend-node-type.js index e976a1c4f6af6..e314ce2a7c488 100644 --- a/packages/gatsby-transformer-remark/src/extend-node-type.js +++ b/packages/gatsby-transformer-remark/src/extend-node-type.js @@ -29,7 +29,6 @@ const { cloneTreeUntil, findLastTextNode, } = require(`./hast-processing`) -const { eachPromise } = require(`./utils`) let fileNodes let pluginsCacheStr = `` @@ -69,6 +68,19 @@ const safeGetCache = ({ getCache, cache }) => id => { return getCache(id) } +/** + * @template T + * @param {Array} input + * @param {(input: T) => Promise} iterator + * @return Promise + */ +const eachPromise = (input, iterator) => + input.reduce( + (accumulatorPromise, nextValue) => + accumulatorPromise.then(() => void iterator(nextValue)), + Promise.resolve() + ) + const HeadingType = new GraphQLObjectType({ name: `MarkdownHeading`, fields: { diff --git a/packages/gatsby-transformer-remark/src/utils.js b/packages/gatsby-transformer-remark/src/utils.js deleted file mode 100644 index 39456e299c311..0000000000000 --- a/packages/gatsby-transformer-remark/src/utils.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @template T - * @param {Array} input - * @param {(input: T) => Promise} iterator - * @return Promise - */ -exports.eachPromise = (input, iterator) => - input.reduce( - (accumulatorPromise, nextValue) => - accumulatorPromise.then(() => iterator(nextValue)), - Promise.resolve() - )