Skip to content

Commit 103b159

Browse files
committed
fix tests
1 parent 8836128 commit 103b159

21 files changed

Lines changed: 144 additions & 898 deletions

README.md

Lines changed: 52 additions & 852 deletions
Large diffs are not rendered by default.

src/processors/applePanelsProcessor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ class ApplePanelsProcessor extends BaseProcessor {
227227
}
228228

229229
async loadIntoTree(filePathOrBuffer: ProcessorInput): Promise<AACTree> {
230+
await Promise.resolve();
230231
const filename =
231232
typeof filePathOrBuffer === 'string' ? getBasename(filePathOrBuffer) : 'upload.plist';
232233
let buffer: Uint8Array;
@@ -483,6 +484,7 @@ class ApplePanelsProcessor extends BaseProcessor {
483484
}
484485

485486
async saveFromTree(tree: AACTree, outputPath: string): Promise<void> {
487+
await Promise.resolve();
486488
// Support two output modes:
487489
// 1) Single-file .plist (PanelDefinitions.plist content written directly)
488490
// 2) Apple Panels bundle folder (*.ascconfig) with Contents/Resources structure

src/processors/astericsGridProcessor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ class AstericsGridProcessor extends BaseProcessor {
847847
}
848848

849849
async loadIntoTree(filePathOrBuffer: ProcessorInput): Promise<AACTree> {
850+
await Promise.resolve();
850851
const tree = new AACTree();
851852
const filename =
852853
typeof filePathOrBuffer === 'string' ? getBasename(filePathOrBuffer) : 'upload.grd';
@@ -1311,6 +1312,7 @@ class AstericsGridProcessor extends BaseProcessor {
13111312
translations: Map<string, string>,
13121313
outputPath: string
13131314
): Promise<Uint8Array> {
1315+
await Promise.resolve();
13141316
let content = readTextFromInput(filePathOrBuffer);
13151317

13161318
// Remove BOM if present
@@ -1446,6 +1448,7 @@ class AstericsGridProcessor extends BaseProcessor {
14461448
}
14471449

14481450
async saveFromTree(tree: AACTree, outputPath: string): Promise<void> {
1451+
await Promise.resolve();
14491452
// Use default Asterics Grid styling instead of taking from first page
14501453
// This prevents issues where the first page has unusual colors (like purple)
14511454
const defaultPageStyle = {

src/processors/dotProcessor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class DotProcessor extends BaseProcessor {
9191
}
9292

9393
async extractTexts(filePathOrBuffer: ProcessorInput): Promise<string[]> {
94+
await Promise.resolve();
9495
const content = readTextFromInput(filePathOrBuffer);
9596

9697
const { nodes, edges } = this.parseDotFile(content);
@@ -112,6 +113,7 @@ class DotProcessor extends BaseProcessor {
112113
}
113114

114115
async loadIntoTree(filePathOrBuffer: ProcessorInput): Promise<AACTree> {
116+
await Promise.resolve();
115117
const filename =
116118
typeof filePathOrBuffer === 'string' ? getBasename(filePathOrBuffer) : 'upload.dot';
117119
const buffer = readBinaryFromInput(filePathOrBuffer);
@@ -217,6 +219,7 @@ class DotProcessor extends BaseProcessor {
217219
translations: Map<string, string>,
218220
outputPath: string
219221
): Promise<Uint8Array> {
222+
await Promise.resolve();
220223
const content = readTextFromInput(filePathOrBuffer);
221224
let translatedContent = content;
222225

@@ -239,6 +242,7 @@ class DotProcessor extends BaseProcessor {
239242
}
240243

241244
async saveFromTree(tree: AACTree, _outputPath: string): Promise<void> {
245+
await Promise.resolve();
242246
let dotContent = `digraph "${tree.metadata?.name || 'AACBoard'}" {\n`;
243247

244248
// Helper to escape DOT string

src/processors/excelProcessor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class ExcelProcessor extends BaseProcessor {
2525
* @returns Array of all text content found in the Excel file
2626
*/
2727
async extractTexts(_filePathOrBuffer: ProcessorInput): Promise<string[]> {
28+
await Promise.resolve();
2829
console.warn('ExcelProcessor.extractTexts is not implemented yet.');
2930
return [];
3031
}
@@ -35,6 +36,7 @@ export class ExcelProcessor extends BaseProcessor {
3536
* @returns AACTree representation of the Excel file
3637
*/
3738
async loadIntoTree(_filePathOrBuffer: ProcessorInput): Promise<AACTree> {
39+
await Promise.resolve();
3840
console.warn('ExcelProcessor.loadIntoTree is not implemented yet.');
3941
const tree = new AACTree();
4042
tree.metadata.format = 'excel';
@@ -53,6 +55,7 @@ export class ExcelProcessor extends BaseProcessor {
5355
_translations: Map<string, string>,
5456
outputPath: string
5557
): Promise<Uint8Array> {
58+
await Promise.resolve();
5659
console.warn('ExcelProcessor.processTexts is not implemented yet.');
5760
const outputDir = path.dirname(outputPath);
5861
if (!fs.existsSync(outputDir)) {

src/processors/gridset/helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ export async function openImage(
6565
): Promise<Uint8Array | null> {
6666
try {
6767
// eslint-disable-next-line @typescript-eslint/no-var-requires
68-
const JSZip = require('jszip');
68+
const JSZip = require('jszip') as typeof import('jszip');
6969
const zip = await JSZip.loadAsync(gridsetBuffer);
70-
const entries = await getZipEntriesWithPassword(zip, password);
70+
const entries = getZipEntriesWithPassword(zip, password);
7171
const want = normalizeZipPath(entryPath);
72-
const entry = entries.find((e: any) => normalizeZipPath(e.entryName) === want);
72+
const entry = entries.find((e) => normalizeZipPath(e.entryName) === want);
7373
if (!entry) return null;
7474
const data = await entry.getData();
7575
if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') {

src/processors/gridset/password.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from 'path';
2+
import type JSZip from 'jszip';
23
import { ProcessorOptions } from '../../core/baseProcessor';
34
import { ProcessorInput } from '../../utils/io';
45

@@ -36,12 +37,14 @@ export function resolveGridsetPasswordFromEnv(): string | undefined {
3637
* @param password - Optional password (kept for API compatibility, not used with JSZip)
3738
* @returns Array of entry objects with name and data
3839
*/
39-
export async function getZipEntriesWithPassword(
40-
zip: any,
41-
password?: string
42-
): Promise<
43-
Array<{ name: string; entryName: string; dir: boolean; getData: () => Promise<Uint8Array> }>
44-
> {
40+
type ZipEntry = {
41+
name: string;
42+
entryName: string;
43+
dir: boolean;
44+
getData: () => Promise<Uint8Array>;
45+
};
46+
47+
export function getZipEntriesWithPassword(zip: JSZip, password?: string): ZipEntry[] {
4548
const entries: Array<{
4649
name: string;
4750
entryName: string;
@@ -58,7 +61,7 @@ export async function getZipEntriesWithPassword(
5861
);
5962
}
6063

61-
zip.forEach((relativePath: string, file: any) => {
64+
zip.forEach((relativePath: string, file: JSZip.JSZipObject) => {
6265
entries.push({
6366
name: relativePath,
6467
entryName: relativePath,

src/processors/gridset/wordlistHelpers.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
import { XMLParser, XMLBuilder } from 'fast-xml-parser';
13+
import type JSZip from 'jszip';
1314
import { getZipEntriesWithPassword, resolveGridsetPasswordFromEnv } from './password';
1415
import { decodeText } from '../../utils/io';
1516

@@ -133,15 +134,15 @@ export async function extractWordlists(
133134
const wordlists = new Map<string, WordList>();
134135
const parser = new XMLParser();
135136

136-
let zip: any;
137+
let zip: JSZip;
137138
try {
138139
// eslint-disable-next-line @typescript-eslint/no-var-requires
139-
const JSZip = require('jszip');
140+
const JSZip = require('jszip') as typeof import('jszip');
140141
zip = await JSZip.loadAsync(gridsetBuffer);
141142
} catch (error: any) {
142143
throw new Error(`Invalid gridset buffer: ${error.message}`);
143144
}
144-
const entries = await getZipEntriesWithPassword(zip, password);
145+
const entries = getZipEntriesWithPassword(zip, password);
145146

146147
// Process each grid file
147148
for (const entry of entries) {
@@ -220,15 +221,15 @@ export async function updateWordlist(
220221
suppressEmptyNode: false,
221222
});
222223

223-
let zip: any;
224+
let zip: JSZip;
224225
try {
225226
// eslint-disable-next-line @typescript-eslint/no-var-requires
226-
const JSZip = require('jszip');
227+
const JSZip = require('jszip') as typeof import('jszip');
227228
zip = await JSZip.loadAsync(gridsetBuffer);
228229
} catch (error: any) {
229230
throw new Error(`Invalid gridset buffer: ${error.message}`);
230231
}
231-
const entries = await getZipEntriesWithPassword(zip, password);
232+
const entries = getZipEntriesWithPassword(zip, password);
232233

233234
let found = false;
234235

@@ -271,7 +272,7 @@ export async function updateWordlist(
271272

272273
// Rebuild the XML
273274
const updatedXml = builder.build(data);
274-
zip.file(entry.entryName, updatedXml, 'utf8');
275+
zip.file(entry.entryName, updatedXml, { binary: false });
275276
found = true;
276277
} catch (error) {
277278
const message = error instanceof Error ? error.message : String(error);

src/processors/gridsetProcessor.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ import { isSymbolLibraryReference } from './gridset/resolver';
3535
import { generateCloneId } from '../utilities/analytics/utils/idGenerator';
3636
import { translateWithSymbols, extractSymbolsFromButton } from './gridset/symbolAlignment';
3737
import { ProcessorInput, readBinaryFromInput, decodeText } from '../utils/io';
38+
import type JSZip from 'jszip';
3839
// Use dynamic import for JSZip to support both browser and Node environments
39-
let JSZipModule: any;
40-
async function getJSZip() {
40+
type JSZipStatic = typeof JSZip;
41+
let JSZipModule: JSZipStatic | undefined;
42+
async function getJSZip(): Promise<JSZipStatic> {
4143
if (!JSZipModule) {
4244
try {
4345
// Try ES module import first (browser/Vite)
@@ -54,6 +56,9 @@ async function getJSZip() {
5456
}
5557
}
5658
}
59+
if (!JSZipModule) {
60+
throw new Error('Zip handling requires JSZip in this environment.');
61+
}
5762
return JSZipModule;
5863
}
5964

@@ -443,7 +448,7 @@ class GridsetProcessor extends BaseProcessor {
443448
async loadIntoTree(filePathOrBuffer: ProcessorInput): Promise<AACTree> {
444449
const tree = new AACTree();
445450

446-
let zip: any;
451+
let zip: JSZip;
447452
try {
448453
const JSZip = await getJSZip();
449454
const zipInput = readBinaryFromInput(filePathOrBuffer);
@@ -452,11 +457,7 @@ class GridsetProcessor extends BaseProcessor {
452457
throw new Error(`Invalid ZIP file format: ${error.message}`);
453458
}
454459
const password = this.getGridsetPassword(filePathOrBuffer);
455-
const entries = await getZipEntriesWithPassword(
456-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
457-
zip,
458-
password
459-
);
460+
const entries = getZipEntriesWithPassword(zip, password);
460461
const parser = new XMLParser({ ignoreAttributes: false });
461462
const isEncryptedArchive =
462463
typeof filePathOrBuffer === 'string' && filePathOrBuffer.toLowerCase().endsWith('.gridsetx');
@@ -617,9 +618,9 @@ class GridsetProcessor extends BaseProcessor {
617618
// Skip unreadable files
618619
continue;
619620
}
620-
let data: any;
621+
let data: Record<string, unknown>;
621622
try {
622-
data = parser.parse(xmlContent);
623+
data = parser.parse(xmlContent) as Record<string, unknown>;
623624
console.log(`[Gridset] Parsed ${entry.entryName}, root keys:`, Object.keys(data));
624625
} catch (error: any) {
625626
// Skip malformed XML but log the specific error
@@ -628,7 +629,7 @@ class GridsetProcessor extends BaseProcessor {
628629
}
629630

630631
// Grid3 XML: <Grid> root
631-
const grid = data.Grid || data.grid;
632+
const grid = (data as { Grid?: any; grid?: any }).Grid || (data as { grid?: any }).grid;
632633
if (!grid) {
633634
console.warn(`[Gridset] No Grid/grid found in ${entry.entryName}`);
634635
continue;
@@ -1866,7 +1867,7 @@ class GridsetProcessor extends BaseProcessor {
18661867
suppressEmptyNode: true,
18671868
});
18681869
const settingsXmlContent = settingsBuilder.build(settingsData);
1869-
zip.file('Settings0/settings.xml', settingsXmlContent, 'utf8');
1870+
zip.file('Settings0/settings.xml', settingsXmlContent, { binary: false });
18701871

18711872
// Create Settings0/Styles/style.xml if there are styles
18721873
if (uniqueStyles.size > 0) {
@@ -1904,7 +1905,7 @@ class GridsetProcessor extends BaseProcessor {
19041905
indentBy: ' ',
19051906
});
19061907
const styleXmlContent = styleBuilder.build(styleData);
1907-
zip.file('Settings0/Styles/styles.xml', styleXmlContent, 'utf8');
1908+
zip.file('Settings0/Styles/styles.xml', styleXmlContent, { binary: false });
19081909
}
19091910

19101911
// Collect grid file paths for FileMap.xml
@@ -2073,7 +2074,7 @@ class GridsetProcessor extends BaseProcessor {
20732074
// Add to zip in Grids folder with proper Grid3 naming
20742075
const gridPath = `Grids/${page.name || page.id}/grid.xml`;
20752076
gridFilePaths.push(gridPath);
2076-
zip.file(gridPath, xmlContent, 'utf8');
2077+
zip.file(gridPath, xmlContent, { binary: false });
20772078
});
20782079

20792080
// Write image files to ZIP
@@ -2125,7 +2126,7 @@ class GridsetProcessor extends BaseProcessor {
21252126
indentBy: ' ',
21262127
});
21272128
const fileMapXmlContent = fileMapBuilder.build(fileMapData);
2128-
zip.file('FileMap.xml', fileMapXmlContent, 'utf8');
2129+
zip.file('FileMap.xml', fileMapXmlContent, { binary: false });
21292130

21302131
// Write the zip file
21312132
const zipBuffer = await zip.generateAsync({ type: 'uint8array' });

src/processors/obfProcessor.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ import {
2929
writeTextToPath,
3030
encodeBase64,
3131
} from '../utils/io';
32+
import type JSZip from 'jszip';
3233

3334
// Use dynamic import for JSZip to support both browser and Node environments
34-
let JSZipModuleObf: any;
35-
async function getJSZipObf() {
35+
type JSZipStatic = typeof JSZip;
36+
let JSZipModuleObf: JSZipStatic | undefined;
37+
async function getJSZipObf(): Promise<JSZipStatic> {
3638
if (!JSZipModuleObf) {
3739
try {
3840
// Try ES module import first (browser/Vite)
@@ -49,6 +51,9 @@ async function getJSZipObf() {
4951
}
5052
}
5153
}
54+
if (!JSZipModuleObf) {
55+
throw new Error('Zip handling requires JSZip in this environment.');
56+
}
5257
return JSZipModuleObf;
5358
}
5459

@@ -101,7 +106,7 @@ interface ObfBoard {
101106
}
102107

103108
class ObfProcessor extends BaseProcessor {
104-
private zipFile?: any; // JSZip instance
109+
private zipFile?: JSZip; // JSZip instance
105110
private imageCache: Map<string, string> = new Map(); // Cache for data URLs
106111

107112
constructor(options?: ProcessorOptions) {
@@ -133,7 +138,8 @@ class ObfProcessor extends BaseProcessor {
133138
try {
134139
const file = this.zipFile.file(imagePath as string);
135140
if (file) {
136-
return await file.async('nodebuffer');
141+
const buffer = await file.async('nodebuffer');
142+
return buffer;
137143
}
138144
} catch (err) {
139145
continue;
@@ -174,7 +180,7 @@ class ObfProcessor extends BaseProcessor {
174180
try {
175181
const file = this.zipFile.file(imagePath as string);
176182
if (file) {
177-
const buffer = await file.async('nodebuffer');
183+
const buffer = await file.async('uint8array');
178184
const contentType =
179185
(imageData as { content_type?: string }).content_type ||
180186
this.getMimeTypeFromFilename(imagePath as string);
@@ -506,7 +512,7 @@ class ObfProcessor extends BaseProcessor {
506512
}
507513

508514
const JSZip = await getJSZipObf();
509-
let zip: any;
515+
let zip: JSZip;
510516
try {
511517
const zipInput = readBinaryFromInput(filePathOrBuffer);
512518
zip = await JSZip.loadAsync(zipInput);
@@ -522,8 +528,8 @@ class ObfProcessor extends BaseProcessor {
522528
console.log('[OBF] Detected zip archive, extracting .obf files');
523529

524530
// Collect all .obf entries
525-
const obfEntries: Array<{ name: string; file: any }> = [];
526-
zip.forEach((relativePath: string, file: any) => {
531+
const obfEntries: Array<{ name: string; file: JSZip.JSZipObject }> = [];
532+
zip.forEach((relativePath: string, file: JSZip.JSZipObject) => {
527533
if (file.dir) return;
528534
if (relativePath.endsWith('.obf')) {
529535
obfEntries.push({ name: relativePath, file });

0 commit comments

Comments
 (0)