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): handle initializing multiple instances of gatsby-plugin-sharp #37306

Merged
merged 9 commits into from
Dec 22, 2022

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Dec 20, 2022

Description

Fix for

error Gatsby-plugin-sharp wasn't setup correctly in gatsby-config.js. Make sure you add it to the plugins array.

errors when there's multiple instances of gatsby-plugin-sharp package (for themes scenarios, when there might be different versions and package manager doesn't or can't dedupe)

Explanation of changes:

  1. We where deduping plugins when merging themes, which would be fine, but at that point we don't know yet what those plugins resolve to so we were potentially throwing away plugin entries that seemed the same but actually weren't. Case of gatsby-plugin-sharp which most often doesn't have any options and was deduped because it's specified just as gatsby-plugin-sharp - this meant that some instances of gatsby-plugin-sharp were not initiated at all. This PR moves it to after we resolve plugins where we can check actual plugin packages instances when deduping. This also required update to import-gatsby-plugin to be able to not just use plugin name, but different identifier - for gatsby build/develop we rely on plugin.resolve property. I did have to keep fallback to name for gatsby-worker, as when trying to use it we are losing which instance it is for.
  2. Engines needed adjustments to not use plugin's name for dictionary keys as then we would lose information when there is multiple instances left after deduping, instead we use array. Additionally as we are dropping/clearing resolve property from engines I needed yet another way to adjust import-gatsby-plugin and used simple importKey which is 1-indexed counter (and it represent just the index of plugin in the plugins list
  3. Used this opportunity to convert load-themes/index.js to typescript

Documentation

Related Issues

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Dec 20, 2022
@pieh pieh removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Dec 20, 2022
@pieh pieh marked this pull request as ready for review December 21, 2022 20:45
@pieh pieh changed the title Fix/broken sharp setup with multiple instances fix(gatsby): handle initializing multiple instances of gatsby-plugin-sharp Dec 21, 2022
Copy link
Contributor

@tyhopp tyhopp left a comment

Choose a reason for hiding this comment

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

Looks great, one question and then I'll approve!

@@ -26,6 +26,7 @@ import { store } from "../../redux"
import { validateEngines } from "../../utils/validate-engines"

async function run(): Promise<void> {
process.env.GATSBY_SLICES = `1`
Copy link
Contributor

Choose a reason for hiding this comment

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

Double checking, is this change also required for the fix or left in accidentally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not needed for a fix as we don't actually use this file in regular usage.

I just noticed problems with trying to use engines regenerated with this script manually as I was iterating on this PR and testing produced engines

@tyhopp tyhopp merged commit 26f2b72 into master Dec 22, 2022
@tyhopp tyhopp deleted the fix/broken-sharp-setup-with-multiple-instances branch December 22, 2022 07:30
pieh added a commit that referenced this pull request Dec 23, 2022
…sharp (#37306)

* fix(gatsby): handle initializing multiple instances of gatsby-plugin-sharp

* fix(gatsby): handle initializing multiple instances of gatsby-plugin-sharp in engines

* update standalone-regenerate

* normalize main config when loading themes

* move deduplicaiton to plugin loading instead of themes loading

* convert load-themes to TS

* lint

* update assertions

* remove test that no longer make sense

(cherry picked from commit 26f2b72)
pieh added a commit that referenced this pull request Dec 23, 2022
…sharp (#37306)

* fix(gatsby): handle initializing multiple instances of gatsby-plugin-sharp

* fix(gatsby): handle initializing multiple instances of gatsby-plugin-sharp in engines

* update standalone-regenerate

* normalize main config when loading themes

* move deduplicaiton to plugin loading instead of themes loading

* convert load-themes to TS

* lint

* update assertions

* remove test that no longer make sense

(cherry picked from commit 26f2b72)
pieh added a commit that referenced this pull request Dec 23, 2022
…sharp (#37306)

* fix(gatsby): handle initializing multiple instances of gatsby-plugin-sharp

* fix(gatsby): handle initializing multiple instances of gatsby-plugin-sharp in engines

* update standalone-regenerate

* normalize main config when loading themes

* move deduplicaiton to plugin loading instead of themes loading

* convert load-themes to TS

* lint

* update assertions

* remove test that no longer make sense

(cherry picked from commit 26f2b72)
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