@@ -110,6 +110,20 @@ function _loadUserApp(
110
110
}
111
111
}
112
112
113
+ async function _initializeFunction ( userApp : any ) : Promise < void > {
114
+ try {
115
+ await userApp . initializeFunction ( ) ;
116
+ } catch ( e ) {
117
+ if ( e instanceof TypeError ) {
118
+ // initializeFunction lifecycle hook not implemented
119
+ return ;
120
+ }
121
+ else {
122
+ throw e ;
123
+ }
124
+ }
125
+ }
126
+
113
127
function _throwIfInvalidHandler ( fullHandlerString : string ) : void {
114
128
if ( fullHandlerString . includes ( RELATIVE_PATH_SUBSTRING ) ) {
115
129
throw new MalformedHandlerName (
@@ -137,10 +151,10 @@ function _throwIfInvalidHandler(fullHandlerString: string): void {
137
151
* for traversing up the filesystem '..')
138
152
* Errors for scenarios known by the runtime, will be wrapped by Runtime.* errors.
139
153
*/
140
- export const load = function (
154
+ export const load = async function (
141
155
appRoot : string ,
142
156
fullHandlerString : string
143
- ) : HandlerFunction {
157
+ ) : Promise < HandlerFunction > {
144
158
_throwIfInvalidHandler ( fullHandlerString ) ;
145
159
146
160
const [ moduleRoot , moduleAndHandler ] = _moduleRootAndHandler (
@@ -149,6 +163,9 @@ export const load = function (
149
163
const [ module , handlerPath ] = _splitHandlerString ( moduleAndHandler ) ;
150
164
151
165
const userApp = _loadUserApp ( appRoot , moduleRoot , module ) ;
166
+
167
+ await _initializeFunction ( userApp ) ;
168
+
152
169
const handlerFunc = _resolveHandler ( userApp , handlerPath ) ;
153
170
154
171
if ( ! handlerFunc ) {
0 commit comments