1
- import { existsSync , promises as fs } from " node:fs" ;
2
- import path from " node:path" ;
1
+ import { existsSync , promises as fs } from ' node:fs' ;
2
+ import path from ' node:path' ;
3
3
import {
4
4
createDependencyGraph ,
5
5
type DependencyGraph ,
6
- } from " ./create-dependency-graph.js" ;
6
+ } from ' ./create-dependency-graph.js' ;
7
7
8
8
const pathToFileForTestingDependencyGraph = path . join (
9
9
__dirname ,
10
- " .for-dependency-graph.ts" ,
10
+ ' .for-dependency-graph.ts' ,
11
11
) ;
12
12
13
- vi . mock ( " @babel/traverse" , async ( ) => {
14
- const traverse = await vi . importActual ( " @babel/traverse" ) ;
13
+ vi . mock ( ' @babel/traverse' , async ( ) => {
14
+ const traverse = await vi . importActual ( ' @babel/traverse' ) ;
15
15
return { default : traverse } ;
16
16
} ) ;
17
17
18
- test ( " createDependencyGraph()" , async ( ) => {
18
+ test ( ' createDependencyGraph()' , async ( ) => {
19
19
if ( existsSync ( pathToFileForTestingDependencyGraph ) ) {
20
20
await fs . rm ( pathToFileForTestingDependencyGraph ) ;
21
21
}
@@ -44,163 +44,161 @@ test("createDependencyGraph()", async () => {
44
44
} ;
45
45
46
46
const initialDependencyGraph = convertPathsToAbsolute ( {
47
- " ../../../../package.json" : {
47
+ ' ../../../../package.json' : {
48
48
dependencyPaths : [ ] ,
49
- dependentPaths : [ " ../../packageJson.ts" ] ,
49
+ dependentPaths : [ ' ../../packageJson.ts' ] ,
50
50
moduleDependencies : [ ] ,
51
- path : " ../../../../package.json" ,
51
+ path : ' ../../../../package.json' ,
52
52
} ,
53
- " create-dependency-graph.ts" : {
54
- path : " create-dependency-graph.ts" ,
53
+ ' create-dependency-graph.ts' : {
54
+ path : ' create-dependency-graph.ts' ,
55
55
dependencyPaths : [
56
- " ../start-dev-server.ts" ,
57
- " get-imported-modules.ts" ,
58
- " resolve-path-aliases.ts" ,
56
+ ' ../start-dev-server.ts' ,
57
+ ' get-imported-modules.ts' ,
58
+ ' resolve-path-aliases.ts' ,
59
59
] ,
60
60
dependentPaths : [
61
- " create-dependency-graph.spec.ts" ,
62
- " setup-hot-reloading.ts" ,
61
+ ' create-dependency-graph.spec.ts' ,
62
+ ' setup-hot-reloading.ts' ,
63
63
] ,
64
- moduleDependencies : [ " node:fs" , " node:path" , " chokidar/handler.js" ] ,
64
+ moduleDependencies : [ ' node:fs' , ' node:path' , ' chokidar/handler.js' ] ,
65
65
} ,
66
- "../../get-preview-server-location.ts" : {
67
- dependencyPaths : [
68
- "../../packageJson.ts" ,
69
- ] ,
70
- dependentPaths : [ "../../preview/start-dev-server.ts" ] ,
71
- moduleDependencies : [ "node:path" , "node:url" , "jiti" , "nypm" , "prompts" ] ,
72
- path : "../../get-preview-server-location.ts" ,
66
+ '../../get-preview-server-location.ts' : {
67
+ dependencyPaths : [ '../../packageJson.ts' ] ,
68
+ dependentPaths : [ '../../preview/start-dev-server.ts' ] ,
69
+ moduleDependencies : [ 'node:path' , 'node:url' , 'jiti' , 'nypm' , 'prompts' ] ,
70
+ path : '../../get-preview-server-location.ts' ,
73
71
} ,
74
- " ../../packageJson.ts" : {
75
- dependencyPaths : [ " ../../../../package.json" ] ,
72
+ ' ../../packageJson.ts' : {
73
+ dependencyPaths : [ ' ../../../../package.json' ] ,
76
74
dependentPaths : [
77
- " ../../get-preview-server-location.ts" ,
78
- " ../../preview/start-dev-server.ts" ,
75
+ ' ../../get-preview-server-location.ts' ,
76
+ ' ../../preview/start-dev-server.ts' ,
79
77
] ,
80
78
moduleDependencies : [ ] ,
81
- path : " ../../packageJson.ts" ,
79
+ path : ' ../../packageJson.ts' ,
82
80
} ,
83
- " create-dependency-graph.spec.ts" : {
84
- path : " create-dependency-graph.spec.ts" ,
85
- dependencyPaths : [ " create-dependency-graph.ts" ] ,
81
+ ' create-dependency-graph.spec.ts' : {
82
+ path : ' create-dependency-graph.spec.ts' ,
83
+ dependencyPaths : [ ' create-dependency-graph.ts' ] ,
86
84
dependentPaths : [ ] ,
87
- moduleDependencies : [ " node:fs" , " node:path" ] ,
85
+ moduleDependencies : [ ' node:fs' , ' node:path' ] ,
88
86
} ,
89
- " ../get-env-variables-for-preview-app.ts" : {
90
- dependencyPaths : [ " ../../preview/start-dev-server.ts" ] ,
91
- dependentPaths : [ " ../../preview/start-dev-server.ts" ] ,
92
- moduleDependencies : [ " node:path" ] ,
93
- path : " ../../preview/get-env-variables-for-preview-app.ts" ,
87
+ ' ../get-env-variables-for-preview-app.ts' : {
88
+ dependencyPaths : [ ' ../../preview/start-dev-server.ts' ] ,
89
+ dependentPaths : [ ' ../../preview/start-dev-server.ts' ] ,
90
+ moduleDependencies : [ ' node:path' ] ,
91
+ path : ' ../../preview/get-env-variables-for-preview-app.ts' ,
94
92
} ,
95
- " ./test/some-file.ts" : {
93
+ ' ./test/some-file.ts' : {
96
94
dependencyPaths : [ ] ,
97
95
dependentPaths : [ ] ,
98
96
moduleDependencies : [ ] ,
99
- path : " /home/gabriel/Projects/Resend/react-email/packages/react-email/src/cli/utils/preview/hot-reloading/test/some-file.ts" ,
97
+ path : ' /home/gabriel/Projects/Resend/react-email/packages/react-email/src/cli/utils/preview/hot-reloading/test/some-file.ts' ,
100
98
} ,
101
- " resolve-path-aliases.ts" : {
102
- path : " resolve-path-aliases.ts" ,
99
+ ' resolve-path-aliases.ts' : {
100
+ path : ' resolve-path-aliases.ts' ,
103
101
dependentPaths : [
104
- " create-dependency-graph.ts" ,
105
- " resolve-path-aliases.spec.ts" ,
102
+ ' create-dependency-graph.ts' ,
103
+ ' resolve-path-aliases.spec.ts' ,
106
104
] ,
107
105
dependencyPaths : [ ] ,
108
- moduleDependencies : [ " node:path" , " tsconfig-paths" ] ,
106
+ moduleDependencies : [ ' node:path' , ' tsconfig-paths' ] ,
109
107
} ,
110
- " resolve-path-aliases.spec.ts" : {
111
- path : " resolve-path-aliases.spec.ts" ,
112
- dependencyPaths : [ " resolve-path-aliases.ts" ] ,
108
+ ' resolve-path-aliases.spec.ts' : {
109
+ path : ' resolve-path-aliases.spec.ts' ,
110
+ dependencyPaths : [ ' resolve-path-aliases.ts' ] ,
113
111
dependentPaths : [ ] ,
114
- moduleDependencies : [ " node:path" ] ,
112
+ moduleDependencies : [ ' node:path' ] ,
115
113
} ,
116
- " get-imported-modules.ts" : {
117
- path : " get-imported-modules" ,
114
+ ' get-imported-modules.ts' : {
115
+ path : ' get-imported-modules' ,
118
116
dependentPaths : [
119
- " create-dependency-graph.ts" ,
120
- " get-imported-modules.spec.ts" ,
117
+ ' create-dependency-graph.ts' ,
118
+ ' get-imported-modules.spec.ts' ,
121
119
] ,
122
120
dependencyPaths : [ ] ,
123
- moduleDependencies : [ " @babel/parser" , " @babel/traverse" ] ,
121
+ moduleDependencies : [ ' @babel/parser' , ' @babel/traverse' ] ,
124
122
} ,
125
- " get-imported-modules.spec.ts" : {
126
- path : " get-imported-modules.spec.ts" ,
127
- dependencyPaths : [ " get-imported-modules.ts" ] ,
123
+ ' get-imported-modules.spec.ts' : {
124
+ path : ' get-imported-modules.spec.ts' ,
125
+ dependencyPaths : [ ' get-imported-modules.ts' ] ,
128
126
dependentPaths : [ ] ,
129
- moduleDependencies : [ " node:fs" ] ,
127
+ moduleDependencies : [ ' node:fs' ] ,
130
128
} ,
131
- " setup-hot-reloading.ts" : {
132
- path : " setup-hot-reloading.ts" ,
129
+ ' setup-hot-reloading.ts' : {
130
+ path : ' setup-hot-reloading.ts' ,
133
131
dependencyPaths : [
134
- " ../../types/hot-reload-change.ts" ,
135
- " create-dependency-graph.ts" ,
132
+ ' ../../types/hot-reload-change.ts' ,
133
+ ' create-dependency-graph.ts' ,
136
134
] ,
137
135
dependentPaths : [ ] ,
138
136
moduleDependencies : [
139
- " node:http" ,
140
- " node:path" ,
141
- " chokidar" ,
142
- " debounce" ,
143
- " socket.io" ,
137
+ ' node:http' ,
138
+ ' node:path' ,
139
+ ' chokidar' ,
140
+ ' debounce' ,
141
+ ' socket.io' ,
144
142
] ,
145
143
} ,
146
- " ../start-dev-server.ts" : {
144
+ ' ../start-dev-server.ts' : {
147
145
dependencyPaths : [
148
- " ../../register-spinner-autostopping.ts" ,
149
- " ../../get-preview-server-location.ts" ,
150
- " ../../packageJson.ts" ,
151
- " ../../preview/get-env-variables-for-preview-app.ts" ,
152
- " ../../preview/serve-static-file.ts" ,
146
+ ' ../../register-spinner-autostopping.ts' ,
147
+ ' ../../get-preview-server-location.ts' ,
148
+ ' ../../packageJson.ts' ,
149
+ ' ../../preview/get-env-variables-for-preview-app.ts' ,
150
+ ' ../../preview/serve-static-file.ts' ,
153
151
] ,
154
- path : " ../start-dev-server.ts" ,
152
+ path : ' ../start-dev-server.ts' ,
155
153
dependentPaths : [
156
- " ../../preview/get-env-variables-for-preview-app.ts" ,
157
- " create-dependency-graph.ts" ,
154
+ ' ../../preview/get-env-variables-for-preview-app.ts' ,
155
+ ' create-dependency-graph.ts' ,
158
156
] ,
159
157
moduleDependencies : [
160
- " node:http" ,
161
- " node:path" ,
162
- " node:url" ,
163
- " chalk" ,
164
- " jiti" ,
165
- " log-symbols" ,
166
- " ora" ,
158
+ ' node:http' ,
159
+ ' node:path' ,
160
+ ' node:url' ,
161
+ ' chalk' ,
162
+ ' jiti' ,
163
+ ' log-symbols' ,
164
+ ' ora' ,
167
165
] ,
168
166
} ,
169
- " ../../preview/serve-static-file.ts" : {
167
+ ' ../../preview/serve-static-file.ts' : {
170
168
dependencyPaths : [ ] ,
171
- dependentPaths : [ " ../../preview/start-dev-server.ts" ] ,
169
+ dependentPaths : [ ' ../../preview/start-dev-server.ts' ] ,
172
170
moduleDependencies : [
173
- " node:fs" ,
174
- " node:http" ,
175
- " node:path" ,
176
- " node:url" ,
177
- " mime-types" ,
171
+ ' node:fs' ,
172
+ ' node:http' ,
173
+ ' node:path' ,
174
+ ' node:url' ,
175
+ ' mime-types' ,
178
176
] ,
179
- path : " ../../preview/serve-static-file.ts" ,
177
+ path : ' ../../preview/serve-static-file.ts' ,
180
178
} ,
181
- " ../../register-spinner-autostopping.ts" : {
179
+ ' ../../register-spinner-autostopping.ts' : {
182
180
dependencyPaths : [ ] ,
183
- dependentPaths : [ " ../../preview/start-dev-server.ts" ] ,
184
- moduleDependencies : [ " log-symbols" , " ora" ] ,
185
- path : " ../../register-spinner-autostopping.ts" ,
181
+ dependentPaths : [ ' ../../preview/start-dev-server.ts' ] ,
182
+ moduleDependencies : [ ' log-symbols' , ' ora' ] ,
183
+ path : ' ../../register-spinner-autostopping.ts' ,
186
184
} ,
187
- " ../../types/hot-reload-event.ts" : {
185
+ ' ../../types/hot-reload-event.ts' : {
188
186
dependencyPaths : [ ] ,
189
- dependentPaths : [ " ../../types/hot-reload-change.ts" ] ,
190
- moduleDependencies : [ " chokidar/handler.js" ] ,
191
- path : " ../../types/hot-reload-event.ts" ,
187
+ dependentPaths : [ ' ../../types/hot-reload-change.ts' ] ,
188
+ moduleDependencies : [ ' chokidar/handler.js' ] ,
189
+ path : ' ../../types/hot-reload-event.ts' ,
192
190
} ,
193
- " ../../types/hot-reload-change.ts" : {
194
- path : " ../../types/hot-reload-change.ts" ,
195
- dependencyPaths : [ " ../../types/hot-reload-event.ts" ] ,
196
- dependentPaths : [ " setup-hot-reloading.ts" ] ,
191
+ ' ../../types/hot-reload-change.ts' : {
192
+ path : ' ../../types/hot-reload-change.ts' ,
193
+ dependencyPaths : [ ' ../../types/hot-reload-event.ts' ] ,
194
+ dependentPaths : [ ' setup-hot-reloading.ts' ] ,
197
195
moduleDependencies : [ ] ,
198
196
} ,
199
197
} satisfies DependencyGraph ) ;
200
198
201
199
expect (
202
200
dependencyGraph ,
203
- " the initial value for the dependency graph should work with the directory of this testing file" ,
201
+ ' the initial value for the dependency graph should work with the directory of this testing file' ,
204
202
) . toEqual ( initialDependencyGraph ) ;
205
203
206
204
await fs . writeFile (
@@ -210,30 +208,30 @@ import {} from './setup-hot-reloading';
210
208
import {} from './get-imported-modules';
211
209
import {} from './create-dependency-graph.ts';
212
210
` ,
213
- " utf8" ,
211
+ ' utf8' ,
214
212
) ;
215
- await updateDependencyGraph ( " add" , pathToFileForTestingDependencyGraph ) ;
213
+ await updateDependencyGraph ( ' add' , pathToFileForTestingDependencyGraph ) ;
216
214
expect (
217
215
dependencyGraph [ pathToFileForTestingDependencyGraph ] ,
218
- " added file to have proper dependency paths" ,
216
+ ' added file to have proper dependency paths' ,
219
217
) . toEqual ( {
220
218
path : pathToFileForTestingDependencyGraph ,
221
219
dependentPaths : [ ] ,
222
220
dependencyPaths : [
223
- toAbsolute ( " setup-hot-reloading.ts" ) ,
224
- toAbsolute ( " get-imported-modules.ts" ) ,
225
- toAbsolute ( " create-dependency-graph.ts" ) ,
221
+ toAbsolute ( ' setup-hot-reloading.ts' ) ,
222
+ toAbsolute ( ' get-imported-modules.ts' ) ,
223
+ toAbsolute ( ' create-dependency-graph.ts' ) ,
226
224
] ,
227
225
moduleDependencies : [ ] ,
228
226
} satisfies DependencyGraph [ number ] ) ;
229
227
expect (
230
- dependencyGraph [ toAbsolute ( " setup-hot-reloading.ts" ) ] ?. dependentPaths ,
228
+ dependencyGraph [ toAbsolute ( ' setup-hot-reloading.ts' ) ] ?. dependentPaths ,
231
229
) . toContain ( pathToFileForTestingDependencyGraph ) ;
232
230
expect (
233
- dependencyGraph [ toAbsolute ( " get-imported-modules.ts" ) ] ?. dependentPaths ,
231
+ dependencyGraph [ toAbsolute ( ' get-imported-modules.ts' ) ] ?. dependentPaths ,
234
232
) . toContain ( pathToFileForTestingDependencyGraph ) ;
235
233
expect (
236
- dependencyGraph [ toAbsolute ( " create-dependency-graph.ts" ) ] ?. dependentPaths ,
234
+ dependencyGraph [ toAbsolute ( ' create-dependency-graph.ts' ) ] ?. dependentPaths ,
237
235
) . toContain ( pathToFileForTestingDependencyGraph ) ;
238
236
239
237
await fs . writeFile (
@@ -242,45 +240,45 @@ import {} from './create-dependency-graph.ts';
242
240
import {} from './setup-hot-reloading';
243
241
import {} from './create-dependency-graph.ts';
244
242
` ,
245
- " utf8" ,
243
+ ' utf8' ,
246
244
) ;
247
- await updateDependencyGraph ( " change" , pathToFileForTestingDependencyGraph ) ;
245
+ await updateDependencyGraph ( ' change' , pathToFileForTestingDependencyGraph ) ;
248
246
expect (
249
247
dependencyGraph [ pathToFileForTestingDependencyGraph ] ,
250
- " changed file to have updated dependencyPaths" ,
248
+ ' changed file to have updated dependencyPaths' ,
251
249
) . toEqual ( {
252
250
path : pathToFileForTestingDependencyGraph ,
253
251
dependentPaths : [ ] ,
254
252
dependencyPaths : [
255
- toAbsolute ( " setup-hot-reloading.ts" ) ,
256
- toAbsolute ( " create-dependency-graph.ts" ) ,
253
+ toAbsolute ( ' setup-hot-reloading.ts' ) ,
254
+ toAbsolute ( ' create-dependency-graph.ts' ) ,
257
255
] ,
258
256
moduleDependencies : [ ] ,
259
257
} satisfies DependencyGraph [ number ] ) ;
260
258
expect (
261
- dependencyGraph [ toAbsolute ( " setup-hot-reloading.ts" ) ] ?. dependentPaths ,
259
+ dependencyGraph [ toAbsolute ( ' setup-hot-reloading.ts' ) ] ?. dependentPaths ,
262
260
) . toContain ( pathToFileForTestingDependencyGraph ) ;
263
261
expect (
264
- dependencyGraph [ toAbsolute ( " get-imported-modules.ts" ) ] ?. dependentPaths ,
265
- " when removing dependency on a file, the dependency should have its dependents updated to not have the testing file again" ,
262
+ dependencyGraph [ toAbsolute ( ' get-imported-modules.ts' ) ] ?. dependentPaths ,
263
+ ' when removing dependency on a file, the dependency should have its dependents updated to not have the testing file again' ,
266
264
) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
267
265
expect (
268
- dependencyGraph [ toAbsolute ( " create-dependency-graph.ts" ) ] ?. dependentPaths ,
266
+ dependencyGraph [ toAbsolute ( ' create-dependency-graph.ts' ) ] ?. dependentPaths ,
269
267
) . toContain ( pathToFileForTestingDependencyGraph ) ;
270
268
271
269
await fs . rm ( pathToFileForTestingDependencyGraph ) ;
272
- await updateDependencyGraph ( " unlink" , pathToFileForTestingDependencyGraph ) ;
270
+ await updateDependencyGraph ( ' unlink' , pathToFileForTestingDependencyGraph ) ;
273
271
expect ( dependencyGraph [ pathToFileForTestingDependencyGraph ] ) . toBeUndefined ( ) ;
274
272
expect (
275
- dependencyGraph [ toAbsolute ( " setup-hot-reloading.ts" ) ] ?. dependentPaths ,
273
+ dependencyGraph [ toAbsolute ( ' setup-hot-reloading.ts' ) ] ?. dependentPaths ,
276
274
"should remove itself from dependents once it's unlinked" ,
277
275
) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
278
276
expect (
279
- dependencyGraph [ toAbsolute ( " get-imported-modules.ts" ) ] ?. dependentPaths ,
277
+ dependencyGraph [ toAbsolute ( ' get-imported-modules.ts' ) ] ?. dependentPaths ,
280
278
"should remove itself from dependents once it's unlinked" ,
281
279
) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
282
280
expect (
283
- dependencyGraph [ toAbsolute ( " create-dependency-graph.ts" ) ] ?. dependentPaths ,
281
+ dependencyGraph [ toAbsolute ( ' create-dependency-graph.ts' ) ] ?. dependentPaths ,
284
282
"should remove itself from dependents once it's unlinked" ,
285
283
) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
286
284
} ) ;
0 commit comments