@@ -23,16 +23,25 @@ export const setupHotreloading = async (
2323 } ) ;
2424 } ) ;
2525
26+ const projectRoot = process . cwd ( ) ;
2627 const absolutePathToDocumentsDirectory = path . resolve (
27- process . cwd ( ) ,
28+ projectRoot ,
2829 emailDirRelativePath ,
2930 ) ;
3031
31- logger . info ( `Watching ${ absolutePathToDocumentsDirectory } ` ) ;
32+ logger . info ( `Watching project root at ${ projectRoot } ` ) ;
3233
33- const watcher = watch ( '' , {
34+ const watcher = watch ( '**/* ' , {
3435 ignoreInitial : true ,
35- cwd : absolutePathToDocumentsDirectory ,
36+ cwd : projectRoot ,
37+ ignored : [
38+ '**/node_modules/**' ,
39+ '**/.git/**' ,
40+ '**/dist/**' ,
41+ '**/build/**' ,
42+ '**/.next/**' ,
43+ '**/coverage/**' ,
44+ ] ,
3645 } ) ;
3746
3847 const exit = ( ) => {
@@ -96,25 +105,34 @@ export const setupHotreloading = async (
96105
97106 logger . debug ( `Detected ${ event } in ${ relativePathToChangeTarget } ` ) ;
98107
99- const pathToChangeTarget = path . resolve (
100- absolutePathToDocumentsDirectory ,
101- relativePathToChangeTarget ,
102- ) ;
103- await updateDependencyGraph ( event , pathToChangeTarget ) ;
108+ // Convert the path to be relative to the documents directory if it's within it
109+ const absolutePathToChangeTarget = path . resolve ( projectRoot , relativePathToChangeTarget ) ;
110+ const isInDocumentsDirectory = absolutePathToChangeTarget . startsWith ( absolutePathToDocumentsDirectory ) ;
111+
112+ if ( isInDocumentsDirectory ) {
113+ const pathRelativeToDocuments = path . relative ( absolutePathToDocumentsDirectory , absolutePathToChangeTarget ) ;
114+
115+ await updateDependencyGraph ( event , absolutePathToChangeTarget ) ;
104116
105- changes . push ( {
106- event,
107- filename : relativePathToChangeTarget ,
108- } ) ;
117+ changes . push ( {
118+ event,
119+ filename : pathRelativeToDocuments ,
120+ } ) ;
109121
110- // These dependents are dependents resolved recursively, so even dependents of dependents
111- // will be notified of this change so that we ensure that things are updated in the preview.
112- for ( const dependentPath of resolveDependentsOf ( pathToChangeTarget ) ) {
122+ for ( const dependentPath of resolveDependentsOf ( absolutePathToChangeTarget ) ) {
123+ changes . push ( {
124+ event : 'change' as const ,
125+ filename : path . relative ( absolutePathToDocumentsDirectory , dependentPath ) ,
126+ } ) ;
127+ }
128+ } else {
129+ // For files outside documents directory, just notify of the change relative to project root
113130 changes . push ( {
114- event : 'change' as const ,
115- filename : path . relative ( absolutePathToDocumentsDirectory , dependentPath ) ,
131+ event,
132+ filename : relativePathToChangeTarget ,
116133 } ) ;
117134 }
135+
118136 reload ( ) ;
119137 } ) ;
120138
0 commit comments