Normalize generated central pack licence line endings

This commit is contained in:
unimatrixgit 2026-11-28 14:55:50 +01:00
commit f0a14099a1
2 changed files with 26 additions and 4 deletions

View file

@ -8,6 +8,7 @@ import {profiles,textureEntries,zip} from './build-planet-texture-packs.mjs';
const texturePrefix='assets/minecraft/textures/';
const packPrefix='assets/dunerealms/textures/planets/';
const blocksAtlas='assets/minecraft/atlases/blocks.json';
const generatedLicenceText=new Set(['CREDITS-Sand.txt','LICENSE-Sand-Luanti.txt']);
const cubeItems=fs.readFileSync(new URL('../JarvisConnector/src/main/resources/planet-cube-items.txt',import.meta.url),'utf8')
.split(/\r?\n/).map(line=>line.trim()).filter(Boolean);
if(new Set(cubeItems).size!==cubeItems.length||cubeItems.some(item=>!/^[a-z0-9_]+$/.test(item)))throw Error('Invalid planet cube item catalogue');
@ -19,7 +20,7 @@ function addEntry(entries,name,bytes){
entries.set(name,bytes);
}
export function centralPackEntries(base){
export function centralPackEntries(base,planetEntries=textureEntries){
const merged=new Map(base);
if(!merged.has('pack.mcmeta'))throw Error('The base must be an extracted network resource pack');
const packInfo=JSON.parse(merged.get('pack.mcmeta'));
@ -29,12 +30,14 @@ export function centralPackEntries(base){
const sprites=new Map(atlas.sources.filter(source=>source.type==='single'||source.type==='minecraft:single')
.map(source=>[source.sprite??source.resource,source.resource]));
for(const planet of Object.keys(profiles)){
for(const [name,bytes] of textureEntries(planet)){
for(const [name,bytes] of planetEntries(planet)){
if(name==='pack.mcmeta')continue;
const target=name.startsWith(texturePrefix)
?packPrefix+planet+'/'+name.slice(texturePrefix.length)
:'licenses/planet-materials/'+name;
addEntry(merged,target,bytes);
// The standalone planet archives retain their existing published checksums.
const content=generatedLicenceText.has(name)?Buffer.from(bytes.toString('utf8').replaceAll('\r\n','\n')):bytes;
addEntry(merged,target,content);
}
for(const material of cubeItems){
const id=planet+'/'+material;

View file

@ -5,7 +5,7 @@ import {createHash} from 'node:crypto';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {build,profiles,textureEntries,protectedTextures} from './build-planet-texture-packs.mjs';
import {build,profiles,textureEntries,protectedTextures,zip} from './build-planet-texture-packs.mjs';
import {sandPalettes} from './flat-sand.mjs';
import {centralPackEntries} from './build-central-resource-pack.mjs';
@ -114,3 +114,22 @@ test('the central builder preserves compatible common runtime assets and leaves
assert(!entries.has('assets/minecraft/textures/block/stone.png'));
assert(entries.has('assets/dunerealms/textures/planets/arrakis/block/stone.png'));
});
test('central generated licence text has identical ZIP bytes for Windows and LF inputs',()=>{
const inherited=Buffer.from('Production attribution\r\nKeep verbatim\r\n');
const base=new Map([
['pack.mcmeta',Buffer.from(JSON.stringify({pack:{pack_format:64}}))],
['CREDITS-Sand.txt',inherited],
['LICENSE-Sand-Luanti.txt',inherited]
]);
const names=['CREDITS-Sand.txt','LICENSE-Sand-Luanti.txt'];
const text='Copyright © 2026\nTerms remain intact.\n';
const fixture=eol=>()=>new Map(names.map(name=>[name,Buffer.from(text.replaceAll('\n',eol))]));
const windows=centralPackEntries(base,fixture('\r\n'));
const linux=centralPackEntries(base,fixture('\n'));
assert.deepEqual(zip(windows),zip(linux));
for(const name of names){
assert.deepEqual(windows.get(name),inherited);
assert.equal(windows.get('licenses/planet-materials/'+name).toString('utf8'),text);
}
});