fix(gatsby-plugin-offline): Run app-shell.js from user cache directory for pnp compatibility #22351
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.
Description
This makes
gatsby-plugin-offline
writeapp-shell.js
to the user's cache directory before usingcreatePage()
.The reason for this is because
true-case-path
doesn't work well with yarn 2's virtual dependency paths. The paths normally read:/path/to/project/.yarn/$$virtual/package-name/<number>
As soon as
true-case-path
reaches$$virtual
, it only finds the contents of/path/to/project/.yarn
. Which means it won't ever find$$virtual/package-name/<number>
. It wouldn't even be able to pick up a valid path again until it reaches the number that follows the package name (which resolves to wherever the yarn cache is located).This explains why
gatsby-plugin-offline
throws an exception when trying to callcreatePage()
with${__dirname}/app-shell.js
as the component. By copying that file to the user's cache,true-case-path
is able to process it correctly.An alternative would be to define a base path for
true-case-path
that represents that virtual path, up to<number>
. I didn't think that would be entirely reasonable, since it would require extra runs throughtrue-case-path
to get the correct case up to$$virtual
, and then again after. That's not particularly stable, because it would be dependent on yarn2's current implementation of their virtual paths.Related Issues
Related to #20949 (comment)