@sirenodeck/sirenodeck 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ import { runtimeIdentity } from "./runtime-identity"
2
+ import { z } from "zod"
3
+
4
+ export type RendererState =
5
+ | "starting"
6
+ | "healthy"
7
+ | "recovering"
8
+ | "failed"
9
+ | "not-applicable"
10
+ export interface RuntimeHealth {
11
+ identity: { version: string; buildId: string | null }
12
+ core: "starting" | "ready" | "stopping"
13
+ renderer: { state: RendererState; lastFrameAt: number | null }
14
+ }
15
+
16
+ export const runtimeHealthSchema = z
17
+ .object({
18
+ identity: z
19
+ .object({ version: z.string(), buildId: z.string().nullable() })
20
+ .strict(),
21
+ core: z.enum(["starting", "ready", "stopping"]),
22
+ renderer: z
23
+ .object({
24
+ state: z.enum([
25
+ "starting",
26
+ "healthy",
27
+ "recovering",
28
+ "failed",
29
+ "not-applicable",
30
+ ]),
31
+ lastFrameAt: z.number().finite().nullable(),
32
+ })
33
+ .strict(),
34
+ })
35
+ .strict()
36
+
37
+ const health: RuntimeHealth = {
38
+ identity: runtimeIdentity,
39
+ core: "starting",
40
+ renderer: { state: "starting", lastFrameAt: null },
41
+ }
42
+
43
+ export const runtimeHealth = {
44
+ snapshot: (): RuntimeHealth => ({
45
+ ...health,
46
+ renderer: { ...health.renderer },
47
+ }),
48
+ setCore: (state: RuntimeHealth["core"]): void => {
49
+ health.core = state
50
+ },
51
+ setRenderer: (
52
+ state: RendererState,
53
+ lastFrameAt = health.renderer.lastFrameAt,
54
+ ): void => {
55
+ health.renderer = { state, lastFrameAt }
56
+ },
57
+ }
@@ -0,0 +1,25 @@
1
+ import { dirname, resolve } from "node:path"
2
+ import { fileURLToPath } from "node:url"
3
+ import { VERSION } from "../version"
4
+ import { fingerprintBuildInputs } from "./build-fingerprint"
5
+
6
+ declare const __SIRENO_BUILD_ID__: string | undefined
7
+
8
+ const development = process.env.SIRENO_DEV_MODE === "true"
9
+ let buildId: string | null = null
10
+ if (typeof __SIRENO_BUILD_ID__ !== "undefined") {
11
+ buildId = __SIRENO_BUILD_ID__
12
+ } else if (development) {
13
+ try {
14
+ buildId = fingerprintBuildInputs(
15
+ resolve(dirname(fileURLToPath(import.meta.url)), "../.."),
16
+ )
17
+ } catch {
18
+ // A missing source tree cannot establish a build identity.
19
+ }
20
+ }
21
+
22
+ export const runtimeIdentity = {
23
+ version: `${VERSION}${development ? "-dev" : ""}`,
24
+ buildId,
25
+ } as const
@@ -0,0 +1,48 @@
1
+ import type { Plugin } from "vite"
2
+ import { fingerprintBuildInputs } from "../util/build-fingerprint"
3
+ import packageJson from "../../package.json" with { type: "json" }
4
+
5
+ export const componentIdentity = (
6
+ root: string,
7
+ component: "frontend" | "config-ui",
8
+ ): Plugin => {
9
+ let buildId: string | null = null
10
+ try {
11
+ buildId = fingerprintBuildInputs(root)
12
+ } catch {
13
+ /* unavailable source */
14
+ }
15
+ const version = `${packageJson.version}${process.env.SIRENO_DEV_MODE === "true" ? "-dev" : ""}`
16
+ const identity = JSON.stringify({ component, version, buildId })
17
+ return {
18
+ name: "sireno-component-identity",
19
+ configureServer(server) {
20
+ server.middlewares.use("/assets/sirenodeck-build.json", (_req, res) => {
21
+ res.setHeader("Content-Type", "application/json")
22
+ res.setHeader("Cache-Control", "no-store")
23
+ // HMR can change browser code without restarting the server. Do not
24
+ // claim the startup fingerprint still identifies the running bundle.
25
+ let current: string | null = null
26
+ try {
27
+ current = fingerprintBuildInputs(root)
28
+ } catch {
29
+ /* unavailable source */
30
+ }
31
+ res.end(
32
+ JSON.stringify({
33
+ component,
34
+ version,
35
+ buildId: current === buildId ? buildId : null,
36
+ }),
37
+ )
38
+ })
39
+ },
40
+ generateBundle() {
41
+ this.emitFile({
42
+ type: "asset",
43
+ fileName: "assets/sirenodeck-build.json",
44
+ source: identity,
45
+ })
46
+ },
47
+ }
48
+ }