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-mdx): support yarn PnP #20638

Merged
merged 5 commits into from
Jan 29, 2020
Merged

Conversation

kevin940726
Copy link
Contributor

@kevin940726 kevin940726 commented Jan 16, 2020

Description

See yarnpkg/berry#689 (comment)

In order to support yarn PnP, dependencies have to be explicit listed or required from their direct parents. gatsby-plugin-mdx has required some dependencies which are not listed in package.json, but sub-dependencies of @mdx-js/mdx.

We have 2 options to fix this:

  1. List the dependencies explicitly. But we have to remember to update the range whenever @mdx-js/mdx updates. It would soon become troublesome and tedious.
  2. Require the packages anyways, but require them from the @mdx-js/mdx package via Module.createRequire.

This PR goes for the second approach. The createRequireFromPath util is already implemented in the core package from gatsby/src/utils/create-require-from-path.js. We can just use it here. (Now that it's used by a plugin, should we move it to gatsby-core-utils or something similar?)

Documentation

https://next.yarnpkg.com/features/pnp/, and https://next.yarnpkg.com/advanced/migration

Related Issues

Related to yarnpkg/berry#689. c.c. @arcanis

@kevin940726 kevin940726 requested a review from a team as a code owner January 16, 2020 09:23
@kevin940726 kevin940726 requested review from a team as code owners January 16, 2020 13:16
@kevin940726
Copy link
Contributor Author

yarn 2 has now been released! Any chance we can take a look at this again 😉? @pieh? (Sorry if I pinged the wrong person)

@pieh pieh self-assigned this Jan 29, 2020
@pieh
Copy link
Contributor

pieh commented Jan 29, 2020

Just a note - I just published gatsby-plugin-mdx@berry-mdx with changes from this (+ bunch of other packages like gatsby-core-utils, gatsby etc) and will be testing this out. But you could already start using those dist-tags if you use Yarn 2 in meantime.

@pieh
Copy link
Contributor

pieh commented Jan 29, 2020

Ok, after few bumps, I did get it to build it when using Yarn2 (see appendix :P) and I think we should get this in. @johno do you want to check changes to gatsby-plugin-mdx here? (I think they make total sense).

-- Yarn 2 appendix

  • was getting:
YN0001: │ Error: fsevents@patch:fsevents@npm%3A2.0.7#builtin<compat/fsevents>::version=2.0.7&hash=e8cd9e: Cannot apply hunk #1
    at c (/Users/misiek/test/pr20638/.yarn/releases/yarn-berry.js:58:888149)
    at process._tickCallback (internal/process/next_tick.js:68:7)

which I solved with resolutions by pinning fsevents to 2.1.2 (per yarnpkg/berry#719)

  • was getting:
Error: Something that got detected as your top-level application (because it doesn't seem to belong to any package) tried to access a package that is not declared in your dependencies
  Required package: minimatch (via "minimatch")
  Required by: /Users/misiek/test/pr20638/public/
  Require stack:
  - /Users/misiek/test/pr20638/public/render-page.js
  - /Users/misiek/test/pr20638/.yarn/unplugged/gatsby-virtual-1919d581a5/node_modules/gatsby/dist/utils/worker/render-html.js
  - /Users/misiek/test/pr20638/.yarn/unplugged/gatsby-virtual-1919d581a5/node_modules/gatsby/dist/utils/worker/child.js
  - /Users/misiek/test/pr20638/.yarn/cache/jest-worker-npm-24.9.0-bcd452e3a8-1.zip/node_modules/jest-worker/build/workers/processChild.js

which I hackily solved by installing minimatch in project (but that's something we will need to handle in core most likely, because this is where we generate render-page.js - tho I'm not sure if this is because of gatsby core or some other plugin that was in mdx starter that I was using as test case)

Copy link
Contributor

@johno johno left a comment

Choose a reason for hiding this comment

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

✨ lgtm, thanks @kevin940726!

I would've leaned towards making the versions explicit in the package.json since both Gatsby and MDX core automatically bump dep versions on a quick cadence, but this will work!

@pieh pieh changed the title Support yarn PnP for gatsby-plugin-mdx fix(gatsby-plugin-mdx): support yarn PnP Jan 29, 2020
@pieh pieh merged commit 6375ba9 into gatsbyjs:master Jan 29, 2020
@gatsbot
Copy link

gatsbot bot commented Jan 29, 2020

Holy buckets, @kevin940726 — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. We’ve got Gatsby t-shirts, stickers, hats, scrunchies, and much more. (You can also unlock even more free swag with 5 contributions — wink wink nudge nudge.) See gatsby.dev/swag for details.
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

@pieh
Copy link
Contributor

pieh commented Jan 29, 2020

Published gatsby-plugin-mdx@1.0.69, thanks @kevin940726 for the fixes!

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.

4 participants