Skip to content
Draft
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
17 changes: 17 additions & 0 deletions codemods/v5-migration-recipe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Migrate recipes for Express.js v5

This codemod migration recipe helps you update your Express.js v4 applications to be compatible with Express.js v5 by addressing deprecated APIs.

Included transformations:

- **Back Redirect Deprecated**: This transformation updates instances of `res.redirect('back')` and `res.location('back')` to use the recommended alternatives. Registry entry: [https://app.codemod.com/registry/expressjs/back-redirect-deprecated](https://app.codemod.com/registry/expressjs/back-redirect-deprecated).
- **Req Param**: Migrates usage of the legacy API `req.param(name)` to the current recommended alternatives. Registry entry: [https://app.codemod.com/registry/expressjs/req-param](https://app.codemod.com/registry/expressjs/req-param).
- **Pluralize Method Names**: Migrates deprecated singular request methods to their pluralized counterparts where applicable. Registry entry: [https://app.codemod.com/registry/expressjs/pluralize-method-names](https://app.codemod.com/registry/expressjs/pluralize-method-names).
- **Status Send Order**: Migrates usages of `res.send(status)`, `res.send(obj, status)`, `res.json(obj, status)`, and `res.jsonp(obj, status)` to the recommended argument ordering. Registry entry: [https://app.codemod.com/registry/expressjs/status-send-order](https://app.codemod.com/registry/expressjs/status-send-order).
- **Redirect Arg Order**: Converts `res.redirect(url, status)` calls to the recommended `res.redirect(status, url)` ordering. Registry entry: [https://app.codemod.com/registry/expressjs/redirect-arg-order](https://app.codemod.com/registry/expressjs/redirect-arg-order).
- **Camelcase Sendfile**: Replaces legacy `res.sendfile(file)` usages with the camel-cased `res.sendFile(file)` API. Registry entry: [https://app.codemod.com/registry/expressjs/camelcase-sendfile](https://app.codemod.com/registry/expressjs/camelcase-sendfile).
Comment on lines +7 to +12
Copy link
Member Author

Choose a reason for hiding this comment

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

The links are still to be confirmed, I’ll fix them once they’re in the registry.

- **Route Del to Delete**: Migrates usage of the legacy APIs `app.del()` to `app.delete()`. Registry entry: [https://app.codemod.com/registry/expressjs/route-del-to-delete](https://app.codemod.com/registry/expressjs/route-del-to-delete).

## References

- [Express.js v5 Migration Guide](https://expressjs.com/en/guide/migrating-5)
25 changes: 25 additions & 0 deletions codemods/v5-migration-recipe/codemod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
schema_version: "1.0"
name: "@expressjs/v5/migration-recipe"
version: "1.0.0"
description: This codemod migration recipe helps you update your Express.js v4 applications to be compatible with Express.js v5 by addressing deprecated APIs.
author: bjohansebas (Sebastian Beltran)
license: MIT
workflow: workflow.yaml
category: migration

targets:
languages:
- javascript
- typescript

keywords:
- transformation
- migration
- express
- v5
- v4
- legacy

registry:
access: public
visibility: public
19 changes: 19 additions & 0 deletions codemods/v5-migration-recipe/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@expressjs/v5-migration-recipe",
"private": true,
"version": "1.0.0",
"description": "This codemod migration recipe helps you update your Express.js v4 applications to be compatible with Express.js v5 by addressing deprecated APIs.",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/expressjs/codemod.git",
"directory": "codemods/v5-migration-recipe",
"bugs": "https://github.com/expressjs/codemod/issues"
},
"author": "bjohansebas (Sebastian Beltran)",
"license": "MIT",
"homepage": "https://github.com/expressjs/codemod/blob/main/codemods/v5-migration-recipe/README.md",
"devDependencies": {
"@codemod.com/jssg-types": "^1.3.1"
}
}
32 changes: 32 additions & 0 deletions codemods/v5-migration-recipe/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/codemod-com/codemod/refs/heads/main/schemas/workflow.json

version: "1"

nodes:
- id: apply-transforms
name: Apply AST Transformations
type: automatic
runtime:
type: direct
steps:
- name: Migrates usage of the legacy APIs `res.redirect('back')` and `res.location('back')` to the current recommended approaches
codemod:
source: "@expressjs/back-redirect-deprecated"
- name: Migrates usage of the legacy APIs `req.param(name)` to the current recommended approaches.
codemod:
source: "@expressjs/req-param"
- name: Migrates usage of deprecated singular request methods to their pluralized versions in Express.js applications.
codemod:
source: "@expressjs/pluralize-method-names"
- name: Migrates usage of the legacy APIs `res.send(status)`, `res.send(obj, status)`, `res.json(obj, status)` and `res.jsonp(obj, status)` to the current recommended approaches
codemod:
source: "@expressjs/status-send-order"
- name: Migrates usage of the legacy APIs `res.redirect(url, status)` to use the recommended argument order `res.redirect(status, url)`.
codemod:
source: "@expressjs/redirect-arg-order"
- name: Migrates usage of the legacy API `res.sendfile(file)` to `res.sendFile(file)`
codemod:
source: "@expressjs/camelcase-sendfile"
- name: Migrates usage of the legacy APIs `app.del()` to `app.delete()`
codemod:
source: "@expressjs/route-del-to-delete"