1
+ import { createHash } from "node:crypto" ;
1
2
import { type WriteStream , createReadStream , existsSync , statSync } from "node:fs" ;
2
3
import { mkdir , open , readFile , rename , unlink } from "node:fs/promises" ;
3
4
import { dirname , extname , join , relative } from "node:path/posix" ;
@@ -7,7 +8,7 @@ import JSZip from "jszip";
7
8
import { extract } from "tar-stream" ;
8
9
import { maybeStat , prepareOutput } from "./files.js" ;
9
10
import { FileWatchers } from "./fileWatchers.js" ;
10
- import { getFileHash , getFileInfo } from "./javascript/module.js" ;
11
+ import { getFileInfo } from "./javascript/module.js" ;
11
12
import type { Logger , Writer } from "./logger.js" ;
12
13
import { cyan , faint , green , red , yellow } from "./tty.js" ;
13
14
@@ -155,8 +156,19 @@ export class LoaderResolver {
155
156
return path ;
156
157
}
157
158
159
+ /**
160
+ * Returns the hash of the file with the given name within the source root, or
161
+ * if the name refers to a file generated by a data loader, the hash of the
162
+ * corresponding data loader source and its modification time. The latter
163
+ * ensures that if the data loader is “touched” (even without changing its
164
+ * contents) that the data loader will be re-run.
165
+ */
158
166
getSourceFileHash ( name : string ) : string {
159
- return getFileHash ( this . root , this . getSourceFilePath ( name ) ) ;
167
+ const path = this . getSourceFilePath ( name ) ;
168
+ const info = getFileInfo ( this . root , path ) ;
169
+ if ( ! info ) return createHash ( "sha256" ) . digest ( "hex" ) ;
170
+ const { hash} = info ;
171
+ return path === name ? hash : createHash ( "sha256" ) . update ( hash ) . update ( String ( info . mtimeMs ) ) . digest ( "hex" ) ;
160
172
}
161
173
162
174
getSourceLastModified ( name : string ) : number | undefined {
0 commit comments