@@ -23,16 +23,25 @@ export const setupHotreloading = async (
23
23
} ) ;
24
24
} ) ;
25
25
26
+ const projectRoot = process . cwd ( ) ;
26
27
const absolutePathToDocumentsDirectory = path . resolve (
27
- process . cwd ( ) ,
28
+ projectRoot ,
28
29
emailDirRelativePath ,
29
30
) ;
30
31
31
- logger . info ( `Watching ${ absolutePathToDocumentsDirectory } ` ) ;
32
+ logger . info ( `Watching project root at ${ projectRoot } ` ) ;
32
33
33
- const watcher = watch ( '' , {
34
+ const watcher = watch ( '**/* ' , {
34
35
ignoreInitial : true ,
35
- cwd : absolutePathToDocumentsDirectory ,
36
+ cwd : projectRoot ,
37
+ ignored : [
38
+ '**/node_modules/**' ,
39
+ '**/.git/**' ,
40
+ '**/dist/**' ,
41
+ '**/build/**' ,
42
+ '**/.next/**' ,
43
+ '**/coverage/**' ,
44
+ ] ,
36
45
} ) ;
37
46
38
47
const exit = ( ) => {
@@ -96,25 +105,34 @@ export const setupHotreloading = async (
96
105
97
106
logger . debug ( `Detected ${ event } in ${ relativePathToChangeTarget } ` ) ;
98
107
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 ) ;
104
116
105
- changes . push ( {
106
- event,
107
- filename : relativePathToChangeTarget ,
108
- } ) ;
117
+ changes . push ( {
118
+ event,
119
+ filename : pathRelativeToDocuments ,
120
+ } ) ;
109
121
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
113
130
changes . push ( {
114
- event : 'change' as const ,
115
- filename : path . relative ( absolutePathToDocumentsDirectory , dependentPath ) ,
131
+ event,
132
+ filename : relativePathToChangeTarget ,
116
133
} ) ;
117
134
}
135
+
118
136
reload ( ) ;
119
137
} ) ;
120
138
0 commit comments