-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
pieh
merged 8 commits into
gatsbyjs:master
from
DSchau:gatsby-transformer-remark/sub-cache
Jan 8, 2019
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d65def5
fix(gatsby-transformer-remark): correctly pass cache to sub plugins
DSchau 9b5259c
fix(gatsby-transformer-remark): add a safe way to getCache
DSchau 6e9bb33
chore: test broken test
DSchau cc38488
Merge remote-tracking branch 'upstream/master' into gatsby-transforme…
DSchau b5eb1ab
Merge remote-tracking branch 'upstream/master' into gatsby-transforme…
DSchau 2340397
chore: fix error and re-factor test slightly
DSchau aa7fe00
chore: revert file that should not have been committed
DSchau d5d627d
test: get tests passing maybe (cc @pieh)
DSchau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 60% less jank ™️ |
||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
|
||
/** | ||
|
@@ -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. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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!