Update a field in custom field before everything else is run

I’m writing a plugin which is responsible to load configs based on deployment stage and update a field in custom section of the template.yml .

The plugin works fine but the timing where config is loaded is wrong. The plugin is run on before:package:cleanup hook. Which I thought is the earliest hook that is run. However, it seems like the configs are not picked up by my resources (lambdas).

In particular, i see the following warning:
A valid service attribute to satisfy the declaration 'self:custom.envConfig.XX' could not be found.
but after this I get:

    Serverless: Invoke deploy
    Serverless: Invoke package
    Serverless: Now Custom is:  {"stage":"dev","envConfig":{"XX":"XXvalue"}}

So the plugin sets the custom field correctly. But it’s not doing it in a right time.
I’m hoping that I can just update the serverless.variables.service.custom.envConfig field in my plugin and everything else follows the same as if the config was read from a json file.

I know there is a tool to read json files and read keys from parameters. But for my use case i need to write the plugin.

Any help on how I can achieve this ?