Skip to content

Commit 324f536

Browse files
committed
Complete two backlog items: type CDN scripts and add Lighthouse CI
- Add ambient module declaration (_regions.d.ts) for the WaveSurfer RegionsPlugin CDN ESM URL, removing @ts-expect-error and inline unknown casts from _score.ts. - Add Lighthouse CI job to astro.yml (runs after build with @lhci/cli) and .lighthouserc.json with accessibility error threshold and performance/SEO/best-practices warnings. - Mark both items completed in docs/backlog.md. https://claude.ai/code/session_01Xo3opugkX7CwWd7F7Vr1od
1 parent 539f6fc commit 324f536

5 files changed

Lines changed: 86 additions & 27 deletions

File tree

.github/workflows/astro.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,29 @@ jobs:
6262
with:
6363
path: ${{ env.BUILD_PATH }}/dist
6464

65+
lighthouse:
66+
name: Lighthouse CI
67+
runs-on: ubuntu-latest
68+
needs: build
69+
steps:
70+
- name: Checkout
71+
uses: actions/checkout@v4
72+
- name: Setup Node
73+
uses: actions/setup-node@v4
74+
with:
75+
node-version: "22"
76+
cache: npm
77+
cache-dependency-path: package-lock.json
78+
- name: Install dependencies
79+
run: npm ci
80+
working-directory: ${{ env.BUILD_PATH }}
81+
- name: Build with Astro
82+
run: npx astro build
83+
working-directory: ${{ env.BUILD_PATH }}
84+
- name: Run Lighthouse CI
85+
run: npx @lhci/cli@0.14.x autorun
86+
working-directory: ${{ env.BUILD_PATH }}
87+
6588
deploy:
6689
environment:
6790
name: github-pages

.lighthouserc.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"ci": {
3+
"collect": {
4+
"staticDistDir": "./dist",
5+
"numberOfRuns": 1
6+
},
7+
"assert": {
8+
"assertions": {
9+
"categories:performance": ["warn", { "minScore": 0.8 }],
10+
"categories:accessibility": ["error", { "minScore": 0.9 }],
11+
"categories:best-practices": ["warn", { "minScore": 0.9 }],
12+
"categories:seo": ["warn", { "minScore": 0.9 }]
13+
}
14+
},
15+
"upload": {
16+
"target": "temporary-public-storage"
17+
}
18+
}
19+
}

docs/backlog.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,10 @@ construction" placeholders. The old AI-generated versions have been archived at
1313

1414
## Low Priority
1515

16-
### Type external CDN scripts
17-
18-
`_score.ts` uses `@ts-expect-error` for a CDN ESM import of the WaveSurfer
19-
regions plugin. Consider bundling these dependencies or adding typed wrappers.
20-
21-
- File: `src/pages/ai-generated/do-olls-that-will-talk/_score.ts`
22-
2316
### Add RSS feed
2417

2518
Blog-like content would benefit from `@astrojs/rss`.
2619

27-
### Add Lighthouse CI to GitHub Actions
28-
29-
No performance budget exists. Lighthouse CI in the workflow would catch regressions.
30-
31-
- File: `.github/workflows/astro.yml`
32-
3320
## Improvements
3421

3522
### Consider bundling WaveSurfer and YouTube API
@@ -50,3 +37,9 @@ Loading these from CDN introduces external dependencies. Bundling via npm would
5037
- **Inline trivial npm script wrappers** — justfile recipes already call tools
5138
directly (`eslint`, `tsc`, `astro`, `prettier`, `vitest`); only `precommit`
5239
and `prepush` delegate to npm because they run multi-step pipelines.
40+
- **Type external CDN scripts** — added ambient module declaration
41+
`_regions.d.ts` for the WaveSurfer RegionsPlugin CDN URL; removed
42+
`@ts-expect-error` and inline casts from `_score.ts`.
43+
- **Add Lighthouse CI to GitHub Actions** — added `lighthouse` job to
44+
`astro.yml` (runs after build, uses `@lhci/cli`); added `.lighthouserc.json`
45+
with accessibility error threshold and performance/SEO/best-practices warnings.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Typed ambient declaration for the WaveSurfer RegionsPlugin CDN ESM build.
2+
// This removes the @ts-expect-error on the CDN import in _score.ts.
3+
4+
declare module "https://cdn.jsdelivr.net/npm/wavesurfer.js@7/dist/plugins/regions.esm.js" {
5+
export interface RegionParams {
6+
start: number;
7+
end: number;
8+
color?: string;
9+
content?: string;
10+
resize?: boolean;
11+
drag?: boolean;
12+
id?: string;
13+
}
14+
15+
export interface Region {
16+
start: number;
17+
}
18+
19+
export interface RegionsPluginInstance {
20+
addRegion(params: RegionParams): Region;
21+
on(
22+
event: "region-clicked",
23+
fn: (region: Region, event: { stopPropagation(): void }) => void
24+
): void;
25+
}
26+
27+
const RegionsPlugin: {
28+
create(): RegionsPluginInstance;
29+
};
30+
31+
export default RegionsPlugin;
32+
}

src/pages/ai-generated/do-olls-that-will-talk/_score.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// File: _score.ts
22

3-
// @ts-expect-error - CDN ESM import without type declarations
43
import RegionsPlugin from "https://cdn.jsdelivr.net/npm/wavesurfer.js@7/dist/plugins/regions.esm.js";
4+
import type { RegionsPluginInstance } from "https://cdn.jsdelivr.net/npm/wavesurfer.js@7/dist/plugins/regions.esm.js";
55

66
declare global {
77
interface Window {
@@ -167,14 +167,13 @@ if (!isBrowser()) {
167167
url: "/audio/do-olls-clip.mp4",
168168
});
169169

170-
const regions = ws.registerPlugin(RegionsPlugin.create());
170+
const regions = ws.registerPlugin(
171+
RegionsPlugin.create()
172+
) as RegionsPluginInstance;
171173

172174
ws.on("ready", () => {
173175
markers.forEach((m, i) => {
174-
// regions is untyped (CDN plugin), so we go through unknown.
175-
(
176-
regions as { addRegion: (cfg: Record<string, unknown>) => void }
177-
).addRegion({
176+
regions.addRegion({
178177
start: m.time,
179178
end: m.time + 0.05,
180179
color: categoryColor[m.category],
@@ -202,14 +201,7 @@ if (!isBrowser()) {
202201
if (playPause) playPause.textContent = "Play";
203202
});
204203

205-
(
206-
regions as {
207-
on: (
208-
evt: string,
209-
fn: (r: { start: number }, e: { stopPropagation: () => void }) => void
210-
) => void;
211-
}
212-
).on("region-clicked", (r, e) => {
204+
regions.on("region-clicked", (r, e) => {
213205
e.stopPropagation();
214206
ws.setTime(r.start);
215207
});

0 commit comments

Comments
 (0)