Skip to content

Move gen-favicons into theme/, make it publishable as @docsy/theme - #2684

Merged
chalin merged 18 commits into
docsy:mainfrom
chalin:chalin-m24-npm-theme-pkg-2026-0719
Jul 20, 2026
Merged

chalin merged 18 commits into
docsy:mainfrom
chalin:chalin-m24-npm-theme-pkg-2026-0719

Conversation

@chalin

@chalin chalin commented Jul 19, 2026 •

Copy link
Copy Markdown
Collaborator
  • Contributes to Publish theme to the npm registry as @docsy/theme #2683.
  • Preview(s): Generate favicons
  • Takes two steps toward publishing the theme to the npm registry; no publish happens in this PR (that's a tag-time step).
  • Moves gen-favicons into theme/scripts/ so the helper ships with the theme subtree. Bonus fix: the helper was unavailable to Hugo-module installs (the module root is theme/), and the docs pointed at the wrong module path — docs now use DOCSY_THEME_DIR with per-install-type definitions.
  • Makes theme/ publishable as @docsy/theme: package metadata, files allowlist (the git channel's file set minus npm-only exclusions), bin for gen-favicons, and a lean npm-facing README.md. The tarball LICENSE is materialized from the root LICENSE at pack time (prepack/postpack); the root tarball excludes any stranded copy, so both tarballs are disk-state-independent.
  • Guards the contracts in tests: tarball contract test parameterized over both packages; manifest versions kept in sync by set-package-version; test:tooling lists test files explicitly so a missing file is a hard error.
  • Covers the consumer path (test:smoke): packs theme/, installs the tarball into a scratch site outside the repo, builds, and runs the bin via npx --no-install; a registry-install variant stays skipped until a stable version is live under latest.
  • Verification: test:tooling 53 tests, 52 pass, 1 pre-existing skip; npm run check green; test:fixture-site 37/37.

chalin added 15 commits July 19, 2026 08:35
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.
@chalin

chalin commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

Post-review refinement in 0cbec59: the committed theme/LICENSE (and its byte-equality guard) is replaced by pack-time materialization — prepack copies the root LICENSE in, postpack removes it. Analysis showed the copy serves only the registry tarball: git-channel installs always carry the root LICENSE (npm's always-include list), and Hugo modules get it via the Go toolchain's nested-module injection. The pack contract's required LICENSE entry now doubles as the materialization guard, so drift is impossible by construction rather than merely detected (prior art: Angular/MUI/Nx). Tooling 51/52 green; the tarball consumer smoke test exercises the new lifecycle end to end.

chalin added 3 commits July 20, 2026 10:12
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.
@chalin
chalin merged commit 79448e2 into docsy:main Jul 20, 2026
16 checks passed
@chalin
chalin deleted the chalin-m24-npm-theme-pkg-2026-0719 branch July 20, 2026 16:29
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