Skip to content

Commit e254624

Browse files
authored
Fix WisdomTree browser startup (#3)
* Fix WisdomTree browser script startup * Add inline browser script validation --------- Co-authored-by: daggerok <daggerok@users.noreply.github.com>
1 parent e2967ad commit e254624

4 files changed

Lines changed: 40 additions & 5 deletions

File tree

‎.github/workflows/update-data.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ jobs:
175175
with:
176176
bun-version: latest
177177

178+
- name: Validate inline browser script
179+
run: bun ./scripts/check-index.ts
180+
178181
- name: Run updater unit tests
179182
run: bun test scripts/update-data.test.ts
180183

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ The header toolbar includes the same integrated drag-and-drop upload as `daggero
117117

118118
- `scripts/update-data.ts` — Bun updater with no runtime dependencies: WisdomTree catalog parser, SEC fund/series resolver, raw N-PORT XML parser, issuer fallback, Yahoo chart reader, derived metrics, strict range parsers, bounded-run cursor, retries and deterministic paginated writes.
119119
- `scripts/update-data.test.ts` — Bun tests for range/AUM parsing, catalog parsing and $(000) conversion, SEC mapping and raw N-PORT parsing, Atom resolution, Yahoo chart/return helpers and distribution-frequency inference.
120+
- `scripts/check-index.ts` — Bun transpile check for the inline browser TypeScript, preventing a syntax error from leaving the published catalog on its loading screen.
120121
- `api/wisdomtree/**` — generated static feed: `index.json`, `funds/{TICKER}/meta.json`, paginated `holdings/` and `history/` files, and `update-state.json`.
121122
- `index.html` — single-file TypeScript UI with inline styles and scripts, matching the sibling repositories' searchable catalog, persistent selection/blacklist, watchlist aggregation, detail tabs, exports and N-PORT upload workflow.
122123
- Verification before publishing: `bun test scripts/update-data.test.ts`, `bunx tsc --noEmit`, and a static-server smoke test.

‎index.html‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ <h1 class="min-w-0 text-xl font-bold tracking-tight text-slate-900 dark:text-whi
366366
'CAGR 5Y': 'CAGR 5Y (5-Year Compound Annual Growth Rate) — Annualized market-price return over 5 years, computed from adjusted closes.',
367367
'CAGR 10Y': 'CAGR 10Y (10-Year Compound Annual Growth Rate) — Annualized market-price return over 10 years, computed from adjusted closes.',
368368
YTD: 'YTD market-price total return, last trading day (adjusted closes).',
369-
'1Y': '1-year official WisdomTree Market Price Return where published, otherwise adjusted market-price return, month-end series.'
370-
'3Y': '3-year average annual market-price return (CAGR), official WisdomTree Market Price Return where published, otherwise Yahoo adjusted close.'
371-
'5Y': '5-year average annual market-price return (CAGR), official WisdomTree Market Price Return where published, otherwise Yahoo adjusted close.'
372-
'10Y': '10-year average annual market-price return (CAGR), official WisdomTree Market Price Return where published, otherwise Yahoo adjusted close.'
373-
'SI Ann.': 'Since-inception annualized market-price return, official WisdomTree Market Price Return where published, otherwise Yahoo adjusted close.'
369+
'1Y': '1-year official WisdomTree Market Price Return where published, otherwise adjusted market-price return, month-end series.',
370+
'3Y': '3-year average annual market-price return (CAGR), official WisdomTree Market Price Return where published, otherwise Yahoo adjusted close.',
371+
'5Y': '5-year average annual market-price return (CAGR), official WisdomTree Market Price Return where published, otherwise Yahoo adjusted close.',
372+
'10Y': '10-year average annual market-price return (CAGR), official WisdomTree Market Price Return where published, otherwise Yahoo adjusted close.',
373+
'SI Ann.': 'Since-inception annualized market-price return, official WisdomTree Market Price Return where published, otherwise Yahoo adjusted close.',
374374
'Return As Of': 'As-of date of the month-end return series.',
375375
Inception: 'Fund inception date.',
376376
Exchange: 'Primary listing exchange.',

‎scripts/check-index.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bun
2+
3+
// Parse the browser's inline TypeScript before publishing. The deployed page
4+
// relies on Babel standalone at runtime, so a missing comma or other syntax
5+
// error would otherwise leave the catalog permanently on its loading state.
6+
7+
declare const Bun: {
8+
file(path: string): { text(): Promise<string> };
9+
Transpiler: new (options: { loader: string }) => { transform(source: string): string | Promise<string> };
10+
};
11+
12+
type Match = RegExpExecArray & { 1: string };
13+
14+
export function extractInlineBrowserScript(html: string): string {
15+
const match = /<script\s+type=["']text\/babel["'][^>]*>([\s\S]*?)<\/script>/i.exec(html) as Match | null;
16+
if (!match || !match[1].trim()) throw new Error('index.html: inline text/babel script not found');
17+
return match[1];
18+
}
19+
20+
export async function parseInlineBrowserScript(source: string): Promise<string> {
21+
const transformed = await new Bun.Transpiler({ loader: 'tsx' }).transform(source);
22+
if (!transformed || typeof transformed !== 'string') throw new Error('index.html: inline script did not transpile');
23+
return transformed;
24+
}
25+
26+
if ((import.meta as { main?: boolean }).main) {
27+
const html = await Bun.file(new URL('../index.html', import.meta.url).pathname).text();
28+
const source = extractInlineBrowserScript(html);
29+
const transformed = await parseInlineBrowserScript(source);
30+
console.log(`index.html inline script parses (${source.length.toLocaleString()} source chars, ${transformed.length.toLocaleString()} transpiled chars)`);
31+
}

0 commit comments

Comments
 (0)