Skip to content

refactor: migrate from Astro Starlight to Docusaurus and refactor hosting system#13

Merged
matejstastny merged 18 commits into
mainfrom
refactor/docusaurus
Jul 18, 2026
Merged

refactor: migrate from Astro Starlight to Docusaurus and refactor hosting system#13
matejstastny merged 18 commits into
mainfrom
refactor/docusaurus

Conversation

@matejstastny

Copy link
Copy Markdown
Member

trickfire-docs CLI

  • The CLI was made to remove the need for repos to have a npm project initialized in them, just the docs/ folder and the docs.config.ts config file
  • Runnable via npx using npx trickfire-docs init and npx trickfire-docs dev for testing the pages

Hosted site

  • A self-hosted Docusaurus instance at docs.trickfirerobotics.com serves all member docs under one roof
  • Each member repo's CI calls a reusable sync-docs.yml workflow that rsyncs their docs/ into content/<repo-name>/ on the server and triggers a rebuild
  • This was done to:
    • Unify the documentation pages more
    • Make it possible for the main page to automatically include all documentation subpages
    • Make it possible for this repo to not be named TrickFireRobotics.github.io (done to make the deployment of multiple repos to one domain without changing the org-wide domain possible)
    • Make it possible for the nav in the subdoc pages to include all other subdocs for clarity

Migration from Astro Starlight to Docusaurus

  • The theme looks way better and the page is way easier to read
  • We do not have to write and maintain many lines of typescript to wrap to build Astro Starlight pages from our docs and config file
  • Easier to theme and configure to our liking, rather than the rigid structure and layout of Starlight

Cloudflare tunnel

  • nginx listens on localhost:80 only, with no TLS cert. cloudflared (service: cloudflared-trickfire-docs) opens an outbound tunnel to Cloudflare, which terminates HTTPS and proxies traffic to nginx

@docusaurus/core patch

  • Three fixes required to make Docusaurus work on Node.js 22 with "type":"module" projects:
    • polyfill require.resolveWeak in the SSG eval context
    • write {"type":"commonjs"} next to the server bundle so Node.js doesn't treat webpack CJS chunks as ESM
    • write {} into .docusaurus/ so webpack uses javascript/auto mode for Docusaurus's generated files (which mix export default with require())

Framework docs

  • The framework documents itself at /trickfire-docs/: member guide, architecture overview, configuration reference, content writing guide, and deployment guides for the server, Cloudflare tunnel, and GitHub Actions runner

Three issues prevented Docusaurus 3.10.2 from building on Node.js 22:

1. require.resolveWeak not defined — polyfilled as no-op in ssgNodeRequire
2. Externalized ESM theme files importing @theme/* aliases and .css files fail
   in the SSG eval context — caught and returned as empty modules
3. webpack CJS chunks treated as ESM due to project-level "type":"module" —
   fixed by writing {"type":"commonjs"} into the server output dir before eval
…e tunnel

Adds a full docs/ section for the trickfire-docs framework itself, served
at /trickfire-docs/ on the live site. Covers architecture, member guide,
writing content, sidebar config, configuration reference, and deployment.

Deployment docs describe the Cloudflare tunnel setup instead of direct TLS,
so the nginx config is simplified (localhost:80 only, no certbot needed).
Three root causes fixed:

1. Preset resolution: generated docusaurus.config.js used the bare package
   name "@docusaurus/preset-classic", which Docusaurus resolves via
   createRequire(siteConfigPath) — that require never reaches trickfire-docs's
   node_modules. Fix: resolve the preset to an absolute path at config-
   generation time using createRequire(import.meta.url) inside generate.ts.

2. React/react-dom/@mdx-js symlinks: ensureSiteNodeModules was symlinking into
   .trickfire/node_modules/, but Docusaurus's resolveSitePkg() uses siteDir
   (= cwd) not the config file dir. Symlinks must go in projectRoot/node_modules/.

3. Dangling symlinks: pnpm hoists nothing to node_modules/react — the actual
   path is node_modules/.pnpm/react@x/node_modules/react. Fix: resolve package
   dirs via _require.resolve() rather than constructing guessed paths. Added
   ./package.json-less fallback (walk up from main entry) for packages like
   @mdx-js/react that don't export that subpath.

Also adds scaffold/.npmrc (shamefully-hoist=true) so pnpm member repos hoist
Docusaurus peer deps, and fixes generate.ts to use absolute paths for all
file references so the config works from .trickfire/ as the site root dir.
Raw `Cannot find module` from jiti was confusing. Now shows a clear message
pointing to `trickfire-docs init` (member repos) or `pnpm website:dev` (the
trickfire-docs repo itself).
…auto

When the member repo has "type":"module" in its package.json, webpack treats
all .js files as ESM. Docusaurus's generated client-modules.js and routes.js
use mixed ESM/CJS syntax (export default + require()), which ESM mode rejects.

Extend the @docusaurus/core patch: generateSiteFiles now writes an empty
package.json (no "type" field) into .docusaurus/ before generating any files.
Webpack then uses javascript/auto for files in that directory, which supports
the mixed ESM/CJS pattern Docusaurus has always generated.
Using --config with a named file (trickfire-docs.yml instead of config.yml)
makes cloudflared register the service as cloudflared-trickfire-docs rather
than the generic cloudflared, so multiple tunnels can coexist on the same
server without conflicts.
…vice

The --config flag does not affect the unit name. To get a named service
(cloudflared-trickfire-docs) the unit file must be written manually.
Replace the service install command with a tee + systemd approach.
- docs/deployment/index.md: fill in GitHub Runner TODO section
- deploy.yml: add docs/** and docs-sidebars.js to path triggers so
  changes to the framework's own docs redeploy the site
- CONTRIBUTING.md: remove dead link to README#releasing section
- test-cli.sh: switch npm/npx to pnpm
@matejstastny matejstastny self-assigned this Jul 18, 2026
@matejstastny matejstastny changed the title Migrate from Astro Starlight to Docusaurus and refactor hosting system refactor: migrate from Astro Starlight to Docusaurus and refactor hosting system Jul 18, 2026
@matejstastny
matejstastny merged commit 6fed90a into main Jul 18, 2026
2 checks passed
@trickfirebot

trickfirebot Bot commented Jul 18, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant