@@ -15,6 +15,7 @@ import type {WebSocket} from "ws";
15
15
import { WebSocketServer } from "ws" ;
16
16
import type { Config } from "./config.js" ;
17
17
import { readConfig } from "./config.js" ;
18
+ import type { LoaderResolver } from "./dataloader.js" ;
18
19
import { HttpError , isEnoent , isHttpError , isSystemError } from "./error.js" ;
19
20
import { getClientPath } from "./files.js" ;
20
21
import type { FileWatchers } from "./fileWatchers.js" ;
@@ -23,7 +24,7 @@ import {transpileJavaScript, transpileModule} from "./javascript/transpile.js";
23
24
import { parseMarkdown } from "./markdown.js" ;
24
25
import type { MarkdownCode , MarkdownPage } from "./markdown.js" ;
25
26
import { populateNpmCache } from "./npm.js" ;
26
- import { isPathImport } from "./path.js" ;
27
+ import { isPathImport , resolvePath } from "./path.js" ;
27
28
import { renderPage } from "./render.js" ;
28
29
import type { Resolvers } from "./resolvers.js" ;
29
30
import { getResolvers } from "./resolvers.js" ;
@@ -346,7 +347,7 @@ function handleWatch(socket: WebSocket, req: IncomingMessage, configPromise: Pro
346
347
type : "update" ,
347
348
html : diffHtml ( previousHtml , html ) ,
348
349
code : diffCode ( previousCode , code ) ,
349
- files : diffFiles ( previousFiles , files ) ,
350
+ files : diffFiles ( previousFiles , files , getLastModifiedResolver ( loaders , path ) ) ,
350
351
tables : diffTables ( previousTables , tables , previousFiles , files ) ,
351
352
stylesheets : diffStylesheets ( previousStylesheets , stylesheets ) ,
352
353
hash : { previous : previousHash , current : hash }
@@ -467,10 +468,14 @@ function diffCode(oldCode: Map<string, string>, newCode: Map<string, string>): C
467
468
return patch ;
468
469
}
469
470
470
- type FileDeclaration = { name : string ; mimeType ? : string ; path : string } ;
471
+ type FileDeclaration = { name : string ; mimeType : string ; lastModified : number ; path : string } ;
471
472
type FilePatch = { removed : string [ ] ; added : FileDeclaration [ ] } ;
472
473
473
- function diffFiles ( oldFiles : Map < string , string > , newFiles : Map < string , string > ) : FilePatch {
474
+ function diffFiles (
475
+ oldFiles : Map < string , string > ,
476
+ newFiles : Map < string , string > ,
477
+ getLastModified : ( name : string ) => number | undefined
478
+ ) : FilePatch {
474
479
const patch : FilePatch = { removed : [ ] , added : [ ] } ;
475
480
for ( const [ name , path ] of oldFiles ) {
476
481
if ( newFiles . get ( name ) !== path ) {
@@ -479,12 +484,21 @@ function diffFiles(oldFiles: Map<string, string>, newFiles: Map<string, string>)
479
484
}
480
485
for ( const [ name , path ] of newFiles ) {
481
486
if ( oldFiles . get ( name ) !== path ) {
482
- patch . added . push ( { name, mimeType : mime . getType ( name ) ?? undefined , path} ) ;
487
+ patch . added . push ( {
488
+ name,
489
+ mimeType : mime . getType ( name ) ?? "application/octet-stream" ,
490
+ lastModified : getLastModified ( name ) ?? NaN ,
491
+ path
492
+ } ) ;
483
493
}
484
494
}
485
495
return patch ;
486
496
}
487
497
498
+ function getLastModifiedResolver ( loaders : LoaderResolver , path : string ) : ( name : string ) => number | undefined {
499
+ return ( name ) => loaders . getSourceLastModified ( resolvePath ( path , name ) ) ;
500
+ }
501
+
488
502
type TableDeclaration = { name : string ; path : string } ;
489
503
type TablePatch = { removed : string [ ] ; added : TableDeclaration [ ] } ;
490
504
0 commit comments