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' ;
33import {
44 createDependencyGraph ,
55 type DependencyGraph ,
6- } from " ./create-dependency-graph.js" ;
6+ } from ' ./create-dependency-graph.js' ;
77
88const pathToFileForTestingDependencyGraph = path . join (
99 __dirname ,
10- " .for-dependency-graph.ts" ,
10+ ' .for-dependency-graph.ts' ,
1111) ;
1212
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' ) ;
1515 return { default : traverse } ;
1616} ) ;
1717
18- test ( " createDependencyGraph()" , async ( ) => {
18+ test ( ' createDependencyGraph()' , async ( ) => {
1919 if ( existsSync ( pathToFileForTestingDependencyGraph ) ) {
2020 await fs . rm ( pathToFileForTestingDependencyGraph ) ;
2121 }
@@ -44,163 +44,161 @@ test("createDependencyGraph()", async () => {
4444 } ;
4545
4646 const initialDependencyGraph = convertPathsToAbsolute ( {
47- " ../../../../package.json" : {
47+ ' ../../../../package.json' : {
4848 dependencyPaths : [ ] ,
49- dependentPaths : [ " ../../packageJson.ts" ] ,
49+ dependentPaths : [ ' ../../packageJson.ts' ] ,
5050 moduleDependencies : [ ] ,
51- path : " ../../../../package.json" ,
51+ path : ' ../../../../package.json' ,
5252 } ,
53- " create-dependency-graph.ts" : {
54- path : " create-dependency-graph.ts" ,
53+ ' create-dependency-graph.ts' : {
54+ path : ' create-dependency-graph.ts' ,
5555 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' ,
5959 ] ,
6060 dependentPaths : [
61- " create-dependency-graph.spec.ts" ,
62- " setup-hot-reloading.ts" ,
61+ ' create-dependency-graph.spec.ts' ,
62+ ' setup-hot-reloading.ts' ,
6363 ] ,
64- moduleDependencies : [ " node:fs" , " node:path" , " chokidar/handler.js" ] ,
64+ moduleDependencies : [ ' node:fs' , ' node:path' , ' chokidar/handler.js' ] ,
6565 } ,
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' ,
7371 } ,
74- " ../../packageJson.ts" : {
75- dependencyPaths : [ " ../../../../package.json" ] ,
72+ ' ../../packageJson.ts' : {
73+ dependencyPaths : [ ' ../../../../package.json' ] ,
7674 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' ,
7977 ] ,
8078 moduleDependencies : [ ] ,
81- path : " ../../packageJson.ts" ,
79+ path : ' ../../packageJson.ts' ,
8280 } ,
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' ] ,
8684 dependentPaths : [ ] ,
87- moduleDependencies : [ " node:fs" , " node:path" ] ,
85+ moduleDependencies : [ ' node:fs' , ' node:path' ] ,
8886 } ,
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' ,
9492 } ,
95- " ./test/some-file.ts" : {
93+ ' ./test/some-file.ts' : {
9694 dependencyPaths : [ ] ,
9795 dependentPaths : [ ] ,
9896 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' ,
10098 } ,
101- " resolve-path-aliases.ts" : {
102- path : " resolve-path-aliases.ts" ,
99+ ' resolve-path-aliases.ts' : {
100+ path : ' resolve-path-aliases.ts' ,
103101 dependentPaths : [
104- " create-dependency-graph.ts" ,
105- " resolve-path-aliases.spec.ts" ,
102+ ' create-dependency-graph.ts' ,
103+ ' resolve-path-aliases.spec.ts' ,
106104 ] ,
107105 dependencyPaths : [ ] ,
108- moduleDependencies : [ " node:path" , " tsconfig-paths" ] ,
106+ moduleDependencies : [ ' node:path' , ' tsconfig-paths' ] ,
109107 } ,
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' ] ,
113111 dependentPaths : [ ] ,
114- moduleDependencies : [ " node:path" ] ,
112+ moduleDependencies : [ ' node:path' ] ,
115113 } ,
116- " get-imported-modules.ts" : {
117- path : " get-imported-modules" ,
114+ ' get-imported-modules.ts' : {
115+ path : ' get-imported-modules' ,
118116 dependentPaths : [
119- " create-dependency-graph.ts" ,
120- " get-imported-modules.spec.ts" ,
117+ ' create-dependency-graph.ts' ,
118+ ' get-imported-modules.spec.ts' ,
121119 ] ,
122120 dependencyPaths : [ ] ,
123- moduleDependencies : [ " @babel/parser" , " @babel/traverse" ] ,
121+ moduleDependencies : [ ' @babel/parser' , ' @babel/traverse' ] ,
124122 } ,
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' ] ,
128126 dependentPaths : [ ] ,
129- moduleDependencies : [ " node:fs" ] ,
127+ moduleDependencies : [ ' node:fs' ] ,
130128 } ,
131- " setup-hot-reloading.ts" : {
132- path : " setup-hot-reloading.ts" ,
129+ ' setup-hot-reloading.ts' : {
130+ path : ' setup-hot-reloading.ts' ,
133131 dependencyPaths : [
134- " ../../types/hot-reload-change.ts" ,
135- " create-dependency-graph.ts" ,
132+ ' ../../types/hot-reload-change.ts' ,
133+ ' create-dependency-graph.ts' ,
136134 ] ,
137135 dependentPaths : [ ] ,
138136 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' ,
144142 ] ,
145143 } ,
146- " ../start-dev-server.ts" : {
144+ ' ../start-dev-server.ts' : {
147145 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' ,
153151 ] ,
154- path : " ../start-dev-server.ts" ,
152+ path : ' ../start-dev-server.ts' ,
155153 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' ,
158156 ] ,
159157 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' ,
167165 ] ,
168166 } ,
169- " ../../preview/serve-static-file.ts" : {
167+ ' ../../preview/serve-static-file.ts' : {
170168 dependencyPaths : [ ] ,
171- dependentPaths : [ " ../../preview/start-dev-server.ts" ] ,
169+ dependentPaths : [ ' ../../preview/start-dev-server.ts' ] ,
172170 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' ,
178176 ] ,
179- path : " ../../preview/serve-static-file.ts" ,
177+ path : ' ../../preview/serve-static-file.ts' ,
180178 } ,
181- " ../../register-spinner-autostopping.ts" : {
179+ ' ../../register-spinner-autostopping.ts' : {
182180 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' ,
186184 } ,
187- " ../../types/hot-reload-event.ts" : {
185+ ' ../../types/hot-reload-event.ts' : {
188186 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' ,
192190 } ,
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' ] ,
197195 moduleDependencies : [ ] ,
198196 } ,
199197 } satisfies DependencyGraph ) ;
200198
201199 expect (
202200 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' ,
204202 ) . toEqual ( initialDependencyGraph ) ;
205203
206204 await fs . writeFile (
@@ -210,30 +208,30 @@ import {} from './setup-hot-reloading';
210208import {} from './get-imported-modules';
211209import {} from './create-dependency-graph.ts';
212210` ,
213- " utf8" ,
211+ ' utf8' ,
214212 ) ;
215- await updateDependencyGraph ( " add" , pathToFileForTestingDependencyGraph ) ;
213+ await updateDependencyGraph ( ' add' , pathToFileForTestingDependencyGraph ) ;
216214 expect (
217215 dependencyGraph [ pathToFileForTestingDependencyGraph ] ,
218- " added file to have proper dependency paths" ,
216+ ' added file to have proper dependency paths' ,
219217 ) . toEqual ( {
220218 path : pathToFileForTestingDependencyGraph ,
221219 dependentPaths : [ ] ,
222220 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' ) ,
226224 ] ,
227225 moduleDependencies : [ ] ,
228226 } satisfies DependencyGraph [ number ] ) ;
229227 expect (
230- dependencyGraph [ toAbsolute ( " setup-hot-reloading.ts" ) ] ?. dependentPaths ,
228+ dependencyGraph [ toAbsolute ( ' setup-hot-reloading.ts' ) ] ?. dependentPaths ,
231229 ) . toContain ( pathToFileForTestingDependencyGraph ) ;
232230 expect (
233- dependencyGraph [ toAbsolute ( " get-imported-modules.ts" ) ] ?. dependentPaths ,
231+ dependencyGraph [ toAbsolute ( ' get-imported-modules.ts' ) ] ?. dependentPaths ,
234232 ) . toContain ( pathToFileForTestingDependencyGraph ) ;
235233 expect (
236- dependencyGraph [ toAbsolute ( " create-dependency-graph.ts" ) ] ?. dependentPaths ,
234+ dependencyGraph [ toAbsolute ( ' create-dependency-graph.ts' ) ] ?. dependentPaths ,
237235 ) . toContain ( pathToFileForTestingDependencyGraph ) ;
238236
239237 await fs . writeFile (
@@ -242,45 +240,45 @@ import {} from './create-dependency-graph.ts';
242240import {} from './setup-hot-reloading';
243241import {} from './create-dependency-graph.ts';
244242` ,
245- " utf8" ,
243+ ' utf8' ,
246244 ) ;
247- await updateDependencyGraph ( " change" , pathToFileForTestingDependencyGraph ) ;
245+ await updateDependencyGraph ( ' change' , pathToFileForTestingDependencyGraph ) ;
248246 expect (
249247 dependencyGraph [ pathToFileForTestingDependencyGraph ] ,
250- " changed file to have updated dependencyPaths" ,
248+ ' changed file to have updated dependencyPaths' ,
251249 ) . toEqual ( {
252250 path : pathToFileForTestingDependencyGraph ,
253251 dependentPaths : [ ] ,
254252 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' ) ,
257255 ] ,
258256 moduleDependencies : [ ] ,
259257 } satisfies DependencyGraph [ number ] ) ;
260258 expect (
261- dependencyGraph [ toAbsolute ( " setup-hot-reloading.ts" ) ] ?. dependentPaths ,
259+ dependencyGraph [ toAbsolute ( ' setup-hot-reloading.ts' ) ] ?. dependentPaths ,
262260 ) . toContain ( pathToFileForTestingDependencyGraph ) ;
263261 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' ,
266264 ) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
267265 expect (
268- dependencyGraph [ toAbsolute ( " create-dependency-graph.ts" ) ] ?. dependentPaths ,
266+ dependencyGraph [ toAbsolute ( ' create-dependency-graph.ts' ) ] ?. dependentPaths ,
269267 ) . toContain ( pathToFileForTestingDependencyGraph ) ;
270268
271269 await fs . rm ( pathToFileForTestingDependencyGraph ) ;
272- await updateDependencyGraph ( " unlink" , pathToFileForTestingDependencyGraph ) ;
270+ await updateDependencyGraph ( ' unlink' , pathToFileForTestingDependencyGraph ) ;
273271 expect ( dependencyGraph [ pathToFileForTestingDependencyGraph ] ) . toBeUndefined ( ) ;
274272 expect (
275- dependencyGraph [ toAbsolute ( " setup-hot-reloading.ts" ) ] ?. dependentPaths ,
273+ dependencyGraph [ toAbsolute ( ' setup-hot-reloading.ts' ) ] ?. dependentPaths ,
276274 "should remove itself from dependents once it's unlinked" ,
277275 ) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
278276 expect (
279- dependencyGraph [ toAbsolute ( " get-imported-modules.ts" ) ] ?. dependentPaths ,
277+ dependencyGraph [ toAbsolute ( ' get-imported-modules.ts' ) ] ?. dependentPaths ,
280278 "should remove itself from dependents once it's unlinked" ,
281279 ) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
282280 expect (
283- dependencyGraph [ toAbsolute ( " create-dependency-graph.ts" ) ] ?. dependentPaths ,
281+ dependencyGraph [ toAbsolute ( ' create-dependency-graph.ts' ) ] ?. dependentPaths ,
284282 "should remove itself from dependents once it's unlinked" ,
285283 ) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
286284} ) ;
0 commit comments