Skip to main content

If you have been using the beta release of mirage, chances are that you haven’t made the jump from beta.7 to beta.9 because some of the breaking deprecations.

The deprecations are not super complicated but if you have a lot of tests files then it can be a very boring and task consuming task.

Instead of fixing my code manually, I thought about my old friend recast to automate the whole process , but then I remembered this “new” tool called jscodeshift which offers a nice API on top of recast to do code modifications.

The following script help us with the first deprecation listed here which is pluralizing all the schema models. If we have something like schema.user.all() or server.schema.user.all() then after running the script we’ll have schema.users.all().

To run the script we need to install the following npm packages:

1
2
npm install -g jscodeshift
npm install inflected

For the second breaking deprecation which was calling .models on Collections, I decided not to use codeshift since it would be faster for me to just use perl:

1
2
find . -type f | xargs perl -pi -e 's/all\(\)\.length/all\(\)\.models\.length/g'
find . -type f | xargs perl -pi -e 's/all\(\)\.forEach/all\(\)\.models\.forEach/g'

I hope you find this useful and if come up with a codeshift solution please let me know and I’ll link it here.

Do you Want to learn about JSONAPI? Check out my book JSONAPI By Example.