|
1 | 1 | # Contributing
|
2 | 2 |
|
3 |
| -# Environment |
| 3 | +Wrangler2 is an open source project and we welcome contributions from you. Thank you! |
4 | 4 |
|
5 |
| -# Steps For Making Changes |
| 5 | +Below you can find some guidance on how to be most effective when contributing to the project. |
| 6 | + |
| 7 | +## Getting started |
| 8 | + |
| 9 | +### Set up your environment |
| 10 | + |
| 11 | +Wrangler2 is built and run on the Node.js JavaScript runtime. |
| 12 | + |
| 13 | +- Install the latest LTS version of [Node.js](https://nodejs.dev/) - we recommend using a Node version manager like [nvm](https://github.com/nvm-sh/nvm). |
| 14 | +- Install a code editor - we recommend using [VS Code](https://code.visualstudio.com/). |
| 15 | + - When opening the project in VS Code for the first time, it will prompt you to install the [recommended VS Code extensions](https://code.visualstudio.com/docs/editor/extension-marketplace#:~:text=install%20the%20recommended%20extensions) for the project. |
| 16 | +- Install the [git](https://git-scm.com/) version control tool. |
| 17 | + |
| 18 | +### Fork and clone this repository |
| 19 | + |
| 20 | +Any contributions you make will be via [Pull Requests](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) on [GitHub](https://github.com/) developed in a local git repository and pushed to your own fork of the repository. |
| 21 | + |
| 22 | +- Ensure you have [created an account](https://docs.github.com/en/get-started/onboarding/getting-started-with-your-github-account) on GitHub. |
| 23 | +- [Create your own fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) of [this repository](https://github.com/cloudflare/wrangler2). |
| 24 | +- Clone your fork to your local machine |
| 25 | + ```sh |
| 26 | + > git clone https://github.com/<your-github-username>/wrangler2 |
| 27 | + > cd wrangler |
| 28 | + ``` |
| 29 | + You can see that your fork is setup as the `origin` remote repository. |
| 30 | + Any changes you wish to make should be in a local branch that is then pushed to this origin remote. |
| 31 | + ```sh |
| 32 | + > git remote -v |
| 33 | + origin https://github.com/<your-github-username>/wrangler2 (fetch) |
| 34 | + origin https://github.com/<your-github-username>/wrangler2 (push) |
| 35 | + ``` |
| 36 | +- Add `cloudflare/wrangler2` as the `upstream` remote repository. |
| 37 | + ```sh |
| 38 | + > git remote add upstream https://github.com/cloudflare/wrangler2 |
| 39 | + > git remote -v |
| 40 | + origin https://github.com/<your-github-username>/wrangler2 (fetch) |
| 41 | + origin https://github.com/<your-github-username>/wrangler2 (push) |
| 42 | + upstream https://github.com/cloudflare/wrangler2 (fetch) |
| 43 | + upstream https://github.com/cloudflare/wrangler2 (push) |
| 44 | + ``` |
| 45 | +- You should regularly pull from the `main` branch of the `upstream` repository to keep up to date with the latest changes to the project. |
| 46 | + ```sh |
| 47 | + > git switch main |
| 48 | + > git pull upstream main |
| 49 | + From https://github.com/cloudflare/wrangler2 |
| 50 | + * branch main -> FETCH_HEAD |
| 51 | + Already up to date. |
| 52 | + ``` |
| 53 | + |
| 54 | +### Install dependencies |
| 55 | + |
| 56 | +The Node.js dependencies of the project are managed by the [`npm`](https://www.npmjs.com/) tool. |
| 57 | + |
| 58 | +This repository is setup as a [mono-repo](https://docs.npmjs.com/cli/v7/using-npm/workspaces) of workspaces. The workspaces are stored in the [`packages`](https://github.com/cloudflare/wrangler2/tree/main/packages) directory. |
| 59 | + |
| 60 | +While each workspace has its own dependencies, you install the dependencies using `npm` at the root of the project. |
| 61 | + |
| 62 | +- Install all the dependencies |
| 63 | + ```sh |
| 64 | + > cd wrangler2 |
| 65 | + > npm install |
| 66 | + ``` |
| 67 | + |
| 68 | +**Do not run `npm install` in any of the workspaces directly.** |
| 69 | + |
| 70 | +## Building and running |
| 71 | + |
| 72 | +Each wrangler workspace in this project is written in [TypeScript](https://www.typescriptlang.org/) and compiled, by [esbuild](https://github.com/evanw/esbuild), into JavaScript bundles for distribution. |
| 73 | + |
| 74 | +- Run a distributable for a specific workspace (e.g. wrangler) |
| 75 | + ```sh |
| 76 | + > npm start -w wrangler |
| 77 | + ``` |
| 78 | +- Build a distributable for a specific workspace(e.g. wrangler) |
| 79 | + ```sh |
| 80 | + > npm run build -w wrangler |
| 81 | + ``` |
| 82 | + |
| 83 | +## Checking the code |
| 84 | + |
| 85 | +The code in the repository is checked for type checking, formatting, linting and testing errors. |
| 86 | + |
| 87 | +- Run all checks in all the workspaces |
| 88 | + ```sh |
| 89 | + > npm run check |
| 90 | + ``` |
| 91 | + |
| 92 | +When doing normal development you may want to run these checks individually. |
| 93 | + |
| 94 | +### Type Checking |
| 95 | + |
| 96 | +The code is checked for type errors by [TypeScript](https://www.typescriptlang.org/). |
| 97 | + |
| 98 | +- Type check all the code in the repository |
| 99 | + ```sh |
| 100 | + > npm run type-check |
| 101 | + ``` |
| 102 | +- VS Code will also run type-checking while editing source code, providing immediate feedback. |
| 103 | + |
| 104 | +### Linting |
| 105 | + |
| 106 | +The code is checked for linting errors by [ESLint](https://eslint.org/). |
| 107 | + |
| 108 | +- Run the linting checks |
| 109 | + ```sh |
| 110 | + > npm run lint |
| 111 | + ``` |
| 112 | +- The repository has a recommended VS Code plugin to run ESLint checks while editing source code, providing immediate feedback. |
| 113 | + |
| 114 | +### Formatting |
| 115 | + |
| 116 | +The code is checked for formatting errors by [Prettier](https://prettier.io/). |
| 117 | + |
| 118 | +- Run the formatting checks |
| 119 | + ```sh |
| 120 | + > npm run format-check |
| 121 | + ``` |
| 122 | +- The repository has a recommended VS Code plugin to run Prettier checks, and to automatically format using Prettier, while editing source code, providing immediate feedback. |
| 123 | + |
| 124 | +### Testing |
| 125 | + |
| 126 | +Tests in a workspace are executed, by [Jest](https://jestjs.io/), which is configured to automatically compile and bundle the TypeScript before running the tests. |
| 127 | + |
| 128 | +- Run the tests for all the workspaces |
| 129 | + ```sh |
| 130 | + > npm run test |
| 131 | + ``` |
| 132 | +- Run the tests for a specific workspace (e.g. wrangler) |
| 133 | + ```sh |
| 134 | + > npm run test -w wrangler |
| 135 | + ``` |
| 136 | +- Watch the files in a specific workspace (e.g. wrangler), and run the tests when anything changes |
| 137 | + ```sh |
| 138 | + > npm run test -w wrangler -- --watch |
| 139 | + ``` |
| 140 | + |
| 141 | +## Steps For Making Changes |
| 142 | + |
| 143 | +Every change you make should be stored in a [git commit](https://github.com/git-guides/git-commit). |
| 144 | +Changes should be committed to a new local branch, which then gets pushed to your fork of the repository on GitHub. |
| 145 | + |
| 146 | +- Ensure your `main` branch is up to date |
| 147 | + ```sh |
| 148 | + > git switch main |
| 149 | + > git pull upstream main |
| 150 | + ``` |
| 151 | +- Create a new branch, based off the `main` branch |
| 152 | + ```sh |
| 153 | + > git checkout -b <new-branch-name> main |
| 154 | + ``` |
| 155 | +- Stage files to include in a commit |
| 156 | + - Use [VS Code](https://code.visualstudio.com/docs/editor/versioncontrol#_git-support) |
| 157 | + - Or add and commit files via the command line |
| 158 | + ```sh |
| 159 | + > git add <paths-to-changes-files> |
| 160 | + > git commit |
| 161 | + ``` |
| 162 | +- Push changes to your fork |
| 163 | + ```sh |
| 164 | + git push -u origin <new-branch-name> |
| 165 | + ``` |
| 166 | +- Once you are happy with your changes, create a Pull Request on GitHub |
6 | 167 |
|
7 | 168 | ## Changesets
|
8 | 169 |
|
9 |
| -The project will be utilizing a workflow that will expedite and improve the ease of which contributions with changelogs done. |
| 170 | +Every non-trivial change to the project - those that should appear in the changelog - must be captured in a "changeset". |
| 171 | +We use the [`changesets`](https://github.com/changesets/changesets/blob/main/README.md) tool for creating changesets, publishing versions and updating the changelog. |
| 172 | + |
| 173 | +- Create a changeset for the current change. |
| 174 | + ```sh |
| 175 | + > npx changeset |
| 176 | + ``` |
| 177 | +- Select which workspaces are affected by the change and whether the version requires a major, minor or patch release. |
| 178 | +- Update the generated changeset with a description of the change. |
| 179 | +- Include the generate changeset in the current commit. |
| 180 | + ```sh |
| 181 | + > git add ./changeset/*.md |
| 182 | + ``` |
| 183 | + |
| 184 | +### Changeset message format |
| 185 | + |
| 186 | +Each changeset is a file that describes the change being merged. This file is used to generate the changelog when the changes are released. |
| 187 | + |
| 188 | +To help maintain consistency in the changelog, changesets should have the following format: |
| 189 | + |
| 190 | +``` |
| 191 | +<TYPE>: <TITLE> |
| 192 | +
|
| 193 | +<BODY> |
| 194 | +
|
| 195 | +[BREAKING CHANGES <BREAKING_CHANGE_NOTES>] |
| 196 | +``` |
10 | 197 |
|
11 |
| -- Changeset Bot |
12 |
| -- Create a changeset by running `npm run changeset` or `npx changeset`. [More info.](https://github.com/changesets/changesets#how-do-i-get-started) |
| 198 | +- `TYPE` should be a single word describing the "type" of the change. For example, one of `feature`, `fix`, `refactor`, `docs` or `chore`. |
| 199 | +- `TITLE` should be a single sentence containing an imperative description of the change. |
| 200 | +- `BODY` should be one or more paragraphs that go into more detail about the reason for the change and anything notable about the approach taken. |
| 201 | +- `BREAKING_CHANGE_NOTES` (optional) should be one or more paragraphs describing how this change breaks current usage and how to migrate to the new usage. |
0 commit comments