@@ -4,6 +4,7 @@ import type * as FridaScript from "../FridaScript.ts";
44import * as FileSystem from "@effect/platform/FileSystem" ;
55import * as Path from "@effect/platform/Path" ;
66import * as Cause from "effect/Cause" ;
7+ import * as Chunk from "effect/Chunk" ;
78import * as Context from "effect/Context" ;
89import * as Deferred from "effect/Deferred" ;
910import * as Effect from "effect/Effect" ;
@@ -386,7 +387,7 @@ export const watch = Function.dual<
386387 effect : Effect . Effect < A , E , R >
387388 ) => Effect . Effect <
388389 void ,
389- E | FridaSessionError . FridaSessionError ,
390+ FridaSessionError . FridaSessionError ,
390391 FileSystem . FileSystem | FridaSession . FridaSession | Exclude < R , FridaScript . FridaScript >
391392 > ,
392393 < A , E , R > (
@@ -395,7 +396,7 @@ export const watch = Function.dual<
395396 options ?: FridaScript . LoadOptions | undefined
396397 ) => Effect . Effect <
397398 void ,
398- E | FridaSessionError . FridaSessionError ,
399+ FridaSessionError . FridaSessionError ,
399400 FileSystem . FileSystem | FridaSession . FridaSession | Exclude < R , FridaScript . FridaScript >
400401 >
401402> (
@@ -406,7 +407,7 @@ export const watch = Function.dual<
406407 options ?: FridaScript . LoadOptions | undefined
407408 ) : Effect . Effect <
408409 void ,
409- E | FridaSessionError . FridaSessionError ,
410+ FridaSessionError . FridaSessionError ,
410411 FileSystem . FileSystem | FridaSession . FridaSession | Exclude < R , FridaScript . FridaScript >
411412 > =>
412413 Effect . gen ( function * ( ) {
@@ -422,10 +423,21 @@ export const watch = Function.dual<
422423 } )
423424 ) ;
424425
425- const provideFridaScript = Effect . provideServiceEffect ( Tag , load ( entrypoint , options ) ) ;
426- const sink = Sink . forEach ( ( _ : void ) => provideFridaScript ( effect ) . pipe ( Effect . scoped ) ) ;
426+ const sink = Sink . forEach ( ( event : FileSystem . WatchEvent . Update ) =>
427+ Function . pipe (
428+ Effect . logDebug ( `reloading ${ event . path } ` ) ,
429+ Effect . andThen ( effect ) ,
430+ Effect . andThen ( Effect . logDebug ( `script completed` ) ) ,
431+ Effect . provideServiceEffect ( Tag , load ( entrypoint , options ) ) ,
432+ Effect . scoped ,
433+ Effect . catchAll ( Effect . logError ) ,
434+ Effect . catchAllDefect ( Effect . logError )
435+ )
436+ ) ;
437+
427438 const stream = fileSystem . watch ( pathString ) . pipe (
428439 Stream . filter ( ( event ) => event . _tag === "Update" ) ,
440+ Stream . prepend ( Chunk . of ( FileSystem . WatchEventUpdate ( { path : pathString } ) ) ) ,
429441 Stream . mapError (
430442 ( cause ) =>
431443 new FridaSessionError . FridaSessionError ( {
0 commit comments