# misc/buildinfo (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/misc/buildinfo/

Build info.

## BuildInfo extends Object

Build info.
- Reads the version written by the release build once when the app starts. Read order:
  1. The content of <meta name="build-version" content="..."> in the page head. (If present, that text as is)
  2. If absent, fetches version.json without cache (cache: "no-cache"). So the old version display does not linger after a new version is uploaded.
     Format { version, date, time, hash, ... }, and the text is "date time (hash)". If there is no hash, version, and if that is also missing, empty text.
- If it cannot be read (such as a development run without the file), it is empty text without throwing. If a version was set with setPackageVersion, it is that text.
- If each game writes the version differently, the game composes the value received from readVersionData().

Example: Read the version text

```js
import { BuildInfo } from "./build/vanilla.js";

const buildInfo = new BuildInfo();
buildInfo.setVersionJsonPath("");
buildInfo.setPackageVersion("1.2.3");
const versionText = await buildInfo.load();
const composedText = BuildInfo.composeText({ version: "1.2.3", date: "2026-11-26", time: "07:30", hash: "a1b2c3d" });
console.log(versionText, buildInfo.isLoaded(), composedText);
```

- `constructor(versionJsonPath = DEFAULT_VERSION_JSON_PATH)` (constructor, since 0.4.0): Constructor.
  - `versionJsonPath` string: Build version file URL. (default "./version.json")
- `setMetaName(metaName)` (method, since 0.4.0): Sets the meta name. (default "build-version")
  - `metaName` string: name of the meta that holds the version.
- `setVersionJsonPath(versionJsonPath)` (method, since 0.4.0): Sets the build version file URL. (Does not fetch the file if empty text)
  - `versionJsonPath` string: URL of the build version file. (not fetched if empty)
- `async load()` (method, since 0.4.0): Reads. (meta, or version.json if absent. Does not throw on failure)
  - returns Promise<string>: Version text. (Same as readText)
- `readMetaText()` (method, since 0.4.0): Version written in the page's meta. (Empty text if absent)
  - returns string: The meta content with surrounding spaces trimmed. Empty if missing.
- `setPackageVersion(packageVersion)` (method, since 0.4.0): Sets the version embedded at build time. (Text used when there is neither meta nor version.json, such as a version injected by a bundler)
  - `packageVersion` string: Version text set at build time.
- `getPackageVersion()` (method, since 0.4.0): Returns the version embedded at build time.
  - returns string: Version text set at build time. (empty at first)
- `readText()` (method, since 0.4.0): Version text. (meta > version.json > version embedded at build time, empty text if none)
  - returns string: The version text. Empty if none is available.
- `readVersionData()` (method, since 0.4.0): Value read from version.json. (null if read from meta or could not be read)
  - returns object | null: The values from version.json. null if none.
- `isLoaded()` (method, since 0.4.0): Whether reading has finished. (Finished even on failure)
  - returns boolean: True if load has finished.
- `static composeText(versionData)` (static, since 0.4.0): Builds the version text from a version.json value. (Static, "date time (hash)", version if there is no hash, empty text if that is also missing)
  - `versionData` object: { version, date, time, hash }
  - returns string: The version text.
