1010const os = require ( "os" ) ;
1111const path = require ( "path" ) ;
1212const zlib = require ( "zlib" ) ;
13- const crypto = require ( "crypto" ) ;
1413const { promisify } = require ( "util" ) ;
1514const { readFile, writeFile, mkdir } = require ( "fs/promises" ) ;
1615// Lazily instantiated when needed
@@ -20,14 +19,6 @@ const transform = require("./transform");
2019const serialize = require ( "./serialize" ) ;
2120let defaultCacheDirectory = null ;
2221
23- let hashType = "sha256" ;
24- // use md5 hashing if sha256 is not available
25- try {
26- crypto . createHash ( hashType ) ;
27- } catch {
28- hashType = "md5" ;
29- }
30-
3122const gunzip = promisify ( zlib . gunzip ) ;
3223const gzip = promisify ( zlib . gzip ) ;
3324
@@ -68,9 +59,7 @@ const write = async function (filename, compress, result) {
6859 *
6960 * @return {String }
7061 */
71- const filename = function ( source , identifier , options ) {
72- const hash = crypto . createHash ( hashType ) ;
73-
62+ const filename = function ( source , identifier , options , hash ) {
7463 hash . update ( serialize ( [ options , source , identifier ] ) ) ;
7564
7665 return hash . digest ( "hex" ) + ".json" ;
@@ -89,9 +78,13 @@ const handleCache = async function (directory, params) {
8978 cacheIdentifier,
9079 cacheDirectory,
9180 cacheCompression,
81+ hash,
9282 } = params ;
9383
94- const file = path . join ( directory , filename ( source , cacheIdentifier , options ) ) ;
84+ const file = path . join (
85+ directory ,
86+ filename ( source , cacheIdentifier , options , hash ) ,
87+ ) ;
9588
9689 try {
9790 // No errors mean that the file was previously cached
0 commit comments