Skip to content

Commit 46ce85f

Browse files
chore: remove old package (#96)
* chore: remove old package * docs: update docs * docs: update contributing guide with new codemod initialization steps * Update README.md Co-authored-by: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com> * chore(package.json): remove obsolete bin and engines fields * Apply suggestion from @bjohansebas Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com> --------- Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com> Co-authored-by: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com>
1 parent 943bf41 commit 46ce85f

54 files changed

Lines changed: 221 additions & 6788 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/actions/generate-help-docs.mjs

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
fail-fast: false
4343
matrix:
4444
os: [ubuntu-latest, windows-latest, macos-latest]
45-
node-version: [18, 19, 20, 21, 22, 23]
45+
node-version: [18, 19, 20, 21, 22, 23, 24, 25]
4646
# Node.js release schedule: https://nodejs.org/en/about/releases/
4747

4848
name: Node.js ${{ matrix.node-version }} - ${{matrix.os}}
@@ -71,11 +71,6 @@ jobs:
7171
echo "Node.js version: $(node -v)"
7272
echo "NPM version: $(npm -v)"
7373
74-
- name: Run tests-legacy cli
75-
shell: bash
76-
run: |
77-
npm run test-legacy:ci
78-
7974
- name: Run test
8075
shell: bash
8176
run: |

.github/workflows/generate-readme.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,86 +8,71 @@ The steps below will give you a general idea of how to prepare your local enviro
88

99
1. [Create an issue](https://github.com/expressjs/codemod/issues/new) for the
1010
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.
11+
12+
1. Create your own [fork](https://github.com/expressjs/codemod) on GitHub
13+
14+
1. Clone your fork using SSH, GitHub CLI, or HTTPS.
15+
1316
```sh
1417
git clone git@github.com:<YOUR_GITHUB_USERNAME>/codemod.git # SSH
1518
git clone https://github.com/<YOUR_GITHUB_USERNAME>/codemod.git # HTTPS
1619
gh repo clone <YOUR_GITHUB_USERNAME>/codemod # GitHub CLI
1720
```
18-
4. Change into the nodejs.org directory.
21+
22+
1. Change into the codemod directory.
1923
```sh
2024
cd codemod
2125
```
22-
5. Create a remote to keep your fork and local clone up-to-date.
26+
27+
1. Create a remote to keep your fork and local clone up-to-date.
28+
2329
```sh
2430
git remote add upstream git@github.com:expressjs/codemod.git # SSH
2531
git remote add upstream https://github.com/expressjs/codemod.git # HTTPS
2632
gh repo sync expressjs/codemod # GitHub CLI
2733
```
28-
6. Create a new branch for your work.
34+
35+
1. Create a new branch for your work.
36+
2937
```sh
3038
git checkout -b name-of-your-branch
3139
```
32-
7. Run the following to install the dependencies and start a local build of your work.
40+
41+
1. Run the following to install the dependencies.
42+
3343
```sh
3444
npm ci # installs this project's dependencies
35-
npm run dev # starts a development environment
45+
3646
```
37-
8. Perform your changes
38-
9. Ensure your code is linted by running `npm run lint` -- fix any issue you
47+
1. create the [new codemod](#how-to-add-codemods) or make your changes.
48+
49+
1. Ensure your code is linted by running `npm run lint` -- fix any issue you
3950
see listed.
40-
10. If the tests pass, you can commit your changes to your fork and then create
51+
52+
1. If the tests pass, you can commit your changes to your fork and then create
4153
a pull request from there. Make sure to reference your issue from the pull
4254
request comments by including the issue number e.g. `#123`.
4355

4456
## How to add codemods
4557

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)
58+
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:
6059

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-
}
60+
```sh
61+
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
7562
```
7663

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
64+
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.
8165

82-
import { testSpecBuilder } from './util'
66+
## Useful Resources
8367

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.
68+
- [Codemod CLI Reference](https://docs.codemod.com/cli/cli-reference)
69+
- [Codemod Workflow Documentation](https://docs.codemod.com/cli/workflows)
70+
- [Codemod Studio Documentation](https://docs.codemod.com/codemod-studio)
71+
- [JS ast-grep (jssg) API reference](https://docs.codemod.com/jssg/reference)
72+
- [JS ast-grep Testing Utilities](https://docs.codemod.com/jssg/testing)
73+
- [JS ast-grep Semantic Analysis](https://docs.codemod.com/jssg/semantic-analysis)
74+
- [ast-grep Documentation](https://ast-grep.github.io/)
8975

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.
9176

9277
## Developer's Certificate of Origin 1.1
9378

README.md

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,34 @@
11
# @expressjs/codemod
22

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

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

97
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.
108

11-
## Installation
9+
## Usage
1210

13-
You don't need to install this package, run the following command:
11+
### From Registry
1412

15-
```sh
16-
npx @expressjs/codemod # or pnpx, bunx, etc.
17-
```
18-
19-
or install globally:
13+
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:
2014

2115
```sh
22-
npm i -g @expressjs/codemod # or pnpm, bun, etc.
16+
npx codemod @expressjs/<codemod>
2317
```
2418

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

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

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

25+
```sh
26+
git clone https://github.com/expressjs/codemod.git
27+
cd /path/to/your-project
28+
npx codemod workflow run -w /path/to/codemod/codemods/<recipe>/workflow.yaml
3129
```
32-
Usage: @expressjs/codemod [codemod] [source] [options]
33-
34-
Options:
35-
-v, --version Output the current version of @expressjs/codemod.
36-
-d, --dry Dry run (no changes are made to files)
37-
-p, --print Print transformed files to stdout
38-
--verbose Show more information about the transform process
39-
--silent Don't print anything to stdout
40-
-h, --help Display this help message.
41-
42-
Commands:
43-
upgrade [options] [source] Upgrade your express server to the latest
44-
version.
45-
```
46-
47-
<!-- USAGE END -->
48-
49-
## Available Codemods
50-
51-
All the available codemods to update your express server:
52-
53-
<!-- CODEMODS START -->
54-
55-
### magic redirect (v5.0.0)
56-
57-
Transform the deprecated magic string "back"
58-
59-
### pluralized methods (v5.0.0)
60-
61-
Transform the methods to their pluralized versions
62-
63-
### v4 deprecated signatures (v5.0.0)
64-
65-
Transform the deprecated signatures in Express v4
66-
67-
### req param (v5.0.0)
68-
69-
Change request.param() to dedicated methods
7030

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

7333
## Contributing
7434

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

8444
[MIT](LICENSE)
8545

86-
[npm-downloads-image]: https://badgen.net/npm/dm/@expressjs/codemod
87-
[npm-downloads-url]: https://npmcharts.com/compare/@expressjs/codemod?minimal=true
88-
[npm-url]: https://npmjs.org/package/@expressjs/codemod
89-
[npm-version-image]: https://badgen.net/npm/v/@expressjs/codemod
9046
[ossf-scorecard-badge]: https://api.scorecard.dev/projects/github.com/expressjs/codemod/badge
9147
[ossf-scorecard-visualizer]: https://ossf.github.io/scorecard-visualizer/#/projects/github.com/expressjs/codemod

codemods/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)