Looking for a tool which can help migrating Meteor 2.8

I put my codes here: GitHub - minhna/meteor-async-migration
Use with caution!

1 Like

Thanks for sharing, @minhna. Seems like it is possible to create a generic AST rule/selector that can be consumed by different tools. Will use your selectors to create a corresponding eslint rule

1 Like

Then it would be great if you can share your eslint rules

1 Like

I just stumbled upon https://ts-morph.com

It looks feasible to be able to convert entire call chains to async/await syntax using features such as reference finding (ts-morph - Finding References).

For example, our typical server-side code is similar to this (this is extremely simplified):

const myInternalMethod = (a:string):string=>{
   return MyCollection.findOne({a})?.field ?? "missing";
}

Meteor.methods({"MethodA",function (a:string){
   return myInternalMethod(a)
})

Tackling this piecemeal to find leaf methods that use collection methods should make it possible to write a script that takes e.g. “myInternalMethod” as a parameter - locates it in the project and finds all references recursively up all the way to where they are registered as Meteor method handlers.

Then the tool would need to modify all methods in that call tree to become async so that the end result is:

const myInternalMethod = async (a:string):Promise<string>=>{
   return MyCollection.findOne({a})?.field ?? "missing";
}

Meteor.methods({"MethodA",async function (a:string){
   return await myInternalMethod(a)
})

Once this is done, you can change the collection method invocation and be certain that 90% of the work is already done:

const myInternalMethod = async (a:string):Promise<string>=>{
   return (await MyCollection.findOneAsync({a}))?.field ?? "missing";
}
1 Like

Screenshot from 2022-12-15 17-39-31
It’s not finished yet but migrating a large codebase is hell :crazy_face:

Wow. Kudos to you @minhna. I cannot fathom to do this in one PR. I cannot even start it with all the business requirements we need to prioritize which just add up to this technical debt.

1 Like

Today I finished migrating a big app to use new Async API (Meteor 2.8). We will need to migrate few more functions which introduced in Meteor 2.9.
Screenshot from 2022-12-24 23-44-51
It looks pretty scary. 448 files changed with +11,611 −8,644.
I will write another post describe how I did it. Hopefully it will help other people migrating their app.

1 Like