1# Pull requests 2 3* [Dependencies](#dependencies) 4* [Setting up your local environment](#setting-up-your-local-environment) 5 * [Step 1: Fork](#step-1-fork) 6 * [Step 2: Branch](#step-2-branch) 7* [The process of making changes](#the-process-of-making-changes) 8 * [Step 3: Code](#step-3-code) 9 * [Step 4: Commit](#step-4-commit) 10 * [Commit message guidelines](#commit-message-guidelines) 11 * [Step 5: Rebase](#step-5-rebase) 12 * [Step 6: Test](#step-6-test) 13 * [Step 7: Push](#step-7-push) 14 * [Step 8: Opening the pull request](#step-8-opening-the-pull-request) 15 * [Step 9: Discuss and update](#step-9-discuss-and-update) 16 * [Approval and request changes workflow](#approval-and-request-changes-workflow) 17 * [Step 10: Landing](#step-10-landing) 18* [Reviewing pull requests](#reviewing-pull-requests) 19 * [Review a bit at a time](#review-a-bit-at-a-time) 20 * [Be aware of the person behind the code](#be-aware-of-the-person-behind-the-code) 21 * [Respect the minimum wait time for comments](#respect-the-minimum-wait-time-for-comments) 22 * [Abandoned or stalled pull requests](#abandoned-or-stalled-pull-requests) 23 * [Approving a change](#approving-a-change) 24 * [Accept that there are different opinions about what belongs in Node.js](#accept-that-there-are-different-opinions-about-what-belongs-in-nodejs) 25 * [Performance is not everything](#performance-is-not-everything) 26 * [Continuous integration testing](#continuous-integration-testing) 27* [Notes](#notes) 28 * [Commit squashing](#commit-squashing) 29 * [Getting approvals for your pull request](#getting-approvals-for-your-pull-request) 30 * [Waiting until the pull request gets landed](#waiting-until-the-pull-request-gets-landed) 31 * [Check out the collaborator guide](#check-out-the-collaborator-guide) 32 * [Appendix: subsystems](#appendix-subsystems) 33 34## Dependencies 35 36Node.js has several bundled dependencies in the _deps/_ and the _tools/_ 37directories that are not part of the project proper. Changes to files in those 38directories should be sent to their respective projects. Do not send a patch to 39Node.js. We cannot accept such patches. 40 41In case of doubt, open an issue in the 42[issue tracker](https://github.com/nodejs/node/issues/) or contact one of the 43[project collaborators](https://github.com/nodejs/node/#current-project-team-members). 44 45Node.js has many channels on the 46[OpenJS Foundation Slack](https://slack-invite.openjsf.org/). Interesting 47channels are: 48[#nodejs](https://openjs-foundation.slack.com/archives/CK9Q4MB53) for general 49help, questions, and discussions. 50[#nodejs-core](https://openjs-foundation.slack.com/archives/C019Y2T6STH) for 51development of Node.js core specifically. 52 53Node.js also has an unofficial IRC channel: 54[#Node.js](https://web.libera.chat/?channels=node.js). 55 56## Setting up your local environment 57 58To get started, you will need to have `git` installed locally. Depending on 59your operating system, there are also a number of other dependencies required. 60These are detailed in the [Building guide][]. 61 62Depending on your environment you might want to grab IDE specific settings from 63[IDE configs](https://github.com/nodejs/node-code-ide-configs). 64 65Once you have `git` and are sure you have all of the necessary dependencies, 66it's time to create a fork. 67 68### Step 1: Fork 69 70Fork the project [on GitHub](https://github.com/nodejs/node) and clone your fork 71locally. 72 73```text 74git clone git@github.com:username/node.git 75cd node 76git remote add upstream https://github.com/nodejs/node.git 77git fetch upstream 78``` 79 80Configure `git` so that it knows who you are: 81 82```text 83git config user.name "J. Random User" 84git config user.email "j.random.user@example.com" 85``` 86 87You can use any name/email address you prefer here. We only use the 88metadata generated by `git` using this configuration for properly attributing 89your changes to you in the `AUTHORS` file and the changelog. 90 91If you would like for the GitHub UI to link the commit to your account 92and award you the `Contributor` label after the changes have been merged, 93make sure this local email is also added to your 94[GitHub email list](https://github.com/settings/emails). 95 96### Step 2: Branch 97 98As a best practice to keep your development environment as organized as 99possible, create local branches to work within. These should also be created 100directly off of the upstream default branch. 101 102```text 103git checkout -b my-branch -t upstream/HEAD 104``` 105 106## The process of making changes 107 108### Step 3: Code 109 110Pull requests in Node.js typically involve changes to 111one or more of a few places in the repository. 112 113* C/C++ code contained in the `src` directory 114* JavaScript code contained in the `lib` directory 115* Documentation in `doc/api` 116* Tests within the `test` directory 117 118If you are modifying code, please be sure to run `make lint` (or 119`vcbuild.bat lint` on Windows) to ensure that the changes follow the Node.js 120code style guide. 121 122Any documentation you write (including code comments and API documentation) 123should follow the [Style Guide](../../README.md). Code samples 124included in the API docs will also be checked when running `make lint` (or 125`vcbuild.bat lint` on Windows). If you are adding to or deprecating an API, 126add or change the appropriate YAML documentation. Use `REPLACEME` for the 127version number in the documentation YAML: 128 129```markdown 130### `request.method` 131<!-- YAML 132added: REPLACEME 133--> 134 135* {string} The request method. 136``` 137 138For contributing C++ code, you may want to look at the 139[C++ Style Guide](cpp-style-guide.md), as well as the 140[README of `src/`](../../src/README.md) for an overview of Node.js 141C++ internals. 142 143### Step 4: Commit 144 145It is a best practice to keep your changes as logically grouped 146as possible within individual commits. There is no limit to the number of 147commits any single pull request may have, and many contributors find it easier 148to review changes that are split across multiple commits. 149 150```text 151git add my/changed/files 152git commit 153``` 154 155Multiple commits often get squashed when they are landed. See the 156notes about [commit squashing](#commit-squashing). 157 158#### Commit message guidelines 159 160A good commit message should describe what changed and why. 161 1621. The first line should: 163 164 * contain a short description of the change (preferably 50 characters or 165 less, and no more than 72 characters) 166 * be entirely in lowercase with the exception of proper nouns, acronyms, and 167 the words that refer to code, like function/variable names 168 * be prefixed with the name of the changed [subsystem](#appendix-subsystems) 169 and start with an imperative verb. Check the output of `git log --oneline 170 files/you/changed` to find out what subsystems your changes touch. 171 172 Examples: 173 174 * `net: add localAddress and localPort to Socket` 175 * `src: fix typos in async_wrap.h` 176 1772. Keep the second line blank. 178 1793. Wrap all other lines at 72 columns (except for long URLs). 180 1814. If your patch fixes an open issue, you can add a reference to it at the end 182 of the log. Use the `Fixes:` prefix and the full issue URL. For other 183 references use `Refs:`. 184 185 Examples: 186 187 * `Fixes: https://github.com/nodejs/node/issues/1337` 188 * `Refs: https://eslint.org/docs/rules/space-in-parens.html` 189 * `Refs: https://github.com/nodejs/node/pull/3615` 190 1915. If your commit introduces a breaking change (`semver-major`), it should 192 contain an explanation about the reason of the breaking change, which 193 situation would trigger the breaking change, and what is the exact change. 194 195Sample complete commit message: 196 197```text 198subsystem: explain the commit in one line 199 200The body of the commit message should be one or more paragraphs, explaining 201things in more detail. Please word-wrap to keep columns to 72 characters or 202less. 203 204Fixes: https://github.com/nodejs/node/issues/1337 205Refs: https://eslint.org/docs/rules/space-in-parens.html 206``` 207 208If you are new to contributing to Node.js, please try to do your best at 209conforming to these guidelines, but do not worry if you get something wrong. 210One of the existing contributors will help get things situated and the 211contributor landing the pull request will ensure that everything follows 212the project guidelines. 213 214### Step 5: Rebase 215 216As a best practice, once you have committed your changes, it is a good idea 217to use `git rebase` (not `git merge`) to synchronize your work with the main 218repository. 219 220```text 221git fetch upstream HEAD 222git rebase FETCH_HEAD 223``` 224 225This ensures that your working branch has the latest changes from `nodejs/node`. 226 227### Step 6: Test 228 229Bug fixes and features should always come with tests. A 230[guide for writing tests in Node.js][] has been 231provided to make the process easier. Looking at other tests to see how they 232should be structured can also help. 233 234The `test` directory within the `nodejs/node` repository is complex and it is 235often not clear where a new test file should go. When in doubt, add new tests 236to the `test/parallel/` directory and the right location will be sorted out 237later. 238 239Before submitting your changes in a pull request, always run the full Node.js 240test suite. To run the tests (including code linting) on Unix / macOS: 241 242```text 243./configure && make -j4 test 244``` 245 246We can speed up the builds by using [Ninja](https://ninja-build.org/). For more 247information, see 248[Building Node.js with Ninja](building-node-with-ninja.md). 249 250And on Windows: 251 252```text 253> vcbuild test 254``` 255 256For some configurations, running all tests might take a long time (an hour or 257more). To run a subset of the test suite, see the [running tests][] section of 258the Building guide. 259 260### Step 7: Push 261 262Once you are sure your commits are ready to go, with passing tests and linting, 263begin the process of opening a pull request by pushing your working branch to 264your fork on GitHub. 265 266```text 267git push origin my-branch 268``` 269 270### Step 8: Opening the pull request 271 272From within GitHub, opening a new pull request will present you with a 273[pull request template][]. Please try to do your best at filling out the 274details, but feel free to skip parts if you're not sure what to put. 275 276Once opened, pull requests are usually reviewed within a few days. 277 278To get feedback on your proposed change even though it is not ready 279to land, use the `Convert to draft` option in the GitHub UI. 280Do not use the `wip` label as it might not prevent the PR 281from landing before you are ready. 282 283### Step 9: Discuss and update 284 285You will probably get feedback or requests for changes to your pull request. 286This is a big part of the submission process so don't be discouraged! Some 287contributors may sign off on the pull request right away, others may have 288more detailed comments or feedback. This is a necessary part of the process 289in order to evaluate whether the changes are correct and necessary. 290 291To make changes to an existing pull request, make the changes to your local 292branch, add a new commit with those changes, and push those to your fork. 293GitHub will automatically update the pull request. 294 295```text 296git add my/changed/files 297git commit 298git push origin my-branch 299``` 300 301If a git conflict arises, it is necessary to synchronize your branch with other 302changes that have landed upstream by using `git rebase`: 303 304```text 305git fetch upstream HEAD 306git rebase FETCH_HEAD 307git push --force-with-lease origin my-branch 308``` 309 310**Important:** The `git push --force-with-lease` command is one of the few ways 311to delete history in `git`. It also complicates the review process, as it won't 312allow reviewers to get a quick glance on what changed. Before you use it, make 313sure you understand the risks. If in doubt, you can always ask for guidance in 314the pull request. 315 316There are a number of more advanced mechanisms for managing commits using 317`git rebase` that can be used, but are beyond the scope of this guide. 318 319Feel free to post a comment in the pull request to ping reviewers if you are 320awaiting an answer on something. If you encounter words or acronyms that 321seem unfamiliar, refer to this 322[glossary](https://github.com/nodejs/node/blob/HEAD/glossary.md). 323 324#### Approval and request changes workflow 325 326All pull requests require "sign off" in order to land. Whenever a contributor 327reviews a pull request they may find specific details that they would like to 328see changed or fixed. These may be as simple as fixing a typo, or may involve 329substantive changes to the code you have written. While such requests are 330intended to be helpful, they may come across as abrupt or unhelpful, especially 331requests to change things that do not include concrete suggestions on _how_ to 332change them. 333 334Try not to be discouraged. If you feel that a particular review is unfair, 335say so, or contact one of the other contributors in the project and seek their 336input. Often such comments are the result of the reviewer having only taken a 337short amount of time to review and are not ill-intended. Such issues can often 338be resolved with a bit of patience. That said, reviewers should be expected to 339be helpful in their feedback, and feedback that is simply vague, dismissive, and 340unhelpful is likely safe to ignore. 341 342### Step 10: Landing 343 344In order to land, a pull request needs to be reviewed and [approved][] by 345at least two Node.js Collaborators (one collaborator approval is enough if the 346pull request has been open for more than 7 days) and pass a 347[CI (Continuous Integration) test run][]. After that, as long as there are no 348objections from other contributors, the pull request can be merged. If you find 349your pull request waiting longer than you expect, see the 350[notes about the waiting time](#waiting-until-the-pull-request-gets-landed). 351 352When a collaborator lands your pull request, they will post 353a comment to the pull request page mentioning the commit(s) it 354landed as. GitHub might show the pull request as `Closed` at this 355point, but don't worry. If you look at the branch you raised your 356pull request against, you should see a commit with your name on it. 357Congratulations and thanks for your contribution! 358 359## Reviewing pull requests 360 361All Node.js contributors who choose to review and provide feedback on Pull 362Requests have a responsibility to both the project and the individual making the 363contribution. Reviews and feedback must be helpful, insightful, and geared 364towards improving the contribution as opposed to simply blocking it. Do not 365expect to be able to block a pull request from advancing simply because you say 366"No" without giving an explanation. Be open to having your mind changed. Be open 367to working with the contributor to make the pull request better. 368 369Reviews that are dismissive or disrespectful of the contributor or any other 370reviewers are strictly counter to the [Code of Conduct][]. 371 372When reviewing a pull request, the primary goals are for the codebase to improve 373and for the person submitting the request to succeed. Even if a pull request 374does not land, the submitters should come away from the experience feeling like 375their effort was not wasted or unappreciated. Every pull request from a new 376contributor is an opportunity to grow the community. 377 378### Review a bit at a time 379 380Do not overwhelm new contributors. 381 382It is tempting to micro-optimize and make everything about relative performance, 383perfect grammar, or exact style matches. Do not succumb to that temptation. 384 385Focus first on the most significant aspects of the change: 386 3871. Does this change make sense for Node.js? 3882. Does this change make Node.js better, even if only incrementally? 3893. Are there clear bugs or larger scale issues that need attending to? 3904. Is the commit message readable and correct? If it contains a breaking change 391 is it clear enough? 392 393When changes are necessary, _request_ them, do not _demand_ them, and do not 394assume that the submitter already knows how to add a test or run a benchmark. 395 396Specific performance optimization techniques, coding styles, and conventions 397change over time. The first impression you give to a new contributor never does. 398 399Nits (requests for small changes that are not essential) are fine, but try to 400avoid stalling the pull request. Most nits can typically be fixed by the 401Node.js collaborator landing the pull request but they can also be an 402opportunity for the contributor to learn a bit more about the project. 403 404It is always good to clearly indicate nits when you comment: e.g. 405`Nit: change foo() to bar(). But this is not blocking.` 406 407If your comments were addressed but were not folded automatically after new 408commits or if they proved to be mistaken, please, [hide them][hiding-a-comment] 409with the appropriate reason to keep the conversation flow concise and relevant. 410 411### Be aware of the person behind the code 412 413Be aware that _how_ you communicate requests and reviews in your feedback can 414have a significant impact on the success of the pull request. Yes, we may land 415a particular change that makes Node.js better, but the individual might just 416not want to have anything to do with Node.js ever again. The goal is not just 417having good code. 418 419### Respect the minimum wait time for comments 420 421There is a minimum waiting time which we try to respect for non-trivial 422changes, so that people who may have important input in such a distributed 423project are able to respond. 424 425For non-trivial changes, pull requests must be left open for at least 48 hours. 426Sometimes changes take far longer to review, or need more specialized review 427from subject-matter experts. When in doubt, do not rush. 428 429Trivial changes, typically limited to small formatting changes or fixes to 430documentation, may be landed within the minimum 48 hour window. 431 432### Abandoned or stalled pull requests 433 434If a pull request appears to be abandoned or stalled, it is polite to first 435check with the contributor to see if they intend to continue the work before 436checking if they would mind if you took it over (especially if it just has 437nits left). When doing so, it is courteous to give the original contributor 438credit for the work they started (either by preserving their name and email 439address) in the commit log, or by using an `Author:` meta-data tag in the 440commit. 441 442### Approving a change 443 444Any Node.js core collaborator (any GitHub user with commit rights in the 445`nodejs/node` repository) is authorized to approve any other contributor's 446work. Collaborators are not permitted to approve their own pull requests. 447 448Collaborators indicate that they have reviewed and approve of the changes in 449a pull request either by using GitHub's Approval Workflow, which is preferred, 450or by leaving an `LGTM` ("Looks Good To Me") comment. 451 452When explicitly using the "Changes requested" component of the GitHub Approval 453Workflow, show empathy. That is, do not be rude or abrupt with your feedback 454and offer concrete suggestions for improvement, if possible. If you're not 455sure _how_ a particular change can be improved, say so. 456 457Most importantly, after leaving such requests, it is courteous to make yourself 458available later to check whether your comments have been addressed. 459 460If you see that requested changes have been made, you can clear another 461collaborator's `Changes requested` review. 462 463Change requests that are vague, dismissive, or unconstructive may also be 464dismissed if requests for greater clarification go unanswered within a 465reasonable period of time. 466 467Use `Changes requested` to block a pull request from landing. When doing so, 468explain why you believe the pull request should not land along with an 469explanation of what may be an acceptable alternative course, if any. 470 471### Accept that there are different opinions about what belongs in Node.js 472 473Opinions on this vary, even among the members of the Technical Steering 474Committee. 475 476One general rule of thumb is that if Node.js itself needs it (due to historic 477or functional reasons), then it belongs in Node.js. For instance, `url` 478parsing is in Node.js because of HTTP protocol support. 479 480Also, functionality that either cannot be implemented outside of core in any 481reasonable way, or only with significant pain. 482 483It is not uncommon for contributors to suggest new features they feel would 484make Node.js better. These may or may not make sense to add, but as with all 485changes, be courteous in how you communicate your stance on these. Comments 486that make the contributor feel like they should have "known better" or 487ridiculed for even trying run counter to the [Code of Conduct][]. 488 489### Performance is not everything 490 491Node.js has always optimized for speed of execution. If a particular change 492can be shown to make some part of Node.js faster, it's quite likely to be 493accepted. Claims that a particular pull request will make things faster will 494almost always be met by requests for performance [benchmark results][] that 495demonstrate the improvement. 496 497That said, performance is not the only factor to consider. Node.js also 498optimizes in favor of not breaking existing code in the ecosystem, and not 499changing working functional code just for the sake of changing. 500 501If a particular pull request introduces a performance or functional 502regression, rather than simply rejecting the pull request, take the time to 503work _with_ the contributor on improving the change. Offer feedback and 504advice on what would make the pull request acceptable, and do not assume that 505the contributor should already know how to do that. Be explicit in your 506feedback. 507 508### Continuous integration testing 509 510All pull requests that contain changes to code must be run through 511continuous integration (CI) testing at [https://ci.nodejs.org/][]. 512 513Only Node.js core collaborators and triagers can start a CI testing run. The 514specific details of how to do this are included in the new collaborator 515[Onboarding guide][]. Usually, a collaborator or triager will start a CI 516test run for you as approvals for the pull request come in. 517If not, you can ask a collaborator or triager to start a CI run. 518 519Ideally, the code change will pass ("be green") on all platform configurations 520supported by Node.js. This means that all tests pass and there are no linting 521errors. In reality, however, it is not uncommon for the CI infrastructure itself 522to fail on specific platforms or for so-called "flaky" tests to fail ("be red"). 523It is vital to visually inspect the results of all failed ("red") tests to 524determine whether the failure was caused by the changes in the pull request. 525 526## Notes 527 528### Commit squashing 529 530In most cases, do not squash commits that you add to your pull request during 531the review process. When the commits in your pull request land, they may be 532squashed into one commit per logical change. Metadata will be added to the 533commit message (including links to the pull request, links to relevant issues, 534and the names of the reviewers). The commit history of your pull request, 535however, will stay intact on the pull request page. 536 537For the size of "one logical change", 538[0b5191f](https://github.com/nodejs/node/commit/0b5191f15d0f311c804d542b67e2e922d98834f8) 539can be a good example. It touches the implementation, the documentation, 540and the tests, but is still one logical change. All tests should always pass 541when each individual commit lands on one of the `nodejs/node` branches. 542 543### Getting approvals for your pull request 544 545A pull request is approved either by saying LGTM, which stands for 546"Looks Good To Me", or by using GitHub's Approve button. 547GitHub's pull request review feature can be used during the process. 548For more information, check out 549[the video tutorial](https://www.youtube.com/watch?v=HW0RPaJqm4g) 550or [the official documentation](https://help.github.com/articles/reviewing-changes-in-pull-requests/). 551 552After you push new changes to your branch, you need to get 553approval for these new changes again, even if GitHub shows "Approved" 554because the reviewers have hit the buttons before. 555 556### Waiting until the pull request gets landed 557 558A pull request needs to stay open for at least 48 hours from when it is 559submitted, even after it gets approved and passes the CI. This is to make sure 560that everyone has a chance to weigh in. If the changes are trivial, 561collaborators may decide it doesn't need to wait. A pull request may well take 562longer to be merged in. All these precautions are important because Node.js is 563widely used, so don't be discouraged! 564 565### Check out the collaborator guide 566 567If you want to know more about the code review and the landing process, see the 568[collaborator guide][]. 569 570### Appendix: subsystems 571 572* `lib/*.js` (`assert`, `buffer`, etc.) 573* `build` 574* `doc` 575* `lib / src` 576* `test` 577* `tools` 578 579You can find the full list of supported subsystems in the 580[nodejs/core-validate-commit][] repository. 581More than one subsystem may be valid for any particular issue or pull request. 582 583[Building guide]: ../../BUILDING.md 584[CI (Continuous Integration) test run]: #continuous-integration-testing 585[Code of Conduct]: https://github.com/nodejs/admin/blob/HEAD/CODE_OF_CONDUCT.md 586[Onboarding guide]: ../../onboarding.md 587[approved]: #getting-approvals-for-your-pull-request 588[benchmark results]: writing-and-running-benchmarks.md 589[collaborator guide]: collaborator-guide.md 590[guide for writing tests in Node.js]: writing-tests.md 591[hiding-a-comment]: https://help.github.com/articles/managing-disruptive-comments/#hiding-a-comment 592[https://ci.nodejs.org/]: https://ci.nodejs.org/ 593[nodejs/core-validate-commit]: https://github.com/nodejs/core-validate-commit/blob/main/lib/rules/subsystem.js 594[pull request template]: https://raw.githubusercontent.com/nodejs/node/HEAD/.github/PULL_REQUEST_TEMPLATE.md 595[running tests]: ../../BUILDING.md#running-tests 596