Modernize build and preview commands - #798
Merged
Merged
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Refactors
src/doc_builder/commands/build.pyandpreview.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 inbuild.pyand are reused bypreview.py.Fixes along the way
node_modulesno longer copied to the temp build dir —npm cideletes and recreates it anyway; locally this was ~0.5 GB of wasted copying per build (.svelte-kit/buildartifacts are skipped too, so stale local artifacts can't leak into builds).p.rmdir if p.is_dir() else p.unlink()never calledrmdir(missing parens), so reserved__-named directories like__pycache__were never cleaned before the dev build — only files were.node/npmare resolved viashutil.which(), which replaces preview'sshell=True-on-Windows workaround and makesbuild --html(which had no workaround) work on Windows.--htmlwhen raised frompreview.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 contentwrite_markdown_route_filealready returns; consistentpathlibusage.Verification
llms.txt, markdown route files,_toctree.yml,objects.inv..mdtriggers the watchdog rebuild and the change appears in the served page.ruff check/ruff format --checkclean;pytestpassing.🤖 Generated with Claude Code