Our app was Meteor 2.7 and we decided to update it to 2.8 and migrate to new Async APIs.
At first, I thought I will go through function to function, component to component (we use React in front-end), but @mikkelking suggessed that I should consider to use some tools like codemod or jscodeshift. At this moment I agreed that’s brilliant idea. Thanks Mike.
I decided to learn jscodeshift and it’s interesting that jscodeshift wraps around recast library which benjamn (who is the most contributor of Meteor project) knows very well
You can find the transform scripts I wrote here: GitHub - minhna/meteor-async-migration
At first I thought It’s just some function renaming. But then I realized that once you made a single change, you Ignite a chain of changes. The function which contains the await
expression became async
function. Then you need to search for all places where that function was used, then add await
and async
and search … It depends on how your codes are but onc small change can lead to few dozens changes in other places.
But the problem is not how many changes you need to do, you may have time to do that. The real problem is what if you missed some?
The other problem is, while I’m working to migrate the app, other people were still working on other features. That means I need to make sure those new features/modifications will also works. It’s impossible if I do it manually or I need to ask people to stop working for months which is also imposible.
With those tools, I can do it faster and I can merge new codes and run on them.
But how do I know if the migration works? Fortunately we have integration tests (Mocha) and e2e tests (cypress).
For the integration tests, we use dburles:factory package to generate test data, which now support async APIs.
We also use johanbrook:publication-collector
package to test our publications. Unfortunately, it hasn’t support async publish function yet. I created a pull request but it looks like the package is abandoned. If you use this package, you can use my version at: GitHub - minhna/meteor-publication-collector: Test a Meteor publication by collecting its output.
This is the pull request for the migrating task.
Hopfully the tool can help someone migrating the existing Meteor app. Meteor is awesome. I love it.
Merry Christmas and Happy New Year.