@@ -181,6 +181,14 @@ function formatUint8Array(values: number[], indent = " "): string {
181181 return lines . join ( "\n" ) ;
182182}
183183
184+ async function sha256Hex ( input : string ) : Promise < string > {
185+ let bytes = new TextEncoder ( ) . encode ( input ) ;
186+ let digest = await crypto . subtle . digest ( "SHA-256" , bytes ) ;
187+ return Array . from ( new Uint8Array ( digest ) )
188+ . map ( ( byte ) => byte . toString ( 16 ) . padStart ( 2 , "0" ) )
189+ . join ( "" ) ;
190+ }
191+
184192let [ derivedCategoryText , derivedCorePropsText , eastAsianWidthText ] =
185193 await Promise . all ( [
186194 fetchText ( "extracted/DerivedGeneralCategory.txt" ) ,
@@ -307,11 +315,24 @@ console.error(`special_large_ranges: ${largeRanges.length} entries`);
307315console . error ( `BMP dirty blocks: ${ dirtyBlocks } / 512` ) ;
308316console . error ( `Table data: ${ tableBytes } bytes` ) ;
309317
310- let date = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) ;
318+ // Fingerprint the generated tables (not the source text or comments) so the
319+ // header changes only when the emitted data would actually differ. Re-running
320+ // against identical Unicode data is byte-for-byte reproducible.
321+ let dataHash = ( await sha256Hex (
322+ JSON . stringify ( {
323+ unicode : UNICODE_BASE ,
324+ bmpFilter : Array . from ( bmpFilter ) ,
325+ smallPacked,
326+ largeStarts,
327+ largeCounts,
328+ largeWidths,
329+ } ) ,
330+ ) ) . slice ( 0 , 16 ) ;
311331
312332let output = `\
313333/* wcwidth.c - Unicode character width lookup
314- * Unicode 16.0 - generated by tasks/gen-wcwidth.ts on ${ date }
334+ * Unicode 16.0 - generated by tasks/gen-wcwidth.ts
335+ * Data hash: ${ dataHash }
315336 *
316337 * Only zero-width (combining marks + default ignorable) and double-width
317338 * (wide/fullwidth) codepoints are stored. Everything else defaults to
@@ -423,3 +444,5 @@ if (Deno.args.includes("--check")) {
423444 await Deno . writeTextFile ( "src/wcwidth.c" , output ) ;
424445 console . error ( "Wrote src/wcwidth.c" ) ;
425446}
447+
448+ export { } ;
0 commit comments