this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ts v4

alice 4730e722 2284fea1

+34 -50
+26 -43
scripts/generateAirportTzListHelpers.ts
··· 1 1 import * as fs from 'fs/promises'; 2 2 import * as cheerio from 'cheerio'; 3 3 import { find as findTz } from 'geo-tz'; 4 - import { parse } from 'csv-parse'; 4 + import { parse as parseSync } from 'csv-parse/sync'; 5 5 import { findDstTransitions, DstTransitions } from './tzCommon'; 6 6 7 7 // --------------------------------------------------------------------------- ··· 132 132 if (!response.ok) throw new Error(`Failed to fetch ${url}: ${response.statusText}`); 133 133 const text = await response.text(); 134 134 console.log('Routes data downloaded, parsing...'); 135 - const records: RouteRecord[] = []; 136 - const parser = parse({ delimiter: ',', columns: false, skip_empty_lines: true, trim: true }); 137 - parser.on('readable', () => { 138 - let record; 139 - while ((record = parser.read()) !== null) { 140 - const srcIata = record[2]; 141 - const dstIata = record[4]; 142 - if ( 143 - srcIata?.length === 3 && /^[A-Z]+$/.test(srcIata) && 144 - dstIata?.length === 3 && /^[A-Z]+$/.test(dstIata) 145 - ) { 146 - records.push([srcIata, dstIata]); 147 - } 135 + // Parse CSV synchronously to avoid lingering parser handles 136 + const rawRecords = parseSync(text, { delimiter: ',', columns: false, skip_empty_lines: true, trim: true }) as string[][]; 137 + // Build RouteRecord[] explicitly to satisfy tuple typing 138 + const records = rawRecords.reduce<RouteRecord[]>((acc, record) => { 139 + const srcIata = record[2]; 140 + const dstIata = record[4]; 141 + if ( 142 + srcIata.length === 3 && /^[A-Z]+$/.test(srcIata) && 143 + dstIata.length === 3 && /^[A-Z]+$/.test(dstIata) 144 + ) { 145 + acc.push([srcIata, dstIata]); 148 146 } 149 - }); 150 - parser.on('error', err => console.error('CSV Parsing Error:', err.message)); 151 - return new Promise(resolve => { 152 - parser.on('end', () => { 153 - console.log(`Finished parsing routes. Found ${records.length} valid routes.`); 154 - resolve(records); 155 - }); 156 - parser.write(text); 157 - parser.end(); 158 - }); 147 + return acc; 148 + }, []); 149 + console.log(`Finished parsing routes. Found ${records.length} valid routes.`); 150 + return records; 159 151 } catch (error) { 160 152 console.error('Error downloading or parsing routes data:', error); 161 153 throw error; ··· 187 179 if (!response.ok) throw new Error(`Failed to fetch ${url}: ${response.statusText}`); 188 180 const text = await response.text(); 189 181 console.log('OurAirports data downloaded, parsing...'); 190 - const parser = parse({ delimiter: ',', columns: true, skip_empty_lines: true, trim: true }); 191 - parser.on('readable', () => { 192 - let record; 193 - while ((record = parser.read()) !== null) { 194 - const iata = record.iata_code; 195 - const type = record.type; 196 - const scheduled = record.scheduled_service; 197 - if (iata?.length === 3 && /^[A-Z0-9]+$/.test(iata)) { 198 - ourAirportsMap.set(iata.toUpperCase(), { iata: iata.toUpperCase(), type: type || '', scheduled_service: scheduled || '' }); 199 - } 182 + // Parse CSV synchronously to avoid lingering parser handles 183 + const rawRecords: Array<Record<string, string>> = parseSync(text, { delimiter: ',', columns: true, skip_empty_lines: true, trim: true }); 184 + rawRecords.forEach((record: any) => { 185 + const iata = record.iata_code; 186 + const type = record.type; 187 + const scheduled = record.scheduled_service; 188 + if (iata?.length === 3 && /^[A-Z0-9]+$/.test(iata)) { 189 + ourAirportsMap.set(iata.toUpperCase(), { iata: iata.toUpperCase(), type: type || '', scheduled_service: scheduled || '' }); 200 190 } 201 191 }); 202 - parser.on('error', err => console.error('OurAirports CSV Parsing Error:', err.message)); 203 - return new Promise(resolve => { 204 - parser.on('end', () => { 205 - console.log(`Finished parsing OurAirports. Found ${ourAirportsMap.size} airports with IATA.`); 206 - resolve(ourAirportsMap); 207 - }); 208 - parser.write(text); 209 - parser.end(); 210 - }); 192 + console.log(`Finished parsing OurAirports. Found ${ourAirportsMap.size} airports with IATA.`); 193 + return ourAirportsMap; 211 194 } catch (error) { 212 195 console.error('Error downloading or parsing OurAirports data:', error); 213 196 console.warn('Proceeding without OurAirports classification data.');
+8 -7
scripts/jest.config.js
··· 6 6 moduleFileExtensions: ["ts", "js", "json", "node"], 7 7 // Transform TypeScript files using ts-jest 8 8 transform: { 9 - "^.+\\.tsx?$": "ts-jest", 9 + "^.+\\.tsx?$": [ 10 + "ts-jest", 11 + { 12 + diagnostics: false, 13 + }, 14 + ], 10 15 }, 11 - // Silence verbose warnings from ts-jest about diagnostics for faster runs 12 - globals: { 13 - "ts-jest": { 14 - diagnostics: false, 15 - }, 16 - }, 16 + // Enable detectOpenHandles to report and close any lingering handles 17 + detectOpenHandles: true, 17 18 };