1+ // diffMappings, printDiff, diffMemberArray from https://github.com/modmuss50/YarnDiff/tree/master
2+
3+ import {
4+ getFeatherBuildMaven ,
5+ getFeatherVersionMeta ,
6+ getMinecraftStableVersions ,
7+ getMinecraftVersions ,
8+ } from "./meta_maven_utils.js" ;
9+
10+ import * as tiny from "./tiny_mappings.js" ;
11+
12+ ( async ( ) => {
13+ const minecraftStableVersions = await getMinecraftStableVersions ( ) ;
14+ const minecraftAllVersions = await getMinecraftVersions ( ) ;
15+
16+ let possibleVersions ;
17+
18+ const versionSelectorInput = document . getElementById ( "mc-version" ) ;
19+ const versionListElement = document . getElementById ( "version-list" ) ;
20+ const allowSnapshotsCheck = document . getElementById ( "allow-snapshots" ) ;
21+
22+ const buildSourceElement = document . getElementById ( "build-source" ) ;
23+ const buildTargetElement = document . getElementById ( "build-target" ) ;
24+ const diffViewerElement = document . getElementById ( "diff-viewer" ) ;
25+
26+ const hidePackage = document . getElementById ( "hide-package" ) ;
27+
28+ async function updateFeatherBuilds ( ) {
29+ if (
30+ possibleVersions . some ( ( version ) => versionSelectorInput . value === version )
31+ ) {
32+ await getFeatherVersionMeta ( versionSelectorInput . value ) . then (
33+ ( featherVersionMeta ) => {
34+ buildSourceElement . innerHTML = "" ;
35+ buildTargetElement . innerHTML = "" ;
36+ for ( const featherVersion of featherVersionMeta ) {
37+ const featherVersionElement = document . createElement ( "option" ) ;
38+ featherVersionElement . innerText = "Build " + featherVersion . build ;
39+ featherVersionElement . value = featherVersion . version ;
40+ buildSourceElement . appendChild ( featherVersionElement ) ;
41+ buildTargetElement . appendChild (
42+ featherVersionElement . cloneNode ( true ) ,
43+ ) ;
44+ }
45+ } ,
46+ ) ;
47+
48+ // Hide the diff viewer bc the source and target builds are the same
49+ diffViewerElement . style . display = "none" ;
50+ }
51+ }
52+
53+ async function getTinyMappings ( version ) {
54+ let arrayBuf = await getFeatherBuildMaven ( version )
55+ . then ( ( response ) => response . blob ( ) ) // Get response as a Blob
56+ . then ( async ( blob ) => {
57+ const arrayBuffer = await blob . arrayBuffer ( ) ; // Convert Blob to ArrayBuffer
58+ // Convert to Uint8Array
59+ return new Uint8Array ( arrayBuffer ) ;
60+ } ) ;
61+
62+ const readableStream = new ReadableStream ( {
63+ start ( controller ) {
64+ controller . enqueue ( arrayBuf ) ;
65+ controller . close ( ) ;
66+ }
67+ } ) ;
68+ const ds = new DecompressionStream ( "gzip" ) ;
69+ const tds = new TextDecoderStream ( "utf-8" )
70+
71+ let file = '' ;
72+ const reader = readableStream . pipeThrough ( ds ) . pipeThrough ( tds ) . getReader ( ) ;
73+ while ( true ) {
74+ const { done, value } = await reader . read ( ) ;
75+ if ( done ) {
76+ break ;
77+ }
78+ file += value ;
79+ }
80+
81+ return tiny . parseTiny ( file ) ;
82+ }
83+
84+ async function updateFeatherDiff ( ) {
85+ const source = buildSourceElement . value ;
86+ const target = buildTargetElement . value ;
87+
88+ if ( source === target ) {
89+ console . log ( "Source and target builds are the same" ) ;
90+ // Hide the diff viewer
91+ diffViewerElement . style . display = "none" ;
92+ return ;
93+ }
94+ // Display the diff viewer
95+ diffViewerElement . style . display = "inline" ;
96+
97+ const sourceMappings = await getTinyMappings ( source ) ;
98+ const targetMappings = await getTinyMappings ( target ) ;
99+
100+ diffMappings ( sourceMappings , targetMappings ) ;
101+ }
102+
103+ function diffMappings ( source , target ) {
104+ printDiff ( diffMemberArray ( source . classes , target , hidePackage . checked ) , "classes-diff" )
105+ printDiff ( diffMemberArray ( source . methods , target ) , "methods-diff" )
106+ printDiff ( diffMemberArray ( source . fields , target ) , "fields-diff" )
107+ }
108+
109+ function printDiff ( diff , elementID ) {
110+ document . getElementById ( elementID ) . innerText = diff . map ( value => `${ value . source } -> ${ value . target } ` ) . join ( "\n" )
111+ }
112+
113+ function diffMemberArray ( source , targetMappings , stripPath = false ) {
114+ let diff = [ ]
115+
116+ source . forEach ( source => {
117+ let target = targetMappings . find ( source . calamus )
118+
119+ if ( target !== undefined && source . feather !== target . feather ) {
120+ let sourceFeather = source . feather ;
121+ let targetFeather = target . feather ;
122+
123+ if ( stripPath ) {
124+ if ( sourceFeather . substring ( 0 , sourceFeather . lastIndexOf ( '/' ) ) === targetFeather . substring ( 0 , targetFeather . lastIndexOf ( '/' ) ) ) {
125+ sourceFeather = sourceFeather . split ( '/' ) . pop ( ) ;
126+ targetFeather = targetFeather . split ( '/' ) . pop ( ) ;
127+ }
128+ }
129+
130+ diff . push ( {
131+ source : sourceFeather ,
132+ target : targetFeather
133+ } )
134+ }
135+ } )
136+ return diff
137+ }
138+
139+ versionSelectorInput . addEventListener (
140+ "input" ,
141+ async ( _ ) => await updateFeatherBuilds ( ) ,
142+ ) ;
143+
144+ allowSnapshotsCheck . addEventListener ( "change" , ( _ ) => {
145+ if ( allowSnapshotsCheck . checked ) {
146+ possibleVersions = minecraftAllVersions ;
147+ } else {
148+ possibleVersions = minecraftStableVersions ;
149+ }
150+ updateVersionList ( ) ;
151+ } ) ;
152+
153+ buildSourceElement . addEventListener (
154+ "change" ,
155+ async ( _ ) => await updateFeatherDiff ( ) ,
156+ ) ;
157+
158+ buildTargetElement . addEventListener (
159+ "change" ,
160+ async ( _ ) => await updateFeatherDiff ( ) ,
161+ ) ;
162+
163+ hidePackage . addEventListener ( "change" , async ( _ ) => {
164+ await updateFeatherDiff ( ) ;
165+ } ) ;
166+
167+ function updateVersionList ( ) {
168+ const list = possibleVersions ;
169+ while ( versionListElement . firstChild )
170+ versionListElement . removeChild ( versionListElement . lastChild ) ;
171+ list . forEach ( ( e ) => {
172+ const opt = new Option ( ) ;
173+ opt . value = e ;
174+ versionListElement . appendChild ( opt ) ;
175+ } ) ;
176+ }
177+
178+ possibleVersions = minecraftStableVersions ;
179+ updateVersionList ( ) ;
180+ await updateFeatherBuilds ( ) ;
181+ } ) ( ) ;
0 commit comments