Skip to content

Modernize build and preview commands - #798

Merged
mishig25 merged 1 commit into
mainfrom
modernize-build-preview-commands
Jul 5, 2026
Merged

Modernize build and preview commands#798
mishig25 merged 1 commit into
mainfrom
modernize-build-preview-commands

Conversation

@mishig25

@mishig25 mishig25 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

What

Refactors src/doc_builder/commands/build.py and preview.py — no CLI surface changes.

Shared helpers (was ~80 duplicated lines per command)

stage_kit_routes() (copy kit + inject routes + sveltify mdx paths), docs_node_env(), run_npm(), resolve_npm_sibling() now live in build.py and are reused by preview.py.

Fixes along the way

  • node_modules no longer copied to the temp build dirnpm ci deletes and recreates it anyway; locally this was ~0.5 GB of wasted copying per build (.svelte-kit/build artifacts are skipped too, so stale local artifacts can't leak into builds).
  • preview bug: p.rmdir if p.is_dir() else p.unlink() never called rmdir (missing parens), so reserved __-named directories like __pycache__ were never cleaned before the dev build — only files were.
  • Windows: node/npm are resolved via shutil.which(), which replaces preview's shell=True-on-Windows workaround and makes build --html (which had no workaround) work on Windows.
  • Node floor raised to v20 (Vite 7 requirement — the old check accepted v14, which then failed deep inside the vite build) and the error message no longer talks about --html when raised from preview.
  • Dev-server thread is a daemon, so Ctrl-C on the watcher exits the process cleanly.
  • env["package_name"] or x if cond else x (works only via conditional-expression precedence) → env.get("package_name") or x; build no longer re-reads markdown files whose content write_markdown_route_file already returns; consistent pathlib usage.

Verification

  • Byte-identical accelerate e2e (same as the CI workflow): 48/48 HTML pages byte-identical to a pre-change build (normalizing only hashed asset names), identical file inventories, and byte-identical llms.txt, markdown route files, _toctree.yml, objects.inv.
  • Preview smoke-tested end-to-end: dev server builds and serves pages; editing a source .md triggers the watchdog rebuild and the change appears in the served page.
  • ruff check / ruff format --check clean; pytest passing.

🤖 Generated with Claude Code

- extract the duplicated kit-staging logic (~80 lines in each command)
  into shared helpers in build.py: stage_kit_routes(), docs_node_env(),
  run_npm(), resolve_npm_sibling()
- skip node_modules/.svelte-kit/build when copying the kit folder to the
  temp dir: npm ci recreates node_modules anyway (locally this avoided
  copying ~0.5GB per build)
- fix a preview bug: `p.rmdir if p.is_dir() else p.unlink()` never called
  rmdir, so reserved `__`-named directories (e.g. __pycache__) were never
  removed before the dev build
- resolve node/npm via shutil.which: replaces preview's shell=True-on-
  Windows workaround and makes `build --html` work on Windows too
- raise the node version check to >= 20 (vite 7 requirement) and make the
  error message command-agnostic (preview reused it with a message about
  the --html flag)
- run the dev-server thread as a daemon so Ctrl-C exits cleanly
- replace `env["package_name"] or x if cond else x` precedence puzzle
  with env.get(); drop the markdown re-read in build (the content is
  already returned by write_markdown_route_file); pathlib throughout

Verified: byte-identical accelerate e2e output (48/48 pages + identical
file inventory, llms.txt, markdown routes, objects.inv); preview smoke
tested end-to-end (dev server serves pages, watchdog rebuild reflects an
edited md file in the served page); ruff and pytest clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mishig25
mishig25 merged commit 41c17d1 into main Jul 5, 2026
4 checks passed
@mishig25
mishig25 deleted the modernize-build-preview-commands branch July 5, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant