docs/contributing/code-contributions.md
The beauty of contributing to open source is that you can clone your favorite project, get it running locally, and test out experiments and changes in real time! You get the opportunity to participate in a community while feeling a wizard doing it. For instructions on contributing to the docs, visit the docs contributions page.
Gatsby uses a "monorepo" pattern to manage its many dependencies and relies on Lerna and Yarn to configure the repository for both active development and documentation infrastructure changes.
Yarn is a package manager for your code, similar to npm. While npm is used to develop Gatsby sites with the CLI, contributing to the Gatsby repo requires Yarn for the following reason: we use Yarn's workspaces feature that comes really handy for monorepos. It allows us to install dependencies from multiple package.json files in sub-folders, enabling a faster and lighter installation process.
node --version^1) by executing yarn --version. The Gatsby monorepo does not yet support later versions of Yarn.gatsbyjs/gatsby repository.git clone https://github.com/<your-username>/gatsby.gityarn run bootstrapgit checkout -b topics/new-feature-nameyarn run watch from the root of the repo to watch for changes to packages' source code and compile these changes on-the-fly as you work.
yarn run watch --scope={gatsby,gatsby-cli}.gatsby, run yarn run watch --scope=gatsby.Note: Optionally you can run
git clone --depth=1 https://github.com/<your-username>/gatsby.gitto do a shallow clone (smaller download size) rather than a deep clone, however this sometimes leads to problems when you want to reference older upstream branches.
Install gatsby-dev-cli:
gatsby-dev -vyarn global add gatsby-dev-cligatsby-dev --set-path-to-repo /path/to/my/forked/version/gatsby to point gatsby-dev-cli to your forkRun yarn install in each of the sites you're testing.
For each of your Gatsby test sites, run the gatsby-dev command inside the test site's directory to copy
the built files from your cloned copy of Gatsby. It'll watch for your changes
to Gatsby packages and copy them into the site. For more detailed instructions
see the gatsby-dev-cli README and check out the gatsby-dev-cli demo video.
gatsby, run gatsby-dev --packages gatsbygatsby directly, you need to either add those manually to your test sites so that they are listed in package.json (e.g. yarn add gatsby-link), or specify them explicitly with gatsby-dev --packages gatsby-link).If you've recently run gatsby-dev your node_modules will be out of sync with current published packages. In order to undo this, you can remove the node_modules directory, revert any changes to package.json and lockfiles, and reinstall modules with npm install or yarn install . Alternatively, you can run:
git checkout package.json; yarn --force
yarn test.
yarn jest <package-name>.yarn jest <file-path>.If you're adding e2e tests and want to run them against local changes:
yarn lerna run build --scope=<package-name> where package-name is the directory containing the changes you're testing.gatsby-dev inside your specific e2e test directory, for example e2e-tests/themes/development-runtime.yarn test in that same e2e test directory.To test compatibility with different React versions, you can use the upgrade-react.js script to update the React version in a test directory, then run the tests:
REACT_VERSION=19.0.0 TEST_PATH=e2e-tests/production-runtime node ./scripts/upgrade-react.js
cd e2e-tests/production-runtime
yarn test
This will update the package.json file in the test directory to use the specified React version. This is useful for:
The same approach works for any e2e test directory. The CI system automatically runs e2e tests against both React 18 and React 19 to catch compatibility issues.
At any point during the contributing process the Gatsby team would love to help! For help with a specific problem you can open an Discussion on GitHub.
yarn run bootstrap to compile all packages. When files or tests depend on the build output (files in /dist directories) they might fail otherwise.yarn run watch on the packages' source code you're changing.If you've made all your changes, added tests, and want to contribute your changes to Gatsby, you can head over to the How to open a pull request documentation to learn more.
If you create a loader or plugin, we would love for you to open source it and put it on npm. For more information on creating custom plugins, please see the documentation for plugins and the API specification.
Gatsby's policy is that "Using" example sites (like those in the examples part of the repo) should only be around plugins that are maintained by the core team as it's hard to keep things up to date otherwise.
To contribute example sites, it is recommended to create your own GitHub repo and link to it from your source plugin, etc.
Check Debugging the build process page to learn how to debug Gatsby.
At any point during the contributing process the Gatsby team would love to help! For help with a specific problem you can open an Discussion on GitHub.