Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

CONTRIBUTING.md

203 lines7.0 KB

1# Contributing
2​
3## Questions
4​
5If you have questions about implementation details, help or support, then please use our dedicated community forum at [GitHub Discussions](https://github.com/TanStack/query/discussions) **PLEASE NOTE:** If you choose to instead open an issue for your question, your issue will be immediately closed and redirected to the forum.
6​
7## Reporting Issues
8​
9If you have found what you think is a bug, please [file an issue](https://github.com/TanStack/query/issues/new/choose). **PLEASE NOTE:** Issues that are identified as implementation questions or non-issues will be immediately closed and redirected to [GitHub Discussions](https://github.com/TanStack/query/discussions)
10​
11## Suggesting new features
12​
13If you are here to suggest a feature, first create an issue if it does not already exist. From there, we will discuss use-cases for the feature and then finally discuss how it could be implemented.
14​
15## Development
16​
17_TanStack/query uses **symlink-based** configuration files. For smooth development in a local environment, we recommend developing in an environment that supports symlinks(ex: Linux, macOS, Windows Subsystem for Linux / WSL)._
18​
19If you have been assigned to fix an issue or develop a new feature, please follow these steps to get started:
20​
21- Fork this repository.
22- Install dependencies
23​
24 ```bash
25 pnpm install
26 ```
27​
28 - We use [pnpm](https://pnpm.io/) v10 for package management (run in case of pnpm-related issues).
29​
30 ```bash
31 corepack enable && corepack prepare
32 ```
33​
34 - We use [nvm](https://github.com/nvm-sh/nvm) to manage node versions - please make sure to use the version mentioned in `.nvmrc`
35​
36 ```bash
37 nvm use
38 ```
39​
40- Build all packages.
41​
42 ```bash
43 pnpm build:all
44 ```
45​
46- Run development server.
47​
48 ```bash
49 pnpm run watch
50 ```
51​
52- Implement your changes and tests to files in the `src/` directory and corresponding test files.
53- Document your changes in the appropriate doc page.
54- Git stage your required changes and commit (see below commit guidelines).
55- Submit PR for review.
56​
57### Editing the docs locally and previewing the changes
58​
59The documentations for all the TanStack projects are hosted on [tanstack.com](https://tanstack.com), which is a TanStack Start application (https://github.com/TanStack/tanstack.com). You need to run this app locally to preview your changes in the `TanStack/query` docs.
60​
61> [!NOTE]
62> The website fetches the doc pages from GitHub in production, and searches for them at `../query/docs` in development. Your local clone of `TanStack/query` needs to be in the same directory as the local clone of `TanStack/tanstack.com`.
63​
64You can follow these steps to set up the docs for local development:
65​
661. Make a new directory called `tanstack`.
67​
68```sh
69mkdir tanstack
70```
71​
722. Enter that directory and clone the [`TanStack/query`](https://github.com/TanStack/query) and [`TanStack/tanstack.com`](https://github.com/TanStack/tanstack.com) repos.
73​
74```sh
75cd tanstack
76git clone git@github.com:TanStack/query.git
77# We probably don't need all the branches and commit history
78# from the `tanstack.com` repo, so let's just create a shallow
79# clone of the latest version of the `main` branch.
80# Read more about shallow clones here:
81# https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/#user-content-shallow-clones
82git clone git@github.com:TanStack/tanstack.com.git --depth=1 --single-branch --branch=main
83```
84​
85> [!NOTE]
86> Your `tanstack` directory should look like this:
88> ```
89> tanstack/
90> |
91> +-- query/ (<-- this directory cannot be called anything else!)
92> |
93> +-- tanstack.com/
94> ```
95​
963. Enter the `tanstack/tanstack.com` directory, install the dependencies and run the app in dev mode:
97​
98```sh
99cd tanstack.com
100pnpm i
101# The app will run on https://localhost:3000 by default
102pnpm dev
103```
104​
1054. Now you can visit http://localhost:3000/query/latest/docs/framework/react/overview in the browser and see the changes you make in `tanstack/query/docs` there.
106​
107> [!WARNING]
108> You will need to update the `docs/config.json` file (in `TanStack/query`) if you add a new documentation page!
109​
110You can see the whole process in the screen capture below:
111​
112https://github.com/fulopkovacs/form/assets/43729152/9d35a3c3-8153-4e74-9cb2-af275f7a269b
113​
114### Running examples
115​
116- Make sure you've installed the dependencies in the repo's root directory.
117​
118 ```bash
119 pnpm install
120 ```
121​
122- If you want to run the example against your local changes, run below in the repo's root directory. Otherwise, it will be run against the latest TanStack Query release.
123​
124 ```bash
125 pnpm run watch
126 ```
127​
128- Run below in the selected examples' directory.
129​
130 ```bash
131 pnpm run dev
132 ```
133​
134#### Note on standalone execution
135​
136If you want to run an example without installing dependencies for the whole repo, just follow the instructions from the example's README.md file. It will then be run against the latest TanStack Query release.
137​
138## Online one-click setup
139​
140You can use Gitpod (An Online open-source VS Code-like IDE that is free for Open Source) for developing online. With a single click it will start a workspace and automatically:
141​
142- clone the `TanStack/query` repo.
143- install all the dependencies in `/` and `/docs`.
144- run below in the root(`/`) to Auto-build files.
145​
146 ```bash
147 npm start
148 ```
149​
150- run below in `/docs`.
151​
152 ```bash
153 npm run dev
154 ```
155​
156[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/TanStack/query)
157​
158## Changesets
159​
160This repo uses [Changesets](https://github.com/changesets/changesets) to automate releases. If your PR should release a new package version (patch, minor, or major), please run run `pnpm changeset` and commit the file. If needed, changeset descriptions can be more descriptive, and will be included in the changelog. If your PR affects docs, examples, styles, etc., you probably don't need to generate a changeset.
161​
162## Pull requests
163​
164Maintainers merge pull requests by squashing all commits and editing the commit message if necessary using the GitHub user interface.
165​
166Use an appropriate commit type. Be especially careful with breaking changes.
167​
168## Releases
169​
170For each new commit added to `main`, a GitHub Workflow is triggered which runs the [Changesets Action](https://github.com/changesets/action). This generates a preview PR showing the impact of all changesets. When this PR is merged, the package will be published to NPM.
171​
172## πŸ§ͺ Test
173​
174TanStack Query uses [Nx](https://nx.dev/) as its monorepo tool.
175To run tests in a local environment, you should use `nx` commands from the root directory.
176​
177### βœ… Run all tests
178​
179To run tests for **all packages**, run:
180​
181```bash
182npm run test
183```
184​
185### βœ… Run tests for a specific package
186​
187To run tests for a specific package, use the following command:
188​
189```bash
190npx nx run @tanstack/{package-name}:test:lib
191```
192​
193For example:
194​
195```bash
196npx nx run @tanstack/react-query:test:lib
197```
198​
199### ⚠️ Caution
200​
201Do not run `pnpm run test:lib` inside individual package folders.
202This can cause test failures due to dependencies between packages.
203Always run tests from the **root folder** using `nx` commands.