Files
apf_portal/docs/.vitepress/config.mts
T
Julien Gautier 003dc35f71
CI / scan (pull_request) Successful in 2m58s
CI / commits (pull_request) Successful in 2m58s
CI / check (pull_request) Successful in 4m56s
CI / a11y (pull_request) Successful in 2m17s
Docs site / build (pull_request) Successful in 2m7s
CI / perf (pull_request) Successful in 5m54s
fix(docs): cap vite below 7 (rolldown-vite) and pin mermaid transitives
`pnpm docs:dev` failed with two distinct symptoms after #159 forced
vite past its vulnerable 5.x line:

1. VitePress refused to boot with `VitePress v1 is not compatible
   with rolldown-vite. Use VitePress v2 instead.` The previous
   override `vite@<6.4.2 → >=6.4.2` had no upper bound; pnpm
   resolved vitepress's `vite ^5.0.0` constraint up to vite 7.3.2,
   which uses the new rolldown bundler and is explicitly rejected
   by VitePress 1.x.

2. Even when the server eventually booted on a different port, the
   console was flooded with `Failed to resolve dependency: dayjs,
   debug, @braintree/sanitize-url, cytoscape, cytoscape-cose-bilkent`
   — the vitepress-plugin-mermaid wrapper injects those into
   `optimizeDeps.include` but they aren't reachable from the
   workspace root under pnpm's strict isolation (transitives of
   mermaid, never hoisted).

Three changes:

* `pnpm.overrides.vite` is now an **unconditional** `>=6.4.2 <7`
  range (not the previous `<6.4.2 → >=6.4.2` selector). The
  selector form was a no-op once vite had already resolved into
  7.x; the unconditional form forces a downgrade to 6.4.2 across
  every consumer (vitepress, @nx/vite, @analogjs, Vitest). All
  six top-level projects still lint, test, and build.

* `optimizeDeps.include` simplified to `['mermaid']`. Vite 6's
  dep optimizer walks Mermaid's transitives automatically once
  Mermaid itself is included, so the explicit list of children
  the previous fix carried (#157) becomes redundant.

* `dayjs`, `debug`, `@braintree/sanitize-url`, `cytoscape`,
  `cytoscape-cose-bilkent` are pinned as **top-level devDeps**.
  The vitepress-plugin-mermaid wrapper expects them at the
  workspace root; under pnpm's strict isolation a transitive of
  mermaid isn't reachable from a `optimizeDeps.include` lookup
  unless the workspace declares it. Pinning silences the
  resolution warnings without changing the resolved tree (these
  packages were already present via mermaid).

Verification: `pnpm docs:dev` boots clean on :5173, home + ADR
pages return 200, no warnings. `pnpm docs:build` succeeds in ~9 s.
`pnpm audit --audit-level=moderate` reports zero vulnerabilities.
`pnpm exec nx run-many -t lint test build` for the 6 main projects
all pass.
2026-05-15 23:52:33 +02:00

181 lines
6.2 KiB
TypeScript

import { readdirSync } from 'node:fs';
import { join } from 'node:path';
import { defineConfig } from 'vitepress';
import { withMermaid } from 'vitepress-plugin-mermaid';
/**
* VitePress configuration for the APF Portal documentation site
* per ADR-0022.
*
* Source tree maps directly to URLs:
* docs/index.md → /
* docs/development.md → /development
* docs/architecture.md → /architecture
* docs/decisions/README.md → /decisions/
* docs/decisions/00NN-…md → /decisions/00NN-… (auto-listed sidebar)
* docs/setup/0N-…md → /setup/0N-…
*
* `docs/README.md` stays as the git-side / IDE-preview index and is
* therefore excluded from the published site; `decisions/template.md`
* is an authoring scaffold, also excluded.
*/
const DECISIONS_DIR = join(__dirname, '..', 'decisions');
const ADR_FILE_RE = /^\d{4}-[\w-]+\.md$/;
/**
* Walks `docs/decisions/` and returns one sidebar entry per accepted
* ADR (`NNNN-kebab-title.md`), ordered by numeric prefix. Adding a
* new ADR is then a single-file change — no `config.ts` edit
* required (the convention spelled out in ADR-0022 §"Sidebar
* generation").
*
* The link text drops the numeric prefix's leading zeroes to read
* naturally ("ADR-0009 — …") while the underlying URL keeps the
* full filename for stable routing across renames.
*/
function adrSidebarItems(): { text: string; link: string }[] {
return readdirSync(DECISIONS_DIR)
.filter((name) => ADR_FILE_RE.test(name))
.sort()
.map((name) => {
const slug = name.replace(/\.md$/, '');
const num = slug.slice(0, 4);
const title = slug.slice(5).replace(/-/g, ' ');
return {
text: `ADR-${num}${title}`,
link: `/decisions/${slug}`,
};
});
}
export default withMermaid(
defineConfig({
title: 'APF Portal Documentation',
description:
"Architecture decisions, development guide, and onboarding material for APF France Handicap's web portal.",
// Root files (`README.md`) and authoring artefacts (`template.md`)
// never make it to the rendered site — see ADR-0022.
srcExclude: ['README.md', 'decisions/template.md'],
// The curated decisions index lives in `decisions/README.md`
// (git/IDE convention). VitePress expects `index.md` at a
// folder root for clean URLs, so we rewrite at build time —
// source layout stays git-friendly, the published URL resolves
// `/decisions/` to the curated landing.
rewrites: {
'decisions/README.md': 'decisions/index.md',
},
// ADRs and the development guide carry deliberate references to
// files that live OUTSIDE `docs/` (CLAUDE.md, apps/**, infra/**,
// notes/**), localhost URLs that only resolve in a dev session,
// and the authoring `template.md` we explicitly excluded. All of
// those are valid from a git/IDE reader's perspective; VitePress
// is told to skip them rather than fail the build.
ignoreDeadLinks: [
/^https?:\/\/localhost/,
/^\.{1,2}\//,
/\/template$/,
/\/README$/,
],
// VitePress emits `.html` files by default; clean URLs hide the
// extension. Mirrors what readers will see in the browser address
// bar and what the inline ADR refs in `portal-admin` already use
// when they target Gitea source-view (forward-compatible the day
// we flip those refs to point at the docs site).
cleanUrls: true,
// The site is internal + read-only; we let crawlers in by
// default but won't ship a sitemap until the hostname is locked
// by the future infra ADR.
lastUpdated: true,
themeConfig: {
nav: [
{ text: 'Development', link: '/development' },
{ text: 'Architecture', link: '/architecture' },
{ text: 'Decisions', link: '/decisions/' },
{ text: 'Onboarding', link: '/setup/01-wsl-terminal-setup' },
],
sidebar: {
'/development': [
{
text: 'Daily development',
items: [{ text: 'Repo layout & commands', link: '/development' }],
},
],
'/architecture': [
{
text: 'Architecture',
items: [{ text: 'C4 + module boundaries', link: '/architecture' }],
},
],
'/decisions/': [
{
text: 'Decisions',
items: [
{ text: 'Index by theme', link: '/decisions/' },
...adrSidebarItems(),
],
},
],
'/setup/': [
{
text: 'Onboarding',
items: [
{ text: 'WSL terminal setup', link: '/setup/01-wsl-terminal-setup' },
{ text: 'Dev web stack', link: '/setup/02-dev-web-stack' },
{ text: 'Angular + Nx monorepo', link: '/setup/03-angular-nx-monorepo' },
],
},
],
},
socialLinks: [
{ icon: 'git', link: 'https://git.unespace.com/julien/apf_portal' },
],
search: {
provider: 'local',
},
outline: {
level: [2, 3],
},
footer: {
message: 'APF Portal — internal documentation',
},
},
// `vitepress-plugin-mermaid` passes its `mermaid` key through to
// the Mermaid runtime. Theme `default` follows VitePress's
// light/dark switcher automatically; explicit `securityLevel`
// tightens the renderer so diagrams can't inject arbitrary HTML
// from the source markdown.
mermaid: {
securityLevel: 'strict',
},
// Pre-bundle Mermaid through Vite's dep optimizer. When this was
// first added (#157) Vite 5's dev server resolved Mermaid's CJS
// transitives (`dayjs`, `cytoscape`, `debug`, `@braintree/sanitize-url`)
// eagerly as ESM and the browser threw `does not provide an export
// named 'default'` on the first navigation. With Vite 6 — to which
// we're now pinned per ADR-0022's "stable, recognized" bar (#160
// capped vite below 7 because VitePress 1.x rejects the new
// rolldown-vite) — the pre-bundler walks Mermaid's transitives
// automatically once Mermaid itself is in `include`, so the
// explicit list of children has been collapsed.
vite: {
optimizeDeps: {
include: ['mermaid'],
},
},
}),
);