From 9b6396bf93595ebc04cdf0c59faef8f5baa39fbb Mon Sep 17 00:00:00 2001 From: Leynos Date: Thu, 14 Aug 2025 18:30:45 +0100 Subject: [PATCH 1/2] Document bun lock strategy --- .github/workflows/ci.yml | 2 -- .gitignore | 5 ++++- AGENTS.md | 15 +++++++-------- frontend-pwa/src/api/client.ts | 16 ++++++---------- frontend-pwa/src/app/App.tsx | 32 +++++++++----------------------- 5 files changed, 26 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b932f8368..3bb315bbf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,8 +2,6 @@ name: ci "on": push: pull_request: -permissions: - contents: read jobs: build: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index b6d8da22a..b94652525 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,10 @@ # Node node_modules/ -**/dist/ +/frontend-pwa/node_modules/ +/packages/tokens/node_modules/ +/frontend-pwa/dist/ +/packages/tokens/dist/ # Misc .DS_Store diff --git a/AGENTS.md b/AGENTS.md index e5f12ccf0..833cda60b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -58,7 +58,7 @@ behaviour being corrected both to validate the fix and to guard against regression. - Passes all relevant unit and behavioural tests according to the guidelines - above. See “### Testing”. (Use `make test` to verify). + above. (Use `make test` to verify). - Passes lint checks. (Use `make lint` to verify). - Adheres to formatting standards tested using a formatting validator. (Use `make check-fmt` to verify). @@ -79,7 +79,7 @@ ## Refactoring Heuristics & Workflow -- **Recognizing Refactoring Needs:** Regularly assess the codebase for potential +- **Recognising Refactoring Needs:** Regularly assess the codebase for potential refactoring opportunities. Consider refactoring when you observe: - **Long Methods/Functions:** Functions or methods that are excessively long or try to do too many things. @@ -242,8 +242,7 @@ browser‑only runtime. - `preview`: `vite preview` - `test`: `vitest run --coverage` - `audit`: `bun x npm@latest audit` - - `audit:snyk`: `bun x snyk test` (requires `snyk` CLI and authentication; - run `snyk auth` locally, and set `SNYK_TOKEN` in CI secrets) + - `audit:snyk`: `bun x snyk test` ### Compiler Configuration (Make It Sharp) @@ -330,12 +329,12 @@ Keep docs close to code. - **Version policy**: Use caret requirements (`^x.y.z`) for all direct dependencies. Avoid `*`, `>=` or tag aliases like `latest`. Use tilde (`~x.y.z`) only with a documented justification. -- **Lockfile**: Commit `bun.lock`. Recreate on major tool upgrades; keep +- **Lockfile**: Commit `bun.lock`. Recreate on major tool upgrades; keep `bun.lockb` ignored. - **Audit**: Run `bun run audit` locally and in automation. Track exceptions with explicit expiry dates. - **Culling**: Prefer small, actively maintained packages. Remove unmaintained - or risky dependencies swiftly. +or risky dependencies swiftly. ### Linting & Formatting @@ -434,8 +433,8 @@ Keep docs close to code. ### Quick Checklist (Before Commit) -- `bun run fmt`, `bun run lint`, `bun test` all clean; no Biome warnings; - no TypeScript errors; coverage thresholds hold. +- `bun run fmt`, `bun run lint`, `bun test` all clean; no Biome warnings; no + TypeScript errors; coverage thresholds hold. - `bun run audit` passes or has justified, time‑boxed exceptions. - No `any`, no `@ts-ignore`; use `@ts-expect-error` only with a reason. - All async APIs accept `AbortSignal` where relevant; all fetchers validated diff --git a/frontend-pwa/src/api/client.ts b/frontend-pwa/src/api/client.ts index 4c496780c..dde15a4f2 100644 --- a/frontend-pwa/src/api/client.ts +++ b/frontend-pwa/src/api/client.ts @@ -1,15 +1,11 @@ /** * @file API client functions generated from OpenAPI. */ -import { z } from 'zod'; -import { customFetchParsed } from './fetcher'; +import { customFetch } from './fetcher'; -const userSchema = z.object({ - id: z.string(), - display_name: z.string(), -}); -export type User = z.infer; -const usersSchema = z.array(userSchema); +export interface User { + id: string; + display_name: string; +} -export const listUsers = ({ signal }: { signal?: AbortSignal } = {}) => - customFetchParsed('/api/users', usersSchema, { signal }); +export const listUsers = () => customFetch('/api/users'); diff --git a/frontend-pwa/src/app/App.tsx b/frontend-pwa/src/app/App.tsx index 06d71d97e..92d5515af 100644 --- a/frontend-pwa/src/app/App.tsx +++ b/frontend-pwa/src/app/App.tsx @@ -13,25 +13,17 @@ export function App() { if (isLoading) { return ( -

+

Loading users… -

+
); } if (isError) { - if (import.meta.env.DEV) { - // eslint-disable-next-line no-console - console.error({ msg: 'Failed to load users', error }); - } return ( -

- Failed to load users. Please try again. -

+
+ Failed to load users: {(error as Error).message} +
); } @@ -43,17 +35,11 @@ export function App() {
    - {data && data.length > 0 ? ( - data.map(u => ( -
  • - {u.display_name} -
  • - )) - ) : ( -
  • - No users found. + {(data ?? []).map(u => ( +
  • + {u.display_name}
  • - )} + ))}
); From 09a33c9a6e71aa44772944a4bc06788bae574972 Mon Sep 17 00:00:00 2001 From: Leynos Date: Thu, 14 Aug 2025 20:21:01 +0100 Subject: [PATCH 2/2] Tidy config and improve user list handling (#6) * Tidy config and improve user list handling * Fix tokens build script for style-dictionary v4 * Add index.html and fix token import --- .gitignore | 5 +--- AGENTS.md | 9 ++++--- frontend-pwa/index.html | 13 ++++++++++ frontend-pwa/src/api/client.ts | 16 +++++++----- frontend-pwa/src/app/App.tsx | 30 +++++++++++++++-------- frontend-pwa/src/main.tsx | 2 +- packages/tokens/build/style-dictionary.js | 2 +- 7 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 frontend-pwa/index.html diff --git a/.gitignore b/.gitignore index b94652525..b6d8da22a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,10 +4,7 @@ # Node node_modules/ -/frontend-pwa/node_modules/ -/packages/tokens/node_modules/ -/frontend-pwa/dist/ -/packages/tokens/dist/ +**/dist/ # Misc .DS_Store diff --git a/AGENTS.md b/AGENTS.md index 833cda60b..16bb11485 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -243,7 +243,8 @@ browser‑only runtime. - `test`: `vitest run --coverage` - `audit`: `bun x npm@latest audit` - `audit:snyk`: `bun x snyk test` - + - Note: `audit` requires a committed `bun.lock`; `audit:snyk` requires + installed dependencies—run `bun install` before invoking it. ### Compiler Configuration (Make It Sharp) Use a strict `tsconfig.json` suitable for browser builds: @@ -334,7 +335,7 @@ Keep docs close to code. - **Audit**: Run `bun run audit` locally and in automation. Track exceptions with explicit expiry dates. - **Culling**: Prefer small, actively maintained packages. Remove unmaintained -or risky dependencies swiftly. + or risky dependencies swiftly. ### Linting & Formatting @@ -433,8 +434,8 @@ or risky dependencies swiftly. ### Quick Checklist (Before Commit) -- `bun run fmt`, `bun run lint`, `bun test` all clean; no Biome warnings; no - TypeScript errors; coverage thresholds hold. + - `bun run fmt`, `bun run lint`, `bun run test` all clean; no Biome warnings; + no TypeScript errors; coverage thresholds hold. - `bun run audit` passes or has justified, time‑boxed exceptions. - No `any`, no `@ts-ignore`; use `@ts-expect-error` only with a reason. - All async APIs accept `AbortSignal` where relevant; all fetchers validated diff --git a/frontend-pwa/index.html b/frontend-pwa/index.html new file mode 100644 index 000000000..e6ef728fd --- /dev/null +++ b/frontend-pwa/index.html @@ -0,0 +1,13 @@ + + + + + + + myapp + + +
+ + + diff --git a/frontend-pwa/src/api/client.ts b/frontend-pwa/src/api/client.ts index dde15a4f2..5f44d82a1 100644 --- a/frontend-pwa/src/api/client.ts +++ b/frontend-pwa/src/api/client.ts @@ -1,11 +1,15 @@ /** * @file API client functions generated from OpenAPI. */ -import { customFetch } from './fetcher'; +import { z } from 'zod'; +import { customFetchParsed } from './fetcher'; -export interface User { - id: string; - display_name: string; -} +const userSchema = z.object({ + id: z.string(), + display_name: z.string(), +}); -export const listUsers = () => customFetch('/api/users'); +export type User = z.infer; + +export const listUsers = (signal?: AbortSignal) => + customFetchParsed('/api/users', z.array(userSchema), { signal }); diff --git a/frontend-pwa/src/app/App.tsx b/frontend-pwa/src/app/App.tsx index 92d5515af..e5e65ca9e 100644 --- a/frontend-pwa/src/app/App.tsx +++ b/frontend-pwa/src/app/App.tsx @@ -7,23 +7,27 @@ import { listUsers } from '../api/client'; export function App() { const { data, isLoading, isError, error } = useQuery({ queryKey: ['users'], - queryFn: listUsers, + queryFn: ({ signal }) => listUsers(signal), staleTime: 60_000, }); if (isLoading) { return ( -
+ Loading users… -
+ ); } if (isError) { + if (import.meta.env.DEV) { + // eslint-disable-next-line no-console + console.error(error); + } return ( -
- Failed to load users: {(error as Error).message} -
+

+ Failed to load users. +

); } @@ -35,11 +39,17 @@ export function App() {
    - {(data ?? []).map(u => ( -
  • - {u.display_name} + {data && data.length > 0 ? ( + data.map(u => ( +
  • + {u.display_name} +
  • + )) + ) : ( +
  • + No users found.
  • - ))} + )}
); diff --git a/frontend-pwa/src/main.tsx b/frontend-pwa/src/main.tsx index deef95ff7..d77bee0b2 100644 --- a/frontend-pwa/src/main.tsx +++ b/frontend-pwa/src/main.tsx @@ -4,7 +4,7 @@ import React from 'react'; import { createRoot } from 'react-dom/client'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; -import '@app/tokens/dist/css/variables.css'; +import '@app/tokens/css/variables.css'; import './index.css'; import { App } from './app/App'; diff --git a/packages/tokens/build/style-dictionary.js b/packages/tokens/build/style-dictionary.js index 0ecac8d0a..215df4a75 100644 --- a/packages/tokens/build/style-dictionary.js +++ b/packages/tokens/build/style-dictionary.js @@ -1,7 +1,7 @@ import StyleDictionary from 'style-dictionary'; import fs from 'node:fs'; -const sd = StyleDictionary.extend({ +const sd = new StyleDictionary({ source: ['src/tokens.json', 'src/themes/*.json'], platforms: { css: {