@@ -110,6 +110,20 @@ function _loadUserApp(
110110 }
111111}
112112
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+
113127function _throwIfInvalidHandler ( fullHandlerString : string ) : void {
114128 if ( fullHandlerString . includes ( RELATIVE_PATH_SUBSTRING ) ) {
115129 throw new MalformedHandlerName (
@@ -137,10 +151,10 @@ function _throwIfInvalidHandler(fullHandlerString: string): void {
137151 * for traversing up the filesystem '..')
138152 * Errors for scenarios known by the runtime, will be wrapped by Runtime.* errors.
139153 */
140- export const load = function (
154+ export const load = async function (
141155 appRoot : string ,
142156 fullHandlerString : string
143- ) : HandlerFunction {
157+ ) : Promise < HandlerFunction > {
144158 _throwIfInvalidHandler ( fullHandlerString ) ;
145159
146160 const [ moduleRoot , moduleAndHandler ] = _moduleRootAndHandler (
@@ -149,6 +163,9 @@ export const load = function (
149163 const [ module , handlerPath ] = _splitHandlerString ( moduleAndHandler ) ;
150164
151165 const userApp = _loadUserApp ( appRoot , moduleRoot , module ) ;
166+
167+ await _initializeFunction ( userApp ) ;
168+
152169 const handlerFunc = _resolveHandler ( userApp , handlerPath ) ;
153170
154171 if ( ! handlerFunc ) {
0 commit comments