Skip to content

Commit 3220e44

Browse files
committed
fix browser for zips
1 parent aad0f6b commit 3220e44

6 files changed

Lines changed: 50 additions & 11 deletions

File tree

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ jobs:
4747
npm version "${{ steps.release_version.outputs.version }}" --no-git-tag-version
4848
4949
- run: npm run build:all --if-present
50+
- run: npm run verify:browser-build --if-present
5051
- run: npm publish --access public

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"format": "prettier --write \"src/**/*.{js,ts}\" \"test/**/*.{js,ts}\" \"*.{js,ts,json,md}\"",
9595
"format:check": "prettier --check \"src/**/*.{js,ts}\" \"test/**/*.{js,ts}\" \"*.{js,ts,json,md}\"",
9696
"smoke:browser": "node scripts/smoke-browser-bundle.js",
97+
"verify:browser-build": "node scripts/verify-browser-build.js",
9798
"test": "npm run build && jest",
9899
"test:watch": "npm run build && jest --watch",
99100
"test:coverage": "npm run build && jest --coverage",
@@ -102,8 +103,8 @@
102103
"docs": "typedoc",
103104
"coverage:report": "node scripts/coverage-analysis.js",
104105
"type-check": "tsc --noEmit",
105-
"prepublishOnly": "npm run build",
106-
"prepack": "npm run build"
106+
"prepublishOnly": "npm run build:all && npm run verify:browser-build",
107+
"prepack": "npm run build:all && npm run verify:browser-build"
107108
},
108109
"keywords": [
109110
"aac",

scripts/verify-browser-build.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const requiredFiles = [
5+
path.join('dist', 'browser', 'index.browser.js'),
6+
path.join('dist', 'index.browser.d.ts'),
7+
];
8+
9+
const missing = requiredFiles.filter((file) => !fs.existsSync(file));
10+
11+
if (missing.length > 0) {
12+
console.error('Browser build verification failed. Missing files:');
13+
missing.forEach((file) => {
14+
console.error(`- ${file}`);
15+
});
16+
process.exit(1);
17+
}
18+
19+
const empty = requiredFiles.filter((file) => fs.statSync(file).size === 0);
20+
if (empty.length > 0) {
21+
console.error('Browser build verification failed. Empty files:');
22+
empty.forEach((file) => {
23+
console.error(`- ${file}`);
24+
});
25+
process.exit(1);
26+
}
27+
28+
console.log('Browser build verification passed.');

src/processors/gridsetProcessor.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,14 @@ class GridsetProcessor extends BaseProcessor {
553553

554554
// Debug: log all entry names
555555
console.log('[Gridset] Total zip entries:', entries.length);
556-
const gridEntries = entries.filter(
557-
(e) => e.entryName.startsWith('Grids/') && e.entryName.endsWith('grid.xml')
558-
);
556+
const normalizeEntryName = (entryName: string): string =>
557+
entryName.replace(/\\/g, '/').toLowerCase();
558+
const isGridXmlEntry = (entryName: string): boolean => {
559+
const normalized = normalizeEntryName(entryName);
560+
if (!normalized.endsWith('grid.xml')) return false;
561+
return normalized.startsWith('grids/') || normalized.includes('/grids/');
562+
};
563+
const gridEntries = entries.filter((e) => isGridXmlEntry(e.entryName));
559564
console.log('[Gridset] Grid XML entries found:', gridEntries.length);
560565
if (gridEntries.length > 0) {
561566
console.log(
@@ -569,7 +574,7 @@ class GridsetProcessor extends BaseProcessor {
569574
const gridIdToNameMap = new Map<string, string>();
570575

571576
for (const entry of entries) {
572-
if (entry.entryName.startsWith('Grids/') && entry.entryName.endsWith('grid.xml')) {
577+
if (isGridXmlEntry(entry.entryName)) {
573578
try {
574579
const xmlContent = decodeText(await readEntryBuffer(entry));
575580
const data = parser.parse(xmlContent);
@@ -605,7 +610,7 @@ class GridsetProcessor extends BaseProcessor {
605610
// Second pass: process each grid file in the gridset
606611
for (const entry of entries) {
607612
// Only process files named grid.xml under Grids/ (any subdir)
608-
if (entry.entryName.startsWith('Grids/') && entry.entryName.endsWith('grid.xml')) {
613+
if (isGridXmlEntry(entry.entryName)) {
609614
let xmlContent: string;
610615
try {
611616
const buffer = await readEntryBuffer(entry);

src/processors/obfProcessor.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class ObfProcessor extends BaseProcessor {
449449
}
450450

451451
// If input is a string path and ends with .obf, treat as JSON
452-
if (typeof filePathOrBuffer === 'string' && filePathOrBuffer.endsWith('.obf')) {
452+
if (typeof filePathOrBuffer === 'string' && filePathOrBuffer.toLowerCase().endsWith('.obf')) {
453453
try {
454454
const content = readTextFromInput(filePathOrBuffer);
455455
const boardData = tryParseObfJson(content);
@@ -502,7 +502,10 @@ class ObfProcessor extends BaseProcessor {
502502

503503
// Otherwise, try as ZIP (.obz). Detect likely zip signature first; throw if neither JSON nor ZIP
504504
function isLikelyZip(input: ProcessorInput): boolean {
505-
if (typeof input === 'string') return input.endsWith('.zip') || input.endsWith('.obz');
505+
if (typeof input === 'string') {
506+
const lowered = input.toLowerCase();
507+
return lowered.endsWith('.zip') || lowered.endsWith('.obz');
508+
}
506509
const bytes = readBinaryFromInput(input);
507510
return bytes.length >= 2 && bytes[0] === 0x50 && bytes[1] === 0x4b;
508511
}
@@ -531,7 +534,7 @@ class ObfProcessor extends BaseProcessor {
531534
const obfEntries: Array<{ name: string; file: JSZip.JSZipObject }> = [];
532535
zip.forEach((relativePath: string, file: JSZip.JSZipObject) => {
533536
if (file.dir) return;
534-
if (relativePath.endsWith('.obf')) {
537+
if (relativePath.toLowerCase().endsWith('.obf')) {
535538
obfEntries.push({ name: relativePath, file });
536539
}
537540
});

tsconfig.browser.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"module": "ES2020",
66
"moduleResolution": "node",
77
"lib": ["ES2020", "DOM"],
8-
"declaration": false
8+
"declaration": true,
9+
"declarationDir": "./dist"
910
},
1011
"include": ["src/index.browser.ts"]
1112
}

0 commit comments

Comments
 (0)