Introducing a new way to review your PRs.

Read the announcement

bas3line / ascii

Animated ascii art for web pages, in TypeScript: React, Next.js, Astro, or one HTML tag

View on GitHub

21 documents · Updated Oct 26, 2026

docs / package-build-and-publishing

Package build and publishing

The package build and publishing workflow turns the TypeScript source into the npm package that users install. It keeps public entry points and piece indexes aligned with the source, checks that generated files are current, and publishes only a versioned build from a clean tag.

Package artifact

Package boundary

The package exposes the core library, piece modules, and framework entry points through stable package paths. Its published boundary contains compiled files in dist and the Astro components in src/astro; the exports map tells consumers which entry point and type declarations to use.

The package treats React as an optional peer dependency. This lets users consume the core, terminal, SVG, or web component paths without requiring React while still supporting the React entry point when it is present.

References: package.json• L14-62

Build pipeline

Source compilation

The build converts the library source into JavaScript and declaration files under dist. It excludes Astro source and test files because those are not part of the compiled TypeScript package output.

The build also runs as the package prepare step. A local install or a clean package install therefore creates the compiled artifact before later checks or publishing use it.

References: package.json• L63-74 tsconfig.build.json• L1-15

Build flow

The package moves from source and generated indexes to a compiled artifact, then through checks before it can reach npm.

flowchart LR
    A[TypeScript source] --> B[npm run gen]
    B --> C[Piece indexes]
    A --> D[npm run build]
    C --> D
    D --> E[dist and package files]
    E --> F[Checks]
    F --> G[npm publish]

The build is not the release decision by itself. The release workflow repeats the clean install, check, and build steps so the published artifact is produced from the tagged commit rather than from a developer's local files.

References: package.json• L62-74 .github/…/release.yml• L16-38

Generated indexes

Piece index generation

The generation step turns the files in src/pieces into two public views of the piece library. One supports named static exports, and the other supports loading a piece by its file name when needed.

The generated data also records which pieces use a canvas. This keeps the piece list and its rendering class in step with the source directory. When a piece is added or renamed, npm run gen is the required source-to-index update; the generated files are not hand-edited.

References: scripts/gen.ts• L1-3 scripts/gen.ts• L8-45 src/…/index.ts• L1-5 src/library.ts• L1-6

Generated state check

Continuous integration runs generation and then checks that the two generated files have no diff. This catches a missing index update before the package can be merged, while the build then confirms that the source and generated exports compile together.

References: .github/…/ci.yml• L17-24 scripts/gen.ts• L24-45

Comparison workflow

Frame comparison

The comparison workflow protects the visible output of a piece during a refactor. It loads the current piece beside a reference version, compares metadata, and checks frames on both dark and light backgrounds for up to eight seconds.

This check is separate from the normal package build. Use it when the code should change without changing the picture; a difference causes the command to fail. Pieces that read the real clock are skipped because their frames depend on when they run.

References: scripts/compare.ts• L1-5 scripts/compare.ts• L19-30 scripts/compare.ts• L33-56 CONTRIBUTING.md• L124-131

Publishing workflow

Versioned release

Publishing starts when a tag with the v prefix is pushed. The tag must match the version in package.json, so the source version and the npm version cannot silently diverge.

The normal release path updates package.json and package-lock.json in a pull request, merges that change to main, and then tags the merged commit. A tag with the wrong version stops before publication.

References: .github/…/release.yml• L1-14 .github/…/release.yml• L27-33 CONTRIBUTING.md• L134-146

Trusted publication

The release job uses Node 24 and a clean npm ci install. That install runs the prepare build, after which the job runs the package check and build again before npm publish sends the result to npm.

Publication uses npm trusted publishing. GitHub Actions provides the identity and npm adds provenance, so the repository does not store an npm token. The npm package must be configured once with the matching repository and workflow identity before this path can succeed.

References: .github/…/release.yml• L3-7 .github/…/release.yml• L16-38 CONTRIBUTING.md• L148

The package workflow depends on validation and release checks that run around the build. See Quality and release automation for the wider validation gates and automation context.

References: .github/…/ci.yml• L8-24 .github/…/release.yml• L16-38

Change checklist

When these files or sections are changed, remember to consider these:

  • When changing package.json exports or published files, check that each public path still has its matching JavaScript and declaration output.
  • When adding or renaming a piece, run generation and include both generated indexes so static exports and on-demand loading agree.
  • When changing build inclusion or exclusion rules, check the package contents and the framework entry points that bypass the TypeScript output.
  • When changing the release tag or workflow identity, keep the package version, tag name, npm trusted publisher, and workflow file aligned.
  • When changing a piece without intending a visual change, compare it with a saved reference in both ink and paper modes.

Important failure modes

TriggerConsequenceGuard
A release tag does not match package.jsonThe workflow stops before npm publication.The release job compares GITHUB_REF_NAME with the package version.
A new or renamed piece is not generatedStatic exports or on-demand loading do not include the piece.CI runs npm run gen and fails on a diff in the generated indexes.
The package is built from stale or local outputThe published artifact can differ from the tagged source.The release job uses npm ci, then runs the check and build before publishing.
A refactor changes a frame or metadata valueThe visible piece changes even when the change was meant to be internal.scripts/compare.ts compares metadata and frames on dark and light backgrounds.
The npm trusted publisher settings do not match the workflownpm rejects the publish even though the build passes.Configure the npm publisher with the exact repository user, repository, and workflow name.

Key files

FileWhy to read it
package.jsonDefines the package boundary, public entry points, build commands, and release version.
tsconfig.build.jsonDefines which source becomes the shipped JavaScript and type output.
scripts/gen.tsDefines how piece files become the static and on-demand indexes.
scripts/compare.tsDefines the visual parity check for refactors.
.github/…/ci.ymlShows the merge-time generation and package validation gates.
.github/…/release.ymlShows the tag-triggered clean build and trusted npm publication path.
CONTRIBUTING.mdDescribes the contributor-facing version, comparison, and release sequence.