Repository navigation
Move gen-favicons into theme/, make it publishable as @docsy/theme - #2684
Merged
Merged
Conversation
Relocate the gen-favicons helper (CLI, lib, README, tests) from scripts/ to theme/scripts/ so that it ships with the theme subtree, in preparation for publishing theme/ as the @docsy/theme npm package. This also fixes gen-favicons availability for Hugo-module installs: the Hugo module is github.com/google/docsy/theme (go.mod lives in theme/), so the helper was previously outside the module tree entirely — and the docs pointed at the wrong module path (github.com/google/docsy). Docs now use DOCSY_THEME_DIR with per-install-type definitions. Wiring updates: - bin and files: theme-relative paths; a !theme/scripts/**/*.test.mjs negation keeps test files out of the tarball (contract-tested). - test:tooling: explicit test-file paths instead of a scripts/** glob. The move demonstrated the glob hazard: the 9 relocated tests silently dropped out of the run (45 -> 36) with exit 0 from the runner. Explicit paths make a missing file a hard error. - npm-pack.test.mjs: contract now requires the helper under theme/scripts/, forbids any .test.mjs in the tarball, and mirrors the files allowlist literally.
Turn the theme workspace into a publishable npm package: - theme/package.json: name @docsy/theme, drop private, add publishConfig.access public, repository directory, keywords, bin (gen-favicons), and a files allowlist covering the theme files that the git channel ships (assets, i18n, images, layouts, static, go.mod, hugo.yaml, theme.toml) plus the gen-favicons helper (tests excluded by the allowlist). - theme/README.md: lean npm-facing page -- install + theme config, with docsy.dev owning the rest. - theme/LICENSE: copy of the repo Apache-2.0 license so the published package carries it. - npm-pack.test.mjs: parameterize the tarball contract over both packages (root GitHub-NPM and @docsy/theme); the theme contract requires LICENSE/README/theme files/helper, forbids node_modules, package-lock.json, and test files, and asserts the manifest (name, publishable, access, files, bin). Verified end to end: npm pack in theme/, install of the tarball in a scratch consumer, bootstrap + fontawesome hoisted transitively, and npx gen-favicons --help works from the scoped install. No publish happens here; that is a tag-time step.
The old test:tooling glob ('scripts/**/*.test.mjs') was single-quoted, so
cmd.exe passed it through literally and it matched nothing: the tooling
tests never ran on Windows (0 tests, exit 0 — silent false-green). The
switch to explicit file paths makes Windows run them for the first time,
exposing two portability bugs:
- npm-pack.test.mjs: spawnSync('npm', ...) can't execute npm.cmd without
a shell on Windows; enable shell there. Split tar output on CRLF.
- gen-favicons.test.mjs: split magick identify output on CRLF; the
trailing \r made every frame-size comparison fail.
The Hugo themes registry and Hugo modules ingest the theme via git, never npm, so npm clients have no use for the registry screenshots (theme/images, 664 kB — the bulk of the tarball), theme.toml, or go.mod. Drop images from both tarballs and the two metadata files from @docsy/theme; the root GitHub-NPM tarball keeps them as a plain mirror of the git tree. Package size drops from 841 kB to ~185 kB compressed. Verified: a scratch consumer site builds from the lean theme tarball with output identical to before, and npx gen-favicons still resolves.
The helper README and the Generate-favicons docs section both gave both command forms and both defined DOCSY_THEME_DIR. The docs section (where --help already points) owns the workflow; the README keeps purpose, requirements, and the npx one-liner, and links out for the rest.
- Title the package README with the package name, per npm convention; this also distinguishes it from the project README on GitHub. - Add the technical-documentation keyword, matching the package description.
The Requirements and Usage sections restated facts owned elsewhere: the ImageMagick requirement is enforced by the CLI with an actionable error, and the docs page owns the workflow commands for each install type. Keep the purpose statement -- the only home of why the icons are pre-generated -- and the pointers.
Mirrors the GitHub-sourced NPM smoke test, but installs the theme-only package from the npm registry -- the path consumers take once @docsy/theme is published -- then builds the site and exercises the gen-favicons bin. Written red-first: before the first publish it fails with ENOVERSIONS (the registry reserves the name with no live versions), proving it exercises the registry and not GitHub. Skipped until the first publish.
The release scripts treated the root manifest as the only home of the package version, so theme/package.json kept a stale development version -- violating the publication invariant that the registry version equals the git tag. set-package-version now syncs secondary manifests (theme/package.json, when present) with the root version on every run, covering the case where the root is already at the target but a secondary copy is stale. The pack contract test asserts the two manifests agree, and the theme manifest is re-synced. Review finding (M1) on docsy#2684.
Smoke coverage of the theme package previously existed only as a skipped registry test, so no test exercised the consumer contract of the code under review. The consumer-site setup is now a shared helper driven by two tests: a tarball test that packs theme/ from the current checkout (pre-publish, runs today) and the registry test, which gains a DOCSY_THEME_PKG spec override (e.g. @docsy/theme@next to vet an RC) and stays skipped until a stable version is live under the latest dist-tag. Bin checks assert the node_modules/.bin shim exists and invoke it with npx --no-install: a bare npx would offer to fetch a same-named package from the public registry when the local bin is missing. The docs and release-post commands use the same guarded form. Review findings (M2, M3) on docsy#2684.
theme/LICENSE is a copy of the root LICENSE (npm pack does not follow symlinks); a byte-equality test now keeps the copies from drifting. Assert messages state the expected condition rather than the failure. Review findings (L) on docsy#2684.
The smoke helpers enabled a shell for npm on Windows (.cmd shims need one) but not for the npx probe; a shared winShell const now covers all three spawn sites. Also: the one remaining negatively phrased pack-contract assert now states the expected condition, and the manifest-sync log line drops its empty old-version slot. Review findings (re-review, all Low) on docsy#2684.
Via set:version:git-info, which now also syncs theme/package.json.
The committed theme/LICENSE served exactly one consumer: the npm registry tarball, which must be self-contained (npm pack cannot reach above the package dir, and skips symlinks). Every other channel is covered by the root LICENSE alone: npm always includes a package-root LICENSE in packs regardless of the files allowlist (so git-channel installs of the root package carry it), and the Go toolchain injects the repo-root LICENSE into nested-module zips for Hugo modules. So keep a single LICENSE in source control and derive the tarball copy: a prepack script copies the root LICENSE into theme/ and postpack removes it (root files includes theme/, overriding the gitignore, so a lingering copy would otherwise leak into the root tarball and make its contents disk-state-dependent). The pack contract's required LICENSE entry now doubles as the guard that materialization ran; the byte-equality drift test retires since drift is impossible by construction. Prior art: Angular, MUI, and Nx materialize license copies into published artifacts rather than committing them. Tooling suite 51/52 (1 registry skip); tarball consumer smoke test packs theme/ and exercises the new lifecycle end to end.
Collaborator
Author
|
Post-review refinement in 0cbec59: the committed |
postpack is not a failure hook: a theme pack that dies after prepack strands the materialized theme/LICENSE on disk, gitignored, and the root files allowlist would sweep it into the next root tarball, making that tarball depend on prior local disk state. Exclude theme/LICENSE from the root files allowlist so the root tarball is disk-state-independent by construction, forbid it in the root pack contract, and assert that a successful theme pack leaves no residue. Red-first: seeded residue tripped the new forbid, and removing postpack tripped the cleanup assert.
4 tasks done
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.
gen-faviconsintotheme/scripts/so the helper ships with the theme subtree. Bonus fix: the helper was unavailable to Hugo-module installs (the module root istheme/), and the docs pointed at the wrong module path — docs now useDOCSY_THEME_DIRwith per-install-type definitions.theme/publishable as@docsy/theme: package metadata,filesallowlist (the git channel's file set minus npm-only exclusions),binforgen-favicons, and a lean npm-facingREADME.md. The tarballLICENSEis materialized from the root LICENSE at pack time (prepack/postpack); the root tarball excludes any stranded copy, so both tarballs are disk-state-independent.set-package-version;test:toolinglists test files explicitly so a missing file is a hard error.test:smoke): packstheme/, installs the tarball into a scratch site outside the repo, builds, and runs the bin vianpx --no-install; a registry-install variant stays skipped until a stable version is live underlatest.test:tooling53 tests, 52 pass, 1 pre-existing skip;npm run checkgreen;test:fixture-site37/37.