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

fix(gatsby-transformer-remark): correctly pass cache to sub plugins #10892

Merged
merged 8 commits into from
Jan 8, 2019
Prev Previous commit
Next Next commit
chore: fix error and re-factor test slightly
  • Loading branch information
DSchau committed Jan 8, 2019
commit 234039748501f76f1408f7710c40f5f6a1c205d8
2 changes: 1 addition & 1 deletion e2e-tests/development-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"author": "Dustin Schau <dustin@gatsbyjs.com>",
"dependencies": {
"gatsby": "^2.0.71",
"gatsby": "^2.0.88",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't really matter. Just for local stuff!

"gatsby-image": "^2.0.20",
"gatsby-plugin-manifest": "^2.0.9",
"gatsby-plugin-offline": "^2.0.20",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function remarkPlugin({ cache, markdownAST }) {
visit(markdownAST, `html`, async node => {
if (node.value.match(id)) {
const value = await cache.get(id)
node.value = node.value.replace(/%SUBCACHE_VALUE%/, () => `>${value}<`)
node.value = node.value.replace(/%SUBCACHE_VALUE%/, value)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

60% less jank ™️

}
})
}
22 changes: 5 additions & 17 deletions packages/gatsby-transformer-remark/src/extend-node-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,11 @@ const withPathPrefix = (url, pathPrefix) =>
(pathPrefix + url).replace(/\/\//, `/`)

// TODO: remove this check with next major release
// the getCache feature was implemented in gatsby@2.0.88
const safeGetCache = ({ getCache, cache, reporter }) => {
const GATSBY_VERSION_WITH_GET_CACHE = `2.0.88`
let warned = false
return id => {
if (!getCache) {
if (!warned) {
warned = true
reporter.warn(reporter.stripIndent`
It looks like you're using a slightly outdated version of gatsby with gatsby-transformer-remark.
To update, run 'npm install gatsby@^${GATSBY_VERSION_WITH_GET_CACHE} --save' or 'yarn add gatsby@^${GATSBY_VERSION_WITH_GET_CACHE}'
`)
}
return cache
}
return getCache(id)
const safeGetCache = ({ getCache, cache }) => id => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for posterity, we already warn on conflicting peerDeps, so a second warning would be sorta redundant.

if (!getCache) {
return cache
}
return getCache(id)
}

/**
Expand Down Expand Up @@ -105,7 +93,7 @@ module.exports = (
pluginsCacheStr = pluginOptions.plugins.map(p => p.name).join(``)
pathPrefixCacheStr = pathPrefix || ``

const getCache = safeGetCache({ cache, getCache: possibleGetCache, reporter })
const getCache = safeGetCache({ cache, getCache: possibleGetCache })

return new Promise((resolve, reject) => {
// Setup Remark.
Expand Down