@@ -35,7 +35,7 @@ public class NodeFunctionInvoker : FunctionInvokerBase
35
35
private readonly string _entryPoint ;
36
36
37
37
private Func < object , Task < object > > _scriptFunc ;
38
- private Func < object , Task < object > > _clearRequireCache ;
38
+ private static Func < object , Task < object > > _clearRequireCache ;
39
39
private static Func < object , Task < object > > _globalInitializationFunc ;
40
40
private static string _functionTemplate ;
41
41
private static string _clearRequireCacheScript ;
@@ -98,7 +98,7 @@ private Func<object, Task<object>> ScriptFunc
98
98
}
99
99
}
100
100
101
- private Func < object , Task < object > > ClearRequireCacheFunc
101
+ private static Func < object , Task < object > > ClearRequireCacheFunc
102
102
{
103
103
get
104
104
{
@@ -238,6 +238,11 @@ protected override void OnScriptFileChanged(object sender, FileSystemEventArgs e
238
238
return ;
239
239
}
240
240
241
+ // clear the node module cache
242
+ // This is done for any files to ensure that, if a file change triggers
243
+ // a host restart, we leave the cache clean.
244
+ ClearRequireCacheFunc ( null ) . GetAwaiter ( ) . GetResult ( ) ;
245
+
241
246
// The ScriptHost is already monitoring for changes to function.json, so we skip those
242
247
string fileName = Path . GetFileName ( e . Name ) ;
243
248
if ( string . Compare ( fileName , ScriptConstants . FunctionMetadataFileName , StringComparison . OrdinalIgnoreCase ) != 0 )
@@ -246,9 +251,6 @@ protected override void OnScriptFileChanged(object sender, FileSystemEventArgs e
246
251
// force a reload on next execution
247
252
_scriptFunc = null ;
248
253
249
- // clear the node module cache
250
- ClearRequireCacheFunc ( null ) . GetAwaiter ( ) . GetResult ( ) ;
251
-
252
254
TraceOnPrimaryHost ( string . Format ( CultureInfo . InvariantCulture , "Script for function '{0}' changed. Reloading." , Metadata . Name ) , System . Diagnostics . TraceLevel . Info ) ;
253
255
}
254
256
}
0 commit comments