diff --git a/codemods/v5-migration-recipe/README.md b/codemods/v5-migration-recipe/README.md new file mode 100644 index 0000000..3b1abc1 --- /dev/null +++ b/codemods/v5-migration-recipe/README.md @@ -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). +- **Explicit Request Params**: Migrates usage of the legacy API `req.param(name)` to the current recommended alternatives. Registry entry: [https://app.codemod.com/registry/@expressjs/explicit-request-params](https://app.codemod.com/registry/@expressjs/explicit-request-params). +- **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). +- **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) diff --git a/codemods/v5-migration-recipe/codemod.yaml b/codemods/v5-migration-recipe/codemod.yaml new file mode 100644 index 0000000..418dc9e --- /dev/null +++ b/codemods/v5-migration-recipe/codemod.yaml @@ -0,0 +1,26 @@ +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 +repository: "https://github.com/expressjs/codemod/tree/HEAD/codemods/v5-migration-recipe" +category: migration + +targets: + languages: + - javascript + - typescript + +keywords: + - transformation + - migration + - express + - v5 + - v4 + - legacy + +registry: + access: public + visibility: public \ No newline at end of file diff --git a/codemods/v5-migration-recipe/package.json b/codemods/v5-migration-recipe/package.json new file mode 100644 index 0000000..7663ab4 --- /dev/null +++ b/codemods/v5-migration-recipe/package.json @@ -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" + } +} diff --git a/codemods/v5-migration-recipe/workflow.yaml b/codemods/v5-migration-recipe/workflow.yaml new file mode 100644 index 0000000..77ae2fd --- /dev/null +++ b/codemods/v5-migration-recipe/workflow.yaml @@ -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/explicit-request-params" + - 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" \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f9dd8a2..fc318a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -113,6 +113,14 @@ "@codemod.com/jssg-types": "^1.3.1" } }, + "codemods/v5-migration-recipe": { + "name": "@expressjs/v5-migration-recipe", + "version": "1.0.0", + "license": "MIT", + "devDependencies": { + "@codemod.com/jssg-types": "^1.3.1" + } + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -1098,6 +1106,10 @@ "resolved": "codemods/status-send-order", "link": true }, + "node_modules/@expressjs/v5-migration-recipe": { + "resolved": "codemods/v5-migration-recipe", + "link": true + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",