What is the commonly accepted pattern to force initialization of a global state in es6 projects before any other code is executed?
//main.js
import './moduleA.js'
//Set up some state e.g. database connection or loggers.
logger.configure(...)
//moduleA.js
//access db or logger
logger.log("I will fail since I am not configured yet!");
export default = () =>{
....
}
If moduleA
requires access to the logger or the db connection they will fail, since the code of callee is resolved before the caller. Using an own module in which the initialization takes place and importing it before moduleA in the main will not solve the problem as the import resolution order is non deterministic.