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-plugin-offline): Run app-shell.js from user cache directory for pnp compatibility #22351

Merged
merged 2 commits into from
Mar 17, 2020

Conversation

Js-Brecht
Copy link
Contributor

Description

This makes gatsby-plugin-offline write app-shell.js to the user's cache directory before using createPage().

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 call createPage() 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 through true-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)

@Js-Brecht Js-Brecht requested a review from a team as a code owner March 17, 2020 00:38
@Js-Brecht Js-Brecht changed the title [gatsby-plugin-offline] Put app-shell.js in user cache directory for pnp compatibility [gatsby-plugin-offline] Run app-shell.js from user cache directory for pnp compatibility Mar 17, 2020
@pieh pieh changed the title [gatsby-plugin-offline] Run app-shell.js from user cache directory for pnp compatibility fix(gatsby-plugin-offline): Run app-shell.js from user cache directory for pnp compatibility Mar 17, 2020
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

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

Nice! Thanks!

@pieh pieh merged commit f8b7317 into gatsbyjs:master Mar 17, 2020
@Js-Brecht Js-Brecht deleted the offline-pnp-compat branch March 17, 2020 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants