Skip to content

feat(magic-redirect): migrate magic-redirect to codemod.com#91

Merged
bjohansebas merged 10 commits intomainfrom
magic-redirect-codemod
Dec 24, 2025
Merged

feat(magic-redirect): migrate magic-redirect to codemod.com#91
bjohansebas merged 10 commits intomainfrom
magic-redirect-codemod

Conversation

@bjohansebas
Copy link
Member

@bjohansebas bjohansebas commented Dec 14, 2025

I’ve just migrated the codemod to use ast-grep, which is what Codemod uses under the hood. I copied the tests from the old CLI and added more tests to ensure it works correctly.

I didn’t remove the files from the old codemod that uses jscodeshift so this PR is easier to review. In the future, once we’ve completed all the migrations, we can remove the old CLI in a single PR

@socket-security
Copy link

socket-security bot commented Dec 14, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​codemod.com/​jssg-types@​1.3.1801007494100

View full report

@bjohansebas bjohansebas force-pushed the magic-redirect-codemod branch 2 times, most recently from 63b5b32 to ced14f3 Compare December 14, 2025 20:28
@bjohansebas bjohansebas marked this pull request as ready for review December 14, 2025 23:47
@bjohansebas
Copy link
Member Author

Hey @expressjs/codemod-collaborators @AugustinMauroy @alexbit-codemod, I’d love your review here, this would be the first codemod to be released on the platform 🙂

@mohebifar
Copy link
Contributor

Hey @bjohansebas! Thank you for using Codemod's JSSG and ast-grep! I just opened a PR to merge to your branch:

#92

I refactored the code to use JSSG's semantic analysis tools (node.definition()). That simplifies the code a lot while making it more reliable. So basically, after grabbing all $OBJ.$METHOD('back') (with METHOD being either location or redirect), we check the definition of $OBJ and make sure its part of the function params. And use the same parameters list to grab the first param (req)

* refactor: refactor the express codemod

* fix lint

Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>

---------

Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>
Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>
Copy link
Contributor

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

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

what if there are another method called redirect ? from my comprehension it's will be modified so we need to create a new workflow logic:

catch express import => with that catch all app => catch all usage of the app => read the call back => modify the arg

It's look complex but there are an esay way which is https://docs.codemod.com/jssg/semantic-analysis (on user lad migration we don't use it for now since this api is new)

in overall it's LGTM.

package.json Outdated
"node": ">=18"
}
},
"workspaces": ["./recipes/*"]
Copy link
Contributor

Choose a reason for hiding this comment

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

use codemod dir recipes was a mistake from userland migration

@bjohansebas
Copy link
Member Author

what if there are another method called redirect ? from my comprehension it's will be modified so we need to create a new workflow logic:

i think this would go further than necessary and would be fairly extreme cases, I’d prefer to keep it simple as it is right now. What do you think?

@AugustinMauroy
Copy link
Contributor

what if there are another method called redirect ? from my comprehension it's will be modified so we need to create a new workflow logic:

i think this would go further than necessary and would be fairly extreme cases, I’d prefer to keep it simple as it is right now. What do you think?

I didn't have strong opinions but start by that and then update if there are report

@bjohansebas
Copy link
Member Author

Since it's end of year and many of us are on vacation, and I'm unsure if they're available to approve the release, I'll merge this to main, but we won't do the release yet (i.e., create the tag that'll deploy to the platform) as it needs another person's approval. Hopefully, the second week of January or sooner if possible, we can do the release when the team is back, along with the other codemods.

@bjohansebas bjohansebas merged commit ba25f2f into main Dec 24, 2025
23 checks passed
@bjohansebas bjohansebas deleted the magic-redirect-codemod branch December 24, 2025 03:00
@bjohansebas bjohansebas mentioned this pull request Dec 26, 2025
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants