Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .github/actions/generate-help-docs.mjs

This file was deleted.

7 changes: 1 addition & 6 deletions .github/workflows/ci.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use node its to do npm ci => node --run test and remove matrix

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [18, 19, 20, 21, 22, 23]
node-version: [18, 19, 20, 21, 22, 23, 24, 25]
# Node.js release schedule: https://nodejs.org/en/about/releases/

name: Node.js ${{ matrix.node-version }} - ${{matrix.os}}
Expand Down Expand Up @@ -71,11 +71,6 @@ jobs:
echo "Node.js version: $(node -v)"
echo "NPM version: $(npm -v)"

- name: Run tests-legacy cli
shell: bash
run: |
npm run test-legacy:ci

- name: Run test
shell: bash
run: |
Expand Down
49 changes: 0 additions & 49 deletions .github/workflows/generate-readme.yml

This file was deleted.

83 changes: 34 additions & 49 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,86 +8,71 @@ The steps below will give you a general idea of how to prepare your local enviro

1. [Create an issue](https://github.com/expressjs/codemod/issues/new) for the
bug you want to fix or the feature that you want to add.
2. Create your own [fork](https://github.com/expressjs/codemod) on GitHub
3. Clone your fork using SSH, GitHub CLI, or HTTPS.

1. Create your own [fork](https://github.com/expressjs/codemod) on GitHub

1. Clone your fork using SSH, GitHub CLI, or HTTPS.

```sh
git clone git@github.com:<YOUR_GITHUB_USERNAME>/codemod.git # SSH
git clone https://github.com/<YOUR_GITHUB_USERNAME>/codemod.git # HTTPS
gh repo clone <YOUR_GITHUB_USERNAME>/codemod # GitHub CLI
```
4. Change into the nodejs.org directory.

1. Change into the codemod directory.
```sh
cd codemod
```
5. Create a remote to keep your fork and local clone up-to-date.

1. Create a remote to keep your fork and local clone up-to-date.

```sh
git remote add upstream git@github.com:expressjs/codemod.git # SSH
git remote add upstream https://github.com/expressjs/codemod.git # HTTPS
gh repo sync expressjs/codemod # GitHub CLI
```
6. Create a new branch for your work.

1. Create a new branch for your work.

```sh
git checkout -b name-of-your-branch
```
7. Run the following to install the dependencies and start a local build of your work.

1. Run the following to install the dependencies.

```sh
npm ci # installs this project's dependencies
npm run dev # starts a development environment

```
8. Perform your changes
9. Ensure your code is linted by running `npm run lint` -- fix any issue you
1. create the [new codemod](#how-to-add-codemods) or make your changes.

1. Ensure your code is linted by running `npm run lint` -- fix any issue you
see listed.
10. If the tests pass, you can commit your changes to your fork and then create

1. If the tests pass, you can commit your changes to your fork and then create
a pull request from there. Make sure to reference your issue from the pull
request comments by including the issue number e.g. `#123`.

## How to add codemods

We use `jscodeshift` to create and run the codemods. To add a new codemod for Express, we follow the following process.

1. Create a new file in the `transforms` directory. For example, `transforms/pluralized-methods.ts`.

2. Write your codemod. Here's an example that pluralizes Express methods:

```typescript
// filepath: codemod/transforms/pluralized-methods.ts
import type { API, FileInfo } from 'jscodeshift'
import { Identifier, identifier } from 'jscodeshift'
import { getParsedFile } from '../utils/parse'

export default function transformer(file: FileInfo, _api: API): string {
const parsedFile = getParsedFile(file)
Each codemod recides in its own directory inside the `codemods` folder. For initializing a new codemod, you can use the following command in the root of the repository and change the parameters as needed:

const identifierNamesToReplace = ['acceptsLanguage', 'acceptsCharset', 'acceptsEncoding']

for (const singular of identifierNamesToReplace) {
const plural = `${singular}s`

parsedFile
.find(Identifier, {
name: singular,
})
.replaceWith(() => identifier(plural))
}

return parsedFile.toSource()
}
```sh
npx codemod init codemods/name-of-codemod --name @expressjs/name-of-codemod --description "Brief description of the codemod" --git-repository-url "git+https://github.com/expressjs/codemod.git" --author "your-github-username (Your Name)" --language typescript --project-type ast-grep-js --package-manager npm --license MIT --no-interactive
```

3. Add tests to verify the functionality of the codemod
- A new file is created in the `/transforms/__test__` directory with the same name as the codemod with the following content
```ts
// filepath: codemod/transforms/__test__/pluralized-methods.ts
Then, rename the `scripts` folder to `src` to keep it consistent with the rest of the repository. After that, you can start implementing your codemod by editing the `codemod.yaml` file and adding any additional files your codemod requires.

import { testSpecBuilder } from './util'
## Useful Resources

testSpecBuilder('magic-redirect')
```
- Two new files are created, `name-codemod.input.ts` and `name_codemod.output.ts`, inside the `/transforms/__testfixtures__` directory
- The files ending in `.input.ts ` contain the content that should be changed by the codemod
- The `.output.ts` files contain the content that should be present after the codemod has been correctly applied.
- [Codemod CLI Reference](https://docs.codemod.com/cli/cli-reference)
- [Codemod Workflow Documentation](https://docs.codemod.com/cli/workflows)
- [Codemod Studio Documentation](https://docs.codemod.com/codemod-studio)
- [JS ast-grep (jssg) API reference](https://docs.codemod.com/jssg/reference)
- [JS ast-grep Testing Utilities](https://docs.codemod.com/jssg/testing)
- [JS ast-grep Semantic Analysis](https://docs.codemod.com/jssg/semantic-analysis)
- [ast-grep Documentation](https://ast-grep.github.io/)

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.

## Developer's Certificate of Origin 1.1

Expand Down
68 changes: 12 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,34 @@
# @expressjs/codemod

[![NPM Version][npm-version-image]][npm-url]
[![NPM Downloads][npm-downloads-image]][npm-downloads-url]
[![OpenSSF Scorecard Badge][ossf-scorecard-badge]][ossf-scorecard-visualizer]

Express.js provides Codemod transforms to help you upgrade your express server when a feature is deprecated or removed.

Codemods are transformations that run on your codebase programmatically. This allows for a large amount of changes to be applied without having to manually go through every file.

## Installation
## Usage

You don't need to install this package, run the following command:
### From Registry

```sh
npx @expressjs/codemod # or pnpx, bunx, etc.
```

or install globally:
With the codemod CLI you can run a workflow from the Codemod Registry. Replace `<codemod>` with the name of the codemod you want to run:

```sh
npm i -g @expressjs/codemod # or pnpm, bun, etc.
npx codemod @expressjs/<codemod>
```

## Usage
For see the list of available codemods, visit the [Express.js Codemod Registry](https://codemod.link/express).

Use `@expressjs/codemod -h` to explore available command-line options.
### From source

<!-- USAGE START -->
You can also clone the repository and run the codemods locally. First, clone the repository:

```sh
git clone https://github.com/expressjs/codemod.git
cd /path/to/your-project
npx codemod workflow run -w /path/to/codemod/codemods/<recipe>/workflow.yaml
```
Usage: @expressjs/codemod [codemod] [source] [options]

Options:
-v, --version Output the current version of @expressjs/codemod.
-d, --dry Dry run (no changes are made to files)
-p, --print Print transformed files to stdout
--verbose Show more information about the transform process
--silent Don't print anything to stdout
-h, --help Display this help message.

Commands:
upgrade [options] [source] Upgrade your express server to the latest
version.
```

<!-- USAGE END -->

## Available Codemods

All the available codemods to update your express server:

<!-- CODEMODS START -->

### magic redirect (v5.0.0)

Transform the deprecated magic string "back"

### pluralized methods (v5.0.0)

Transform the methods to their pluralized versions

### v4 deprecated signatures (v5.0.0)

Transform the deprecated signatures in Express v4

### req param (v5.0.0)

Change request.param() to dedicated methods

<!-- CODEMODS END -->
See the [codemod CLI doc](https://docs.codemod.com/cli) for a full list of available commands.

## Contributing

Expand All @@ -83,9 +43,5 @@ See the [Contributing Guide](https://github.com/expressjs/codemod/blob/main/CONT

[MIT](LICENSE)

[npm-downloads-image]: https://badgen.net/npm/dm/@expressjs/codemod
[npm-downloads-url]: https://npmcharts.com/compare/@expressjs/codemod?minimal=true
[npm-url]: https://npmjs.org/package/@expressjs/codemod
[npm-version-image]: https://badgen.net/npm/v/@expressjs/codemod
[ossf-scorecard-badge]: https://api.scorecard.dev/projects/github.com/expressjs/codemod/badge
[ossf-scorecard-visualizer]: https://ossf.github.io/scorecard-visualizer/#/projects/github.com/expressjs/codemod
Empty file removed codemods/.gitkeep
Empty file.
Loading