Skip to content

Commit

Permalink
refactor(gatsby-transformer-remark): Refactors out Bluebird usage in …
Browse files Browse the repository at this point in the history
…transformer-remark (#29638)

Co-authored-by: Ward Peeters <ward@coding-tech.com>
  • Loading branch information
lourd and wardpeet authored Mar 3, 2021
1 parent c560eaa commit 7193303
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
1 change: 0 additions & 1 deletion packages/gatsby-transformer-remark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
},
"dependencies": {
"@babel/runtime": "^7.12.5",
"bluebird": "^3.7.2",
"gatsby-core-utils": "^2.1.0-next.1",
"gray-matter": "^4.0.2",
"hast-util-raw": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const Promise = require(`bluebird`)
const _ = require(`lodash`)
const { onCreateNode } = require(`../on-node-create`)
const { graphql } = require(`gatsby/graphql`)
Expand Down
15 changes: 6 additions & 9 deletions packages/gatsby-transformer-remark/src/extend-node-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const toHAST = require(`mdast-util-to-hast`)
const hastToHTML = require(`hast-util-to-html`)
const mdastToToc = require(`mdast-util-toc`)
const mdastToString = require(`mdast-util-to-string`)
const Promise = require(`bluebird`)
const unified = require(`unified`)
const parse = require(`remark-parse`)
const stringify = require(`remark-stringify`)
Expand Down Expand Up @@ -116,7 +115,7 @@ module.exports = function remarkExtendNodeType(
}
let remark = new Remark().data(`settings`, remarkOptions)

for (let plugin of pluginOptions.plugins) {
for (const plugin of pluginOptions.plugins) {
const requiredPlugin = require(plugin.resolve)
if (_.isFunction(requiredPlugin.setParserPlugins)) {
for (let parserPlugin of requiredPlugin.setParserPlugins(
Expand Down Expand Up @@ -193,8 +192,8 @@ module.exports = function remarkExtendNodeType(
if (process.env.NODE_ENV !== `production` || !fileNodes) {
fileNodes = getNodesByType(`File`)
}
// Use Bluebird's Promise function "each" to run remark plugins serially.
await Promise.each(pluginOptions.plugins, plugin => {
// Use a for loop to run remark plugins serially.
for (const plugin of pluginOptions.plugins) {
const requiredPlugin = require(plugin.resolve)
// Allow both exports = function(), and exports.default = function()
const defaultFunction = _.isFunction(requiredPlugin)
Expand All @@ -204,7 +203,7 @@ module.exports = function remarkExtendNodeType(
: undefined

if (defaultFunction) {
return defaultFunction(
await defaultFunction(
{
markdownAST,
markdownNode,
Expand All @@ -220,10 +219,8 @@ module.exports = function remarkExtendNodeType(
},
plugin.pluginOptions
)
} else {
return Promise.resolve()
}
})
}

return markdownAST
}
Expand All @@ -236,7 +233,7 @@ module.exports = function remarkExtendNodeType(
// Execute the remark plugins that can mutate the node
// before parsing its content
//
// Use Bluebird's Promise function "each" to run remark plugins serially.
// Use for loop to run remark plugins serially.
for (const plugin of pluginOptions.plugins) {
const requiredPlugin = require(plugin.resolve)
if (typeof requiredPlugin.mutateSource === `function`) {
Expand Down

0 comments on commit 7193303

Please sign in to comment.