@pithyjs/ssr 0.0.0-stage → 0.1.2-beta.8
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.
- package/LICENSE +21 -0
- package/README.md +100 -2
- package/bin/pithy-ssg.mjs +23 -0
- package/dist/browser.d.ts +38 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +40 -0
- package/dist/browser.js.map +1 -0
- package/dist/build/cli-args.d.ts +104 -0
- package/dist/build/cli-args.d.ts.map +1 -0
- package/dist/build/cli-args.js +88 -0
- package/dist/build/cli-args.js.map +1 -0
- package/dist/build/cli-exit.d.ts +95 -0
- package/dist/build/cli-exit.d.ts.map +1 -0
- package/dist/build/cli-exit.js +237 -0
- package/dist/build/cli-exit.js.map +1 -0
- package/dist/build/cli.d.ts +11 -0
- package/dist/build/cli.d.ts.map +1 -0
- package/dist/build/cli.js +93 -0
- package/dist/build/cli.js.map +1 -0
- package/dist/build/collect-css.d.ts +168 -0
- package/dist/build/collect-css.d.ts.map +1 -0
- package/dist/build/collect-css.js +479 -0
- package/dist/build/collect-css.js.map +1 -0
- package/dist/build/css-live-props.d.ts +89 -0
- package/dist/build/css-live-props.d.ts.map +1 -0
- package/dist/build/css-live-props.js +704 -0
- package/dist/build/css-live-props.js.map +1 -0
- package/dist/build/css-purge.d.ts +153 -0
- package/dist/build/css-purge.d.ts.map +1 -0
- package/dist/build/css-purge.js +463 -0
- package/dist/build/css-purge.js.map +1 -0
- package/dist/build/index.d.ts +24 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +31 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/not-found.d.ts +94 -0
- package/dist/build/not-found.d.ts.map +1 -0
- package/dist/build/not-found.js +99 -0
- package/dist/build/not-found.js.map +1 -0
- package/dist/build/relative-links.d.ts +31 -0
- package/dist/build/relative-links.d.ts.map +1 -0
- package/dist/build/relative-links.js +79 -0
- package/dist/build/relative-links.js.map +1 -0
- package/dist/build/shell-head.d.ts +68 -0
- package/dist/build/shell-head.d.ts.map +1 -0
- package/dist/build/shell-head.js +236 -0
- package/dist/build/shell-head.js.map +1 -0
- package/dist/build/sprite-ssg.d.ts +61 -0
- package/dist/build/sprite-ssg.d.ts.map +1 -0
- package/dist/build/sprite-ssg.js +114 -0
- package/dist/build/sprite-ssg.js.map +1 -0
- package/dist/build/ssg.d.ts +117 -0
- package/dist/build/ssg.d.ts.map +1 -0
- package/dist/build/ssg.js +404 -0
- package/dist/build/ssg.js.map +1 -0
- package/dist/build/vite-ssg.d.ts +396 -0
- package/dist/build/vite-ssg.d.ts.map +1 -0
- package/dist/build/vite-ssg.js +1130 -0
- package/dist/build/vite-ssg.js.map +1 -0
- package/dist/client/bootstrap.d.ts +51 -0
- package/dist/client/bootstrap.d.ts.map +1 -0
- package/dist/client/bootstrap.js +121 -0
- package/dist/client/bootstrap.js.map +1 -0
- package/dist/client/hydrate.d.ts +60 -0
- package/dist/client/hydrate.d.ts.map +1 -0
- package/dist/client/hydrate.js +168 -0
- package/dist/client/hydrate.js.map +1 -0
- package/dist/client/index.d.ts +21 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +16 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/server/app.d.ts +166 -0
- package/dist/server/app.d.ts.map +1 -0
- package/dist/server/app.js +200 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/context.d.ts +238 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +371 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/environment.d.ts +88 -0
- package/dist/server/environment.d.ts.map +1 -0
- package/dist/server/environment.js +261 -0
- package/dist/server/environment.js.map +1 -0
- package/dist/server/html-shell.d.ts +41 -0
- package/dist/server/html-shell.d.ts.map +1 -0
- package/dist/server/html-shell.js +208 -0
- package/dist/server/html-shell.js.map +1 -0
- package/dist/server/index.d.ts +26 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +37 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/layout-taint.d.ts +62 -0
- package/dist/server/layout-taint.d.ts.map +1 -0
- package/dist/server/layout-taint.js +313 -0
- package/dist/server/layout-taint.js.map +1 -0
- package/dist/server/loaders.d.ts +194 -0
- package/dist/server/loaders.d.ts.map +1 -0
- package/dist/server/loaders.js +479 -0
- package/dist/server/loaders.js.map +1 -0
- package/dist/server/render-route.d.ts +102 -0
- package/dist/server/render-route.d.ts.map +1 -0
- package/dist/server/render-route.js +182 -0
- package/dist/server/render-route.js.map +1 -0
- package/dist/server/render.d.ts +80 -0
- package/dist/server/render.d.ts.map +1 -0
- package/dist/server/render.js +256 -0
- package/dist/server/render.js.map +1 -0
- package/dist/server/router-adapter.d.ts +134 -0
- package/dist/server/router-adapter.d.ts.map +1 -0
- package/dist/server/router-adapter.js +225 -0
- package/dist/server/router-adapter.js.map +1 -0
- package/dist/server/serialization.d.ts +54 -0
- package/dist/server/serialization.d.ts.map +1 -0
- package/dist/server/serialization.js +287 -0
- package/dist/server/serialization.js.map +1 -0
- package/dist/server/ssr-worker.d.ts +18 -0
- package/dist/server/ssr-worker.d.ts.map +1 -0
- package/dist/server/ssr-worker.js +118 -0
- package/dist/server/ssr-worker.js.map +1 -0
- package/dist/server/utils.d.ts +11 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/server/utils.js +14 -0
- package/dist/server/utils.js.map +1 -0
- package/dist/server/worker-pool.d.ts +153 -0
- package/dist/server/worker-pool.d.ts.map +1 -0
- package/dist/server/worker-pool.js +451 -0
- package/dist/server/worker-pool.js.map +1 -0
- package/dist/server/worker-protocol.d.ts +61 -0
- package/dist/server/worker-protocol.d.ts.map +1 -0
- package/dist/server/worker-protocol.js +9 -0
- package/dist/server/worker-protocol.js.map +1 -0
- package/dist/shared/css-purge.d.ts +71 -0
- package/dist/shared/css-purge.d.ts.map +1 -0
- package/dist/shared/css-purge.js +177 -0
- package/dist/shared/css-purge.js.map +1 -0
- package/dist/shared/entry-path.d.ts +41 -0
- package/dist/shared/entry-path.d.ts.map +1 -0
- package/dist/shared/entry-path.js +87 -0
- package/dist/shared/entry-path.js.map +1 -0
- package/dist/shared/head.d.ts +87 -0
- package/dist/shared/head.d.ts.map +1 -0
- package/dist/shared/head.js +412 -0
- package/dist/shared/head.js.map +1 -0
- package/dist/shared/shell-helpers.d.ts +69 -0
- package/dist/shared/shell-helpers.d.ts.map +1 -0
- package/dist/shared/shell-helpers.js +160 -0
- package/dist/shared/shell-helpers.js.map +1 -0
- package/dist/shared/types.d.ts +332 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +27 -0
- package/dist/shared/types.js.map +1 -0
- package/package.json +84 -3
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.ssr.build.vite-ssg",
|
|
4
|
+
"title": "Vite-integrated SSG Build Orchestrator",
|
|
5
|
+
"category": "feature",
|
|
6
|
+
"risk": "critical"
|
|
7
|
+
}
|
|
8
|
+
*/
|
|
9
|
+
import { type SpriteBundle } from '@pithyjs/shared/sprite';
|
|
10
|
+
import type { RouteNode } from '@pithyjs/router';
|
|
11
|
+
import type { HeadState } from '../shared/types.js';
|
|
12
|
+
import { NOT_FOUND_OUTPUT, hasRenderedText } from './not-found.js';
|
|
13
|
+
interface SSGBuildResult {
|
|
14
|
+
/**
|
|
15
|
+
* Successfully rendered ROUTE paths. Excludes the not-found document, which
|
|
16
|
+
* has no route path of its own — see {@link SSGBuildResult.notFound}.
|
|
17
|
+
*/
|
|
18
|
+
rendered: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Entry the site-wide not-found document was written to (`404.html`), or
|
|
21
|
+
* `null` when none was emitted — no top-level catch-all, a catch-all that
|
|
22
|
+
* rendered no content, or a hand-authored `public/404.html` that won.
|
|
23
|
+
*/
|
|
24
|
+
notFound: string | null;
|
|
25
|
+
failed: Array<{
|
|
26
|
+
path: string;
|
|
27
|
+
error: Error;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Failures that belong to the export as a whole rather than to one route.
|
|
31
|
+
*
|
|
32
|
+
* Separate from {@link SSGBuildResult.failed} because the two deserve
|
|
33
|
+
* different answers: a failed route costs one page and `--allow-partial` can
|
|
34
|
+
* waive it, whereas a failed design-system stylesheet unstyles every page
|
|
35
|
+
* that was written and nothing can. Both are reported; only the first is
|
|
36
|
+
* waivable.
|
|
37
|
+
*
|
|
38
|
+
* Recorded here rather than thrown so the pages still get written —
|
|
39
|
+
* `collectCss()` runs before the first file is written, so a throw would turn
|
|
40
|
+
* a CSS problem into an empty output directory.
|
|
41
|
+
*/
|
|
42
|
+
buildFailures: Array<{
|
|
43
|
+
stage: string;
|
|
44
|
+
error: Error;
|
|
45
|
+
}>;
|
|
46
|
+
totalTime: number;
|
|
47
|
+
}
|
|
48
|
+
export interface BuildSSGOptions {
|
|
49
|
+
/** App root directory (default: process.cwd()) */
|
|
50
|
+
root?: string;
|
|
51
|
+
/** Output directory relative to root (default: 'out') */
|
|
52
|
+
outDir?: string;
|
|
53
|
+
/** Build client JS and enable hydration (default: false) */
|
|
54
|
+
hydrate?: boolean;
|
|
55
|
+
/** Path to pithy.config as Vite module ID (default: '/pithy.config') */
|
|
56
|
+
configPath?: string;
|
|
57
|
+
/** Path to client entry relative to root (default: 'src/main.ts') */
|
|
58
|
+
entryClient?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Convert absolute links to relative for portability (default: true).
|
|
61
|
+
*
|
|
62
|
+
* In static mode: all links (routes + assets) are rewritten to relative
|
|
63
|
+
* paths, making the output fully file:// compatible.
|
|
64
|
+
*
|
|
65
|
+
* In hydrate mode: only asset URLs (.css, .js, etc.) are rewritten;
|
|
66
|
+
* route links (/about, /dashboard) stay absolute so the client router
|
|
67
|
+
* can match them. This means hydrate output requires a static file server
|
|
68
|
+
* (e.g. `npx serve`) and is NOT file:// compatible.
|
|
69
|
+
*/
|
|
70
|
+
relativeLinks?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Document title for pages that set none.
|
|
73
|
+
*
|
|
74
|
+
* Overrides the `<title>` read from the app's HTML shell; a `head()` call in
|
|
75
|
+
* a layout or page still wins over both.
|
|
76
|
+
*/
|
|
77
|
+
title?: string;
|
|
78
|
+
}
|
|
79
|
+
/** What {@link buildClientBundle} found in the client build's Vite manifest. */
|
|
80
|
+
export interface ClientBuildResult {
|
|
81
|
+
/** Relative path to client JS (e.g., 'assets/main-abc123.js') */
|
|
82
|
+
script?: string;
|
|
83
|
+
/** Relative paths to extracted CSS files */
|
|
84
|
+
css?: string[];
|
|
85
|
+
}
|
|
86
|
+
export { pathToFilePath } from '../shared/shell-helpers.js';
|
|
87
|
+
export { NOT_FOUND_OUTPUT, hasRenderedText };
|
|
88
|
+
/** One route {@link buildSSG}'s render loop renders and writes. */
|
|
89
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"RenderJob","stability":"experimental","signature":"interface RenderJob"} */
|
|
90
|
+
export interface RenderJob {
|
|
91
|
+
/** URL to render the page at (a real route path, or the 404 job's synthetic {@link NOT_FOUND_OUTPUT.renderPath}). */
|
|
92
|
+
routePath: string;
|
|
93
|
+
/** Route matched for `routePath`, or absent if none was found. */
|
|
94
|
+
routeNode: RouteNode | null | undefined;
|
|
95
|
+
/** Output file relative to `outDir`. */
|
|
96
|
+
entry: string;
|
|
97
|
+
/**
|
|
98
|
+
* Path `makeLinksRelative()` derives its `../` depth from, or `null` when the
|
|
99
|
+
* document has no fixed depth and must keep ABSOLUTE URLs.
|
|
100
|
+
*
|
|
101
|
+
* A browser resolves relative URLs against the REQUEST url, not against where
|
|
102
|
+
* the file sits in `outDir`. An ordinary page is served at exactly one URL, so
|
|
103
|
+
* a relative base is correct for it. The 404 is served at EVERY unmatched URL,
|
|
104
|
+
* at every depth, so no relative base can be — `assets/x.css` in a document
|
|
105
|
+
* answered for `/docs/whatever` resolves to `/docs/assets/x.css` and 404s.
|
|
106
|
+
*/
|
|
107
|
+
linkBase: string | null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Build the list of pages {@link buildSSG} renders and writes, in emission order.
|
|
111
|
+
*
|
|
112
|
+
* Extracted as a pure, side-effect-free seam because this is the exact wiring
|
|
113
|
+
* BUG-015 got wrong three times before it shipped: the `linkBase` a job carries,
|
|
114
|
+
* the `entry` filename it writes to, and whether a 404 job is appended at all
|
|
115
|
+
* are three independent decisions that nothing but a real `pithy-ssg --hydrate`
|
|
116
|
+
* run used to exercise. `findRouteByPattern` is injected rather than looked up
|
|
117
|
+
* here so a fake tree can stand in for the real route module in a unit test —
|
|
118
|
+
* no `ssrLoadModule`, no Vite server.
|
|
119
|
+
*
|
|
120
|
+
* The not-found job, when `notFoundRoute` is present, is always appended LAST.
|
|
121
|
+
* Its `entry` lands at the output root rather than nested like every ordinary
|
|
122
|
+
* page, so it must not shift collision-detection order for the paths ahead of
|
|
123
|
+
* it. No `notFoundRoute` (the app has no top-level catch-all) is a complete
|
|
124
|
+
* no-op — no job appended, nothing written, build still exits 0.
|
|
125
|
+
*
|
|
126
|
+
* @param staticPaths - Every literal path `collectStaticPaths()` found.
|
|
127
|
+
* @param notFoundRoute - The app's top-level catch-all, or null/undefined if
|
|
128
|
+
* it has none. See {@link findRootCatchAllRoute} in `ssg.ts`.
|
|
129
|
+
* @param findRouteByPattern - Resolves a route path to its `RouteNode`.
|
|
130
|
+
*/
|
|
131
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"planRenderJobs","stability":"experimental","signature":"(staticPaths: string[], notFoundRoute: RouteNode | null | undefined, findRouteByPattern: (routePath: string) => RouteNode | null | undefined) => RenderJob[]"} */
|
|
132
|
+
export declare function planRenderJobs(staticPaths: string[], notFoundRoute: RouteNode | null | undefined, findRouteByPattern: (routePath: string) => RouteNode | null | undefined): RenderJob[];
|
|
133
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"copyPublicAssets","stability":"experimental","signature":"(publicDir: string | false | undefined, outDir: string) => string[]"} */
|
|
134
|
+
/**
|
|
135
|
+
* Copy the app's public directory into the output.
|
|
136
|
+
*
|
|
137
|
+
* Hydrate output gets this for free — the client `vite build` writes into the
|
|
138
|
+
* same `outDir` and copies `publicDir` itself. Static mode runs no client
|
|
139
|
+
* build, so it emitted a document referencing a favicon it never shipped.
|
|
140
|
+
*
|
|
141
|
+
* Call before the pages are written: a page and a public file that resolve to
|
|
142
|
+
* the same path should end with the rendered page, not the raw asset.
|
|
143
|
+
*
|
|
144
|
+
* Walks with `statSync`, which follows symlinks as Vite's own `copyDir` does:
|
|
145
|
+
* a `Dirent` reports a symlink as neither file nor directory, so a linked
|
|
146
|
+
* asset would be dropped and its document reference would 404.
|
|
147
|
+
*
|
|
148
|
+
* Following them is what makes the two guards necessary. Directories are
|
|
149
|
+
* compared by real path, so an `outDir` inside `publicDir` is skipped whether
|
|
150
|
+
* it is reached directly or through a link, and the chain of real paths
|
|
151
|
+
* already open is carried down so a cycle — `public/loop -> public` — ends the
|
|
152
|
+
* branch instead of recursing until the filesystem refuses. The chain is per
|
|
153
|
+
* branch, not global: the same directory linked from two places is legitimate
|
|
154
|
+
* content and is copied to both.
|
|
155
|
+
*
|
|
156
|
+
* @param publicDir - Vite's resolved `publicDir` (`false` when disabled).
|
|
157
|
+
* @param outDir - Directory the build writes into.
|
|
158
|
+
* @returns Paths copied, relative to `publicDir`.
|
|
159
|
+
*/
|
|
160
|
+
export declare function copyPublicAssets(publicDir: string | false | undefined, outDir: string): string[];
|
|
161
|
+
/** Inputs to {@link finalizePageHtml}. */
|
|
162
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"FinalizePageOptions","stability":"experimental","signature":"interface FinalizePageOptions"} */
|
|
163
|
+
export interface FinalizePageOptions {
|
|
164
|
+
/** Rewrite absolute links to relative (see {@link BuildSSGOptions.relativeLinks}). */
|
|
165
|
+
relativeLinks: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Hydrate mode. Narrows the relative-link rewrite to assets only, so route
|
|
168
|
+
* links stay absolute for the client router. It does **not** gate sprite
|
|
169
|
+
* inlining — see {@link finalizePageHtml}.
|
|
170
|
+
*/
|
|
171
|
+
hydrate: boolean;
|
|
172
|
+
/** The app's icon sprite, or the empty bundle. */
|
|
173
|
+
sprite: SpriteBundle;
|
|
174
|
+
}
|
|
175
|
+
/** Result of {@link finalizePageHtml}. */
|
|
176
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"FinalizePageResult","stability":"experimental","signature":"interface FinalizePageResult"} */
|
|
177
|
+
export interface FinalizePageResult {
|
|
178
|
+
/** The document as it will be written to disk. */
|
|
179
|
+
html: string;
|
|
180
|
+
/** Icon names referenced against the sprite that it does not define. */
|
|
181
|
+
missingIcons: string[];
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Keep the generated not-found document out of search indexes.
|
|
185
|
+
*
|
|
186
|
+
* `404.html` is a real, crawlable URL — a host that serves it for unmatched
|
|
187
|
+
* paths also serves it at `/404.html` — and it inherits the shell's `<title>`,
|
|
188
|
+
* so left alone it gets indexed as a duplicate of the home page.
|
|
189
|
+
*
|
|
190
|
+
* Only the generated 404 is touched (`linkBase === null` identifies it), and
|
|
191
|
+
* only when the page has said nothing about robots itself: an app that sets its
|
|
192
|
+
* own directive has made a decision, and this is not the place to overrule it.
|
|
193
|
+
*
|
|
194
|
+
* The title is deliberately left alone. `noindex` removes the search-result
|
|
195
|
+
* problem, and the tab title belongs to the catch-all page, which can set it.
|
|
196
|
+
*/
|
|
197
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"withNotFoundRobots","stability":"internal","signature":"(head: HeadState, job: Pick<RenderJob, 'linkBase'>) => HeadState"} */
|
|
198
|
+
export declare function withNotFoundRobots(head: HeadState, job: Pick<RenderJob, 'linkBase'>): HeadState;
|
|
199
|
+
/**
|
|
200
|
+
* Finalize a rendered page for the URL(s) it will be SERVED at.
|
|
201
|
+
*
|
|
202
|
+
* Takes the JOB, not a path, and reads `linkBase` from it. That is deliberate:
|
|
203
|
+
* an earlier shape took `{ path, linkPath }`, where `path` was never read and
|
|
204
|
+
* existed only to be swapped in — so the mutation this seam was added to close
|
|
205
|
+
* survived it, one token to the right, with 951 tests still green. Passing the
|
|
206
|
+
* already-tested `planRenderJobs` output leaves nothing to swap.
|
|
207
|
+
*
|
|
208
|
+
* `linkBase: null` means the document has no fixed depth — the 404, served at
|
|
209
|
+
* every unmatched URL — so relativisation is DISABLED for it regardless of the
|
|
210
|
+
* caller's `relativeLinks`. Relative URLs resolve against the request, not the
|
|
211
|
+
* file, so `assets/x.css` works for `/nope` and breaks for `/docs/whatever`.
|
|
212
|
+
*/
|
|
213
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"finalizeForOutput","stability":"experimental","signature":"(html: string, job: Pick<RenderJob, 'linkBase'>, options: FinalizePageOptions) => FinalizePageResult"} */
|
|
214
|
+
export declare function finalizeForOutput(html: string, job: Pick<RenderJob, 'linkBase'>, options: FinalizePageOptions): FinalizePageResult;
|
|
215
|
+
/**
|
|
216
|
+
* Apply the last two transforms before a page is written to disk.
|
|
217
|
+
*
|
|
218
|
+
* Extracted from {@link buildSSG} as a pure seam, because the two properties
|
|
219
|
+
* that matter here are exactly the ones an end-to-end build cannot pin in CI:
|
|
220
|
+
*
|
|
221
|
+
* 1. **Ordering.** Sprite inlining must run *after* `makeLinksRelative`, since
|
|
222
|
+
* that is what the emitted file actually contains — `assets/icons-HASH.svg`,
|
|
223
|
+
* not `/assets/…`. Asserting against the pre-rebase URL is the false negative
|
|
224
|
+
* that once made this bug read as fixed.
|
|
225
|
+
* 2. **Hydrate output is inlined too.** It used to be gated off, on the theory
|
|
226
|
+
* that the client build emits the hashed sprite and `virtual:pithy-icons`
|
|
227
|
+
* re-registers it at runtime. Both halves are true of the *client bundle*
|
|
228
|
+
* and neither is true of the *prerendered document*. The app registers its
|
|
229
|
+
* sprite from module scope (`registerIconSprite(SPRITE_URL, …)`), and during
|
|
230
|
+
* SSG that module is loaded through the Vite **dev** server — so `SPRITE_URL`
|
|
231
|
+
* is the dev virtual path `/@pithy-icons-sprite.svg`, a route that exists
|
|
232
|
+
* only under `vite dev` and is never emitted by a build. Hydrate pages
|
|
233
|
+
* therefore shipped `<use href="@pithy-icons-sprite.svg#name">`: a 404 per
|
|
234
|
+
* icon, a blank brand mark until `hydrate()` discards the DOM and re-renders,
|
|
235
|
+
* and permanently blank with JS off.
|
|
236
|
+
*
|
|
237
|
+
* Inlining is the fix rather than rewriting the href at the hashed asset,
|
|
238
|
+
* because the icon has to paint *before* any request resolves — a prerendered
|
|
239
|
+
* document that needs a second round trip to show its logo has given up the
|
|
240
|
+
* thing prerendering is for. It is safe on the hydrate path: the symbol block
|
|
241
|
+
* is inserted at `<body>` level, outside the container `hydrate()` clears, and
|
|
242
|
+
* the client re-registers the real hashed `SPRITE_URL` on boot, so
|
|
243
|
+
* post-hydration `<use>` references resolve against the emitted asset.
|
|
244
|
+
*
|
|
245
|
+
* @param html - The assembled `htmlShell()` output for one route.
|
|
246
|
+
* @param routePath - Route the page was rendered for (e.g. `/about`).
|
|
247
|
+
* @param options - See {@link FinalizePageOptions}.
|
|
248
|
+
* @returns The final document plus any unresolved icon names.
|
|
249
|
+
*/
|
|
250
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"finalizePageHtml","stability":"experimental","signature":"(html: string, routePath: string, options: FinalizePageOptions) => FinalizePageResult"} */
|
|
251
|
+
export declare function finalizePageHtml(html: string, routePath: string, options: FinalizePageOptions): FinalizePageResult;
|
|
252
|
+
/**
|
|
253
|
+
* Create the throwaway directory the generated client config is written into.
|
|
254
|
+
*
|
|
255
|
+
* It has to live **inside the app**, not in `os.tmpdir()`. The config file
|
|
256
|
+
* `import`s from `'vite'`, and Node resolves a module's specifiers from that
|
|
257
|
+
* file's own directory, walking up for `node_modules` — the cwd of the process
|
|
258
|
+
* that spawned it is irrelevant. From the OS temp dir there is no
|
|
259
|
+
* `node_modules/vite` anywhere up the chain, so `--hydrate` died with
|
|
260
|
+
* `ERR_MODULE_NOT_FOUND` for every app (BUG-014). Vite compounds it by
|
|
261
|
+
* rewriting the config into a `.timestamp-*.mjs` sidecar in the same directory.
|
|
262
|
+
*
|
|
263
|
+
* `<root>/node_modules/.pithy-ssg/` reaches `<root>/node_modules` on the second
|
|
264
|
+
* hop of that walk, is already ignored by every VCS, and matches the `.vite` /
|
|
265
|
+
* `.cache` convention.
|
|
266
|
+
*
|
|
267
|
+
* @throws If the directory cannot be created — a silent fallback to a location
|
|
268
|
+
* outside the project would just resurrect the original failure.
|
|
269
|
+
*/
|
|
270
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"createClientConfigDir","stability":"internal","signature":"(root: string) => string"} */
|
|
271
|
+
export declare function createClientConfigDir(root: string): string;
|
|
272
|
+
/**
|
|
273
|
+
* Remove a directory made by {@link createClientConfigDir}.
|
|
274
|
+
*
|
|
275
|
+
* Recursive so Vite's `client.config.mjs.timestamp-*.mjs` sidecars — written
|
|
276
|
+
* next to the config — go with it. Never throws: this runs in a `finally` and
|
|
277
|
+
* must not mask a build error.
|
|
278
|
+
*
|
|
279
|
+
* The shared `.pithy-ssg` PARENT is deliberately left in place. Removing it when
|
|
280
|
+
* it looked empty raced with a concurrently starting build: that build can be
|
|
281
|
+
* between its own `mkdirSync(base)` and `mkdtempSync(base/build-*)`, at which
|
|
282
|
+
* point the parent really is empty, and deleting it makes the other build fail
|
|
283
|
+
* with `ENOENT` — a cleanup step breaking an unrelated build. Retrying creation
|
|
284
|
+
* would narrow that window rather than close it, so the parent simply stays.
|
|
285
|
+
*
|
|
286
|
+
* What it costs is one empty directory under `node_modules/`, which is neither
|
|
287
|
+
* user-facing nor version-controlled. That is a better trade than a build that
|
|
288
|
+
* fails once in a while for a reason nobody can reproduce.
|
|
289
|
+
*/
|
|
290
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"removeClientConfigDir","stability":"internal","signature":"(dir: string) => void"} */
|
|
291
|
+
export declare function removeClientConfigDir(dir: string): void;
|
|
292
|
+
/**
|
|
293
|
+
* Build client JS/CSS bundle using Vite.
|
|
294
|
+
*
|
|
295
|
+
* Loads the app's vite.config.ts and overrides build options.
|
|
296
|
+
* Uses subprocess to avoid sass resolution issues with programmatic API.
|
|
297
|
+
*
|
|
298
|
+
* Exported as a test seam. {@link createClientConfigDir} being correct is worth
|
|
299
|
+
* nothing if this function stops calling it — a suite that only exercises the
|
|
300
|
+
* helpers stays green through a revert to `mkdtemp(os.tmpdir())` right here,
|
|
301
|
+
* which is the exact regression this file's header exists to prevent. The one
|
|
302
|
+
* test that matters therefore drives `buildClientBundle` itself and inspects the
|
|
303
|
+
* `--config` path handed to the vite binary.
|
|
304
|
+
*/
|
|
305
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"buildClientBundle","stability":"internal","signature":"(root: string, outDir: string, entryClient: string) => Promise<ClientBuildResult>"} */
|
|
306
|
+
export declare function buildClientBundle(root: string, outDir: string, entryClient: string): Promise<ClientBuildResult>;
|
|
307
|
+
/**
|
|
308
|
+
* Run `body` with `globalThis.__PITHY_SSR__` set, restoring it exactly.
|
|
309
|
+
*
|
|
310
|
+
* ## Why the flag spans the whole export
|
|
311
|
+
*
|
|
312
|
+
* `setupEnvironment()` sets this flag around a single `renderToString()` call,
|
|
313
|
+
* which is the right scope for a live SSR server handling one request. It is
|
|
314
|
+
* the wrong scope here: every app module is **evaluated** outside that window —
|
|
315
|
+
* `ssrLoadModule(appPath)`, and each route's `imports.page()` in the render
|
|
316
|
+
* loop — and module evaluation is exactly where a module-level reference to a
|
|
317
|
+
* DOM global lives.
|
|
318
|
+
*
|
|
319
|
+
* `apps/playground` proved it. `class PithyDemoElement extends HTMLElement`
|
|
320
|
+
* evaluates its `extends` clause the instant the module loads, so an
|
|
321
|
+
* `isSSRMode()` guard on it was answering `false` during a static export and
|
|
322
|
+
* the route died with `ReferenceError: HTMLElement is not defined` (BUG-027).
|
|
323
|
+
* A guard that cannot be trusted at module scope is not a guard.
|
|
324
|
+
*
|
|
325
|
+
* ## Why the restore is exact, and why it is a `finally`
|
|
326
|
+
*
|
|
327
|
+
* `buildSSG()` is a library export a caller may invoke mid-process and carry on
|
|
328
|
+
* afterwards, so leaving the flag set would silently put the rest of that
|
|
329
|
+
* process into SSR mode. A flag that was **absent** is deleted rather than set
|
|
330
|
+
* to `false`, because `'__PITHY_SSR__' in globalThis` is observable and the two
|
|
331
|
+
* are not the same state. The `finally` means a throwing export restores it
|
|
332
|
+
* too — the case a `--allow-partial`-less build hits routinely.
|
|
333
|
+
*
|
|
334
|
+
* This nests correctly with `setupEnvironment()`: the inner one saves `true`
|
|
335
|
+
* and restores `true`.
|
|
336
|
+
*
|
|
337
|
+
* Safe for `--hydrate` even though the client bundle is built inside this
|
|
338
|
+
* window: `buildClientBundle()` runs Vite in a **separate process**
|
|
339
|
+
* (`execFileSync`), so a global in this one cannot reach it.
|
|
340
|
+
*
|
|
341
|
+
* @param body - The export to run. Its resolution or rejection is passed through.
|
|
342
|
+
* @returns Whatever `body` resolves to.
|
|
343
|
+
* @internal Exported for testing
|
|
344
|
+
*/
|
|
345
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"withSsrExportFlag","stability":"experimental","signature":"<T>(body: () => Promise<T>) => Promise<T>"} */
|
|
346
|
+
export declare function withSsrExportFlag<T>(body: () => Promise<T>): Promise<T>;
|
|
347
|
+
/**
|
|
348
|
+
* Build a static site with optional client-side hydration.
|
|
349
|
+
*
|
|
350
|
+
* Loads the app's configuration, routes, and App component directly via Vite.
|
|
351
|
+
* No entry-server.ts or entry-client.ts needed — the framework handles everything.
|
|
352
|
+
*
|
|
353
|
+
* A thin wrapper whose own job is to own the SSR-mode window: see
|
|
354
|
+
* {@link withSsrExportFlag} for why the flag has to span the whole export
|
|
355
|
+
* rather than each render, and why the restore is a `finally`.
|
|
356
|
+
*
|
|
357
|
+
* @param options - See {@link BuildSSGOptions}.
|
|
358
|
+
* @returns Rendered route paths, the not-found entry, per-route failures and
|
|
359
|
+
* export-wide {@link SSGBuildResult.buildFailures}.
|
|
360
|
+
*
|
|
361
|
+
* @example Static mode (no JS)
|
|
362
|
+
* ```ts
|
|
363
|
+
* await buildSSG();
|
|
364
|
+
* ```
|
|
365
|
+
*
|
|
366
|
+
* @example Hydrate mode (with JS)
|
|
367
|
+
* ```ts
|
|
368
|
+
* await buildSSG({ hydrate: true });
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
export declare function buildSSG(options?: BuildSSGOptions): Promise<SSGBuildResult>;
|
|
372
|
+
/**
|
|
373
|
+
* Every name the dead-declaration purge must keep regardless of liveness: the
|
|
374
|
+
* app's own `keepCustomProperties`, plus the design-system plugin's
|
|
375
|
+
* `channelVarSafelist` read off its published `api`.
|
|
376
|
+
*
|
|
377
|
+
* The plugin's entries are the ones its gate could not prove used — composed at
|
|
378
|
+
* runtime — so this pass cannot see a reference to them either, and without the
|
|
379
|
+
* forward it drops precisely what the author asked the gate to keep.
|
|
380
|
+
*
|
|
381
|
+
* Read rather than imported: `@pithyjs/ssr` does not depend on
|
|
382
|
+
* `@pithyjs/vite-plugin`. Shape-checked because the plugin may be absent, an
|
|
383
|
+
* older version, or a user's own plugin of the same name.
|
|
384
|
+
*
|
|
385
|
+
* Assembled here, not at the call site: `runBuildSSG` needs a live Vite server,
|
|
386
|
+
* so nothing reaches its body from a unit test and logic written inline there
|
|
387
|
+
* can be gutted without reddening anything.
|
|
388
|
+
*/
|
|
389
|
+
/** @codexApi {"parent":"pithy.ssr.build.vite-ssg","name":"livePropSafelist","stability":"experimental","signature":"(config: { keepCustomProperties?: unknown }, plugins?: readonly { name?: string; api?: unknown }[]) => readonly (string | RegExp)[]"} */
|
|
390
|
+
export declare function livePropSafelist(config: {
|
|
391
|
+
keepCustomProperties?: unknown;
|
|
392
|
+
}, plugins?: readonly {
|
|
393
|
+
name?: string;
|
|
394
|
+
api?: unknown;
|
|
395
|
+
}[]): readonly (string | RegExp)[];
|
|
396
|
+
//# sourceMappingURL=vite-ssg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-ssg.d.ts","sourceRoot":"","sources":["../../src/build/vite-ssg.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AA8BF,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AASpD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAUnE,UAAU,cAAc;IACtB;;;OAGG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;IAC9C;;;;;;;;;;;;OAYG;IACH,aAAa,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;IACtD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;OAUG;IACH,aAAa,CA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