/** * A build, from the Studio, handed to content. * * Two callers. A publish JOB's tab builds the job's content and stops once * its artifacts are confirmed (`until: "confirmed"`): content verifies and * seals it, and mints the commit then (valbuild/home, docs/app-mode.md, * "Publishing is a queued job"). An UPDATE builds the live content against a * new dependency layer and takes it live itself. Either way what is here is * the part a managed project has nobody else to do -- read what to build and * what to build it from, build it, and hand the result to content. * * ## Everything it cannot do itself is a parameter * * There are four, and each is something this package must not contain: * * - **`client`** reaches content through this origin's proxy. A browser holds * a session cookie and no project token; the deployment swaps the credential. * - **`loadBuilder`** is the dynamic import, replaceable because nothing that * imports it for real runs under jest — `@rolldown/browser` is ESM-only and * this repository's jest is CommonJS. * - **`generateRouteTree`** is TanStack's generator plus babel, which is 2.6 MB * and is not on npm. See {@link StudioDeployOptions.generateRouteTree}. * - **`commit`** is the commit an update is wired at, which only the caller has. * * So this module is testable without any of them, which is the point: the * sequence is where the mistakes are, and the sequence is what is left. * * ## It does not throw * * Same rule as `runStudioPublish`, and for the same reason: every failure here * means one thing to an editor — nothing is live, and here is why — so a caller * that had to distinguish eight rejections would write eight identical * branches. The `problems` from content survive because they are the only part * a person can act on. */ import type { BuildTarget } from "@valbuild/tanstack-build"; import { PublishProblem } from "../internal/index.js"; import { CarriedArtifact, StudioPublishClient } from "./publishClient.js"; import { PublishPhase } from "./runStudioPublish.js"; import type { StudioBuilder } from "./builder.js"; import { LayerReading } from "./loadedLayer.js"; /** * The binary files a commit wrote, as `/save` answered them. * * `unread` is files the server could not read back before committing. The * build refuses over them: the site would link a file it does not serve. */ export type CommittedBinaryFiles = { files: Record; unread: string[]; }; export type DeployPhase = /** * A publish job waiting its turn: queued behind the one before it. Never * reported by the deploy itself -- it is how the Studio shows a press whose * job has not started (see `publishProgress`). */ { kind: "queued"; } /** Waiting for the bundler. Only ever seen when the preload has not landed. */ | { kind: "getting-ready"; } | { kind: "reading"; } | { kind: "building"; } | PublishPhase; export type StudioDeployResult = { status: "live"; url: string | null; } | { status: "already-live"; url: string | null; } /** A publish job's build, uploaded and confirmed: content does the rest. */ | { status: "uploaded"; publishId: string; } | { status: "failed"; message: string; problems: PublishProblem[]; }; export interface StudioDeployOptions { client: StudioPublishClient; /** * For a publish job's tab: stop once the artifacts are confirmed, and * answer with the publish id. Content runs verify and the seal itself, and * `commit` is `null` -- a job's build is wired at no commit, because its * commit is minted at the seal (valbuild/home, docs/app-mode.md: "A * platform build bakes nothing and asks content"). */ until?: "confirmed"; /** * The commit `/save` just made, or `null` for a publish from no commit. * * The BRANCH is deliberately not here, because the caller has no honest * source for one: `/stat` does not carry it and neither does `/save`, and a * branch the browser invented is a branch content would be asked to record a * build against on the browser's say-so. It is read out of the project's own * `val.server.ts` instead — see {@link branchOf} — which is where the last * build put it and which does not change between publishes. * * The commit is baked in before the build, and that is not bookkeeping: Val * reads content from the content service AT A COMMIT, so a build wired at * the previous one renders and edits a different version of its files than * the code it is running. */ commit: string | null; /** * The publish job this build is for, baked in beside the commit so the * build can say where it sits in the content service's chain -- it has no * commit to say it with (`BUILT_FOR_JOB` in `@valbuild/tanstack-build`). * Left out by a build that is not a job's (an update), which keeps the job * of the source it was made from: an update changes no content. */ job?: string | null; /** * The source files to build, by path, over the project's stored source -- * for a publish job, every file of the job's content, as the server's * `/publish-job-prepare` rendered it -- or `null` when there are none to add * (an update, which changes no content). * * Laid over the stored source before anything else, because the stored * source is what the LAST build was made from: without this the build * publishes the site as it was before the change. `null` values are files * the change deleted. Paths may carry a leading `/` (Val's module paths do) * and are matched without it. */ committedFiles?: Record | null; /** * The binary files that commit wrote -- an image uploaded in this save -- * base64 by path, or `null` when there are none to add. * * Nothing else has them: the stored source is text, and the live build * predates the upload. A file under `public/` is published as one; anything * else goes to the build as an asset, where an import can find it. */ committedBinaryFiles?: CommittedBinaryFiles | null; /** * The branch the commit is on, as the server had it from the content * service, or `null` when it did not say. * * Preferred over the branch baked into the last build's `val.server.ts`, * which is the fallback: a project cloned from a template seed was wired at * no commit and no branch, and a branchless publish is refused by a loader * whose pointer follows one -- which admin configures for every project. */ branch?: string | null; /** * The live site's compiled stylesheet, used when this build produced none. * * A build in the browser cannot run Tailwind `@plugin`s, and the stored * source may not carry the stylesheets at all. A Studio save changes content * and uploaded files, never a stylesheet or a component, so the live CSS is * still the right CSS; without this every Studio publish shipped unstyled. */ liveStylesheet?: () => Promise; /** * One of the live site's public files, base64, by its URL path * (`favicon.ico` for `/favicon.ico`). * * Only asked for when content cannot name the live build's public files by * hash and the loader can name them by path. Absent, that case is refused * like the one where nobody can say. */ fetchPublicFile?: (path: string) => Promise; /** * What to build against, when it is not what the live build was built * against. * * Absent for every publish but one: an update, which moves the project onto * its template's current dependency layer. The live build's target names the * layer it is leaving, so the update's own answer is used instead -- and the * publish then names the layer it carries, which is what moves the site. */ target?: BuildTarget; /** * The dependency layer the live build had when this page loaded (see * `loadedLayer.ts`), or `undefined` when it cannot say. * * A publish whose build target names a different one is refused: the site * was updated since, this Studio is the old version, and building with it * would use the old builder. Not asked of an update, whose whole point is a * different layer. */ loadedLayer?: LayerReading; /** * The live build's layer NOW. Asked once more after the build, just before * the declare: an update that went live while this page was building would * pass the check against the target read at the start, and this publish * would then put the old dependencies back. Absent, only that first check * is made. What closes the remaining window -- declare to promote -- is the * seal in publish-jobs. */ liveLayer?: () => Promise; loadBuilder: () => Promise; /** * Generates `src/routeTree.gen.ts` for a file-based project. * * A capability, like `routeSplitter` and `loadCssModule` on `BuildInput` and * for the same reason: it is TanStack's generator over babel, it is 2.6 MB * built for a browser, and it is not published. A deployment that has one * supplies it. * * Absent, a file-based project is REFUSED by name. It would otherwise fail * inside rolldown with `UNRESOLVED_ENTRY`, because a file-based project's * entry IS the generated tree — a message about a module specifier, for a * missing capability, several layers from anything anyone can act on. */ generateRouteTree?: (files: Record) => Promise>; onPhase: (phase: DeployPhase) => void; /** * Stops the deploy between its steps: a cancelled proposal build. What is * in flight is the caller's to stop -- the requests, through the client's * `fetchImpl`; the builder, by stopping its worker -- and nothing after the * step it was on is started, so a build stopped before its upload is never * declared. */ signal?: AbortSignal; } export declare function runStudioDeploy(options: StudioDeployOptions): Promise; /** * The stored source with a commit's files laid over it. * * A new record rather than an edit of the one read, which the caller may still * hold. Val names module files with a leading `/`; the stored record does * not, so the slash is dropped -- two spellings of one path would build the * old file and publish the new one beside it. */ export declare function withCommittedFiles(source: Record, committed: Record | null): Record; /** * A commit's binary files, as the build takes them: `public/...` served as is, * everything else an asset an import can reach. Keys lose the leading `/` * Val's paths carry, as in {@link withCommittedFiles}. */ export declare function splitBinaryFiles(files: Record): { publicFiles: Record; assets: Record; }; /** * The live build's public files this build keeps, re-declared by hash. * * All of them, except the ones this build produced itself (a file the commit * replaced) and the ones the commit deleted. Content holds the bytes already, * so this uploads nothing -- and if it has lost one, it asks for it, and * `runStudioPublish` refuses rather than publishing a hole. */ export declare function carriedInto(built: ReadonlyArray<{ key: string; }>, carried: ReadonlyArray, committed: Record | null): CarriedArtifact[]; /** What a deploy stopped by its `signal` answers. */ export declare const DEPLOY_STOPPED_MESSAGE = "The build was stopped.";