|
| 1 | +# Express Collaborator Guide |
| 2 | + |
| 3 | +This document contains information for Collaborators of the express codemod regarding maintaining the code, documentation. |
| 4 | + |
| 5 | +## Getting Started |
| 6 | + |
| 7 | +The steps below will give you a general idea of how to prepare your local environment for the express codemods and general steps for getting things done and landing your contribution. |
| 8 | + |
| 9 | +1. [Create an issue](https://github.com/expressjs/codemod/issues/new) for the |
| 10 | + bug you want to fix or the feature that you want to add. |
| 11 | +2. Create your own [fork](https://github.com/expressjs/codemod) on GitHub |
| 12 | +3. Clone your fork using SSH, GitHub CLI, or HTTPS. |
| 13 | +```sh |
| 14 | +git clone [email protected]: <YOUR_GITHUB_USERNAME >/codemod.git # SSH |
| 15 | +git clone https://github.com/<YOUR_GITHUB_USERNAME>/codemod.git # HTTPS |
| 16 | +gh repo clone <YOUR_GITHUB_USERNAME>/codemod # GitHub CLI |
| 17 | +``` |
| 18 | +4. Change into the nodejs.org directory. |
| 19 | +```sh |
| 20 | +cd codemod |
| 21 | +``` |
| 22 | +5. Create a remote to keep your fork and local clone up-to-date. |
| 23 | +```sh |
| 24 | +git remote add upstream [email protected]:expressjs/codemod.git # SSH |
| 25 | +git remote add upstream https://github.com/expressjs/codemod.git # HTTPS |
| 26 | +gh repo sync expressjs/codemod # GitHub CLI |
| 27 | +``` |
| 28 | +6. Create a new branch for your work. |
| 29 | +```sh |
| 30 | +git checkout -b name-of-your-branch |
| 31 | +``` |
| 32 | +7. Run the following to install the dependencies and start a local build of your work. |
| 33 | +```sh |
| 34 | +npm ci # installs this project's dependencies |
| 35 | +npm run dev # starts a development environment |
| 36 | +``` |
| 37 | +8. Perform your changes |
| 38 | +8. Ensure your code is linted by running `npm run lint` -- fix any issue you |
| 39 | + see listed. |
| 40 | +9. If the tests pass, you can commit your changes to your fork and then create |
| 41 | + a pull request from there. Make sure to reference your issue from the pull |
| 42 | + request comments by including the issue number e.g. `#123`. |
| 43 | + |
| 44 | +## How to add codemods |
| 45 | + |
| 46 | +We use `jscodeshift` to create and run the codemods. To add a new codemod for Express, we follow the following process. |
| 47 | + |
| 48 | +1. Create a new file in the `transforms` directory. For example, `transforms/pluralized-methods.ts`. |
| 49 | + |
| 50 | +2. Write your codemod. Here's an example that pluralizes Express methods: |
| 51 | + |
| 52 | +```typescript |
| 53 | +// filepath: codemod/transforms/pluralized-methods.ts |
| 54 | +import type { API, FileInfo } from 'jscodeshift' |
| 55 | +import { Identifier, identifier } from 'jscodeshift' |
| 56 | +import { getParsedFile } from '../utils/parse' |
| 57 | + |
| 58 | +export default function transformer(file: FileInfo, _api: API): string { |
| 59 | + const parsedFile = getParsedFile(file) |
| 60 | + |
| 61 | + const identifierNamesToReplace = ['acceptsLanguage', 'acceptsCharset', 'acceptsEncoding'] |
| 62 | + |
| 63 | + for (const singular of identifierNamesToReplace) { |
| 64 | + const plural = `${singular}s` |
| 65 | + |
| 66 | + parsedFile |
| 67 | + .find(Identifier, { |
| 68 | + name: singular, |
| 69 | + }) |
| 70 | + .replaceWith(() => identifier(plural)) |
| 71 | + } |
| 72 | + |
| 73 | + return parsedFile.toSource() |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +3. Add tests to verify the functionality of the codemod |
| 78 | + - A new file is created in the `/transforms/__test__` directory with the same name as the codemod with the following content |
| 79 | + ```ts |
| 80 | + // filepath: codemod/transforms/__test__/pluralized-methods.ts |
| 81 | + |
| 82 | + import { testSpecBuilder } from './util' |
| 83 | + |
| 84 | + testSpecBuilder('magic-redirect') |
| 85 | + ``` |
| 86 | + - Two new files are created, `name-codemod.input.ts` and `name_codemod.output.ts`, inside the `/transforms/__testfixtures__` directory |
| 87 | + - The files ending in `.input.ts ` contain the content that should be changed by the codemod |
| 88 | + - The `.output.ts` files contain the content that should be present after the codemod has been correctly applied. |
| 89 | + |
| 90 | +4. To make the codemod visible within the CLI, the `config.ts` file is modified, where a brief description of the codemod, its name, and the version of Express to which the migration should be applied are added. |
| 91 | + |
| 92 | +## Developer's Certificate of Origin 1.1 |
| 93 | + |
| 94 | +```text |
| 95 | +By making a contribution to this project, I certify that: |
| 96 | +
|
| 97 | + (a) The contribution was created in whole or in part by me and I |
| 98 | + have the right to submit it under the open source license |
| 99 | + indicated in the file; or |
| 100 | +
|
| 101 | + (b) The contribution is based upon previous work that, to the best |
| 102 | + of my knowledge, is covered under an appropriate open source |
| 103 | + license and I have the right under that license to submit that |
| 104 | + work with modifications, whether created in whole or in part |
| 105 | + by me, under the same open source license (unless I am |
| 106 | + permitted to submit under a different license), as indicated |
| 107 | + in the file; or |
| 108 | +
|
| 109 | + (c) The contribution was provided directly to me by some other |
| 110 | + person who certified (a), (b) or (c) and I have not modified |
| 111 | + it. |
| 112 | +
|
| 113 | + (d) I understand and agree that this project and the contribution |
| 114 | + are public and that a record of the contribution (including all |
| 115 | + personal information I submit with it, including my sign-off) is |
| 116 | + maintained indefinitely and may be redistributed consistent with |
| 117 | + this project or the open source license(s) involved. |
| 118 | +``` |
0 commit comments