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