@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PithyJS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,101 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pithyjs/ssr
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Server-side rendering and static site generation for PithyJS.
|
|
4
|
+
|
|
5
|
+
`pithy-ssg` prerenders every static route of a PithyJS app to HTML. The output
|
|
6
|
+
works with JavaScript off. With `--hydrate`, the client bundle then runs the app
|
|
7
|
+
again and replaces the prerendered DOM with the live tree, so node identity,
|
|
8
|
+
focus and anything typed before it starts are not kept.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @pithyjs/ssr happy-dom parse5
|
|
14
|
+
npm install -D vite
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`happy-dom` (20 or later) is the DOM the pages render into, and `parse5` is the
|
|
18
|
+
template compiler the export uses. npm 7 and later install both for you as
|
|
19
|
+
peer dependencies. Node 20.19+ or 22.12+ is required: happy-dom 20 is an ES
|
|
20
|
+
module, and earlier versions cannot `require()` one.
|
|
21
|
+
|
|
22
|
+
## Static export
|
|
23
|
+
|
|
24
|
+
An app needs three things: the PithyJS Vite plugins, a `pithy.config.ts` that
|
|
25
|
+
names the root component, and a client entry that calls `bootstrap()`.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// vite.config.ts
|
|
29
|
+
import { defineConfig } from 'vite';
|
|
30
|
+
import {
|
|
31
|
+
pithyPlugin,
|
|
32
|
+
htmlTransformPlugin,
|
|
33
|
+
pithyRouter,
|
|
34
|
+
} from '@pithyjs/vite-plugin';
|
|
35
|
+
|
|
36
|
+
export default defineConfig({
|
|
37
|
+
plugins: [
|
|
38
|
+
pithyPlugin(),
|
|
39
|
+
htmlTransformPlugin(),
|
|
40
|
+
pithyRouter({ routesDir: 'src/routes' }),
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// pithy.config.ts
|
|
47
|
+
import { defineConfig } from '@pithyjs/shared';
|
|
48
|
+
|
|
49
|
+
export default defineConfig({ app: '/src/App' });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// src/main.ts
|
|
54
|
+
import { bootstrap } from '@pithyjs/ssr/client';
|
|
55
|
+
import { routes } from 'virtual:pithy/routes.gen';
|
|
56
|
+
import config from '../pithy.config';
|
|
57
|
+
import App from './App';
|
|
58
|
+
|
|
59
|
+
await bootstrap({ App, routes, config });
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Then run the export from the app's directory:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npx pithy-ssg # static HTML, no JavaScript
|
|
66
|
+
npx pithy-ssg --hydrate # also build the client bundle and hydrate it
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The pages are written to `out/`. A route that fails to render makes the
|
|
70
|
+
command exit non-zero; `--allow-partial` keeps the pages that did render and
|
|
71
|
+
exits 0.
|
|
72
|
+
|
|
73
|
+
## Entry points
|
|
74
|
+
|
|
75
|
+
| Import | For |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| `@pithyjs/ssr` | `head()` for titles and meta tags, plus the shared types |
|
|
78
|
+
| `@pithyjs/ssr/client` | `bootstrap()`, `hydrate()`, `defineConfig()` |
|
|
79
|
+
| `@pithyjs/ssr/server` | `renderToString()` and `htmlShell()`, for your own server |
|
|
80
|
+
| `@pithyjs/ssr/build` | `collectStaticPaths()` and `collectCss()`, for your own build |
|
|
81
|
+
| `@pithyjs/ssr/browser` | Helpers that are safe to bundle for the browser |
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { head } from '@pithyjs/ssr';
|
|
85
|
+
|
|
86
|
+
head({
|
|
87
|
+
title: 'Pricing',
|
|
88
|
+
meta: [{ name: 'description', content: 'Plans and prices' }],
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## More detail
|
|
93
|
+
|
|
94
|
+
- [Static export pipeline](https://github.com/PithyJS/pithyjs/blob/master/packages/ssr/src/build/README.md)
|
|
95
|
+
- [Server rendering](https://github.com/PithyJS/pithyjs/blob/master/packages/ssr/src/server/README.md)
|
|
96
|
+
- [Hydration](https://github.com/PithyJS/pithyjs/blob/master/packages/ssr/src/client/README.md)
|
|
97
|
+
- [Head management](https://github.com/PithyJS/pithyjs/blob/master/packages/ssr/src/shared/README.md)
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { dirname, resolve } from 'path';
|
|
4
|
+
import { execFileSync } from 'child_process';
|
|
5
|
+
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const cli = resolve(__dirname, '..', 'dist', 'build', 'cli.js');
|
|
8
|
+
|
|
9
|
+
// `execFileSync` THROWS on a non-zero status, and an uncaught throw here prints
|
|
10
|
+
// ~20 lines of Node internals plus the spawn options — burying the message the
|
|
11
|
+
// CLI just took care to word. Every non-zero path was affected: a rejected
|
|
12
|
+
// `--flag=value`, a design-system build failure, a strict route failure. The
|
|
13
|
+
// child already reported itself on inherited stdio; this process only has to
|
|
14
|
+
// carry its status out.
|
|
15
|
+
try {
|
|
16
|
+
execFileSync('node', [cli, ...process.argv.slice(2)], {
|
|
17
|
+
cwd: process.cwd(),
|
|
18
|
+
stdio: 'inherit',
|
|
19
|
+
});
|
|
20
|
+
} catch (err) {
|
|
21
|
+
// A signal death has no numeric status; 1 is the honest fallback.
|
|
22
|
+
process.exit(typeof err?.status === 'number' ? err.status : 1);
|
|
23
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.ssr.browser",
|
|
4
|
+
"title": "SSR Browser-Safe Exports",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @pithyjs/ssr/browser - Browser-safe SSG helpers
|
|
10
|
+
*
|
|
11
|
+
* A deliberately tiny, dependency-light surface for code that runs in the
|
|
12
|
+
* browser (e.g. the studio's client-side SSG export). It re-exports ONLY pure,
|
|
13
|
+
* leaf-level helpers and imports them from their leaf modules — never from the
|
|
14
|
+
* `./server` or `./build` barrels, which statically pull in Node-only modules
|
|
15
|
+
* (`worker_threads`, `node:fs`, `node:async_hooks`, and Vite → fsevents). Those
|
|
16
|
+
* barrels crash a real `vite build` for the browser; this subpath does not.
|
|
17
|
+
*
|
|
18
|
+
* Exposed surface:
|
|
19
|
+
* - {@link htmlShell} — pure string → HTML5 document generator.
|
|
20
|
+
* - {@link makeLinksRelative} — pure absolute → relative link rewriter.
|
|
21
|
+
* - {@link escapeEntrySegment}, {@link entryCollisionKey} — entry-naming rules,
|
|
22
|
+
* so a browser sink names and detects collisions the way the build does.
|
|
23
|
+
* - {@link NOT_FOUND_OUTPUT} — the not-found document's identity, so a browser
|
|
24
|
+
* sink emits its 404 at the same filename, and with the same `linkBase: null`
|
|
25
|
+
* "no fixed depth" rule, as the build does.
|
|
26
|
+
* - {@link isSelectorUsed}, {@link atRuleName}, {@link isRecursiveAtRule},
|
|
27
|
+
* {@link holdsCascadeSlot} — the CSS-purge decisions, so a browser sink keeps
|
|
28
|
+
* and drops exactly what the build does. Only the decisions: finding the
|
|
29
|
+
* rules stays each side's own.
|
|
30
|
+
* - Supporting types so consumers keep full typing without touching the barrels.
|
|
31
|
+
*/
|
|
32
|
+
export { htmlShell } from './server/html-shell.js';
|
|
33
|
+
export type { ShellOptions, HeadState } from './shared/types.js';
|
|
34
|
+
export { makeLinksRelative, type MakeLinksRelativeOptions, } from './build/relative-links.js';
|
|
35
|
+
export { escapeEntrySegment, entryCollisionKey } from './shared/entry-path.js';
|
|
36
|
+
export { isSelectorUsed, atRuleName, isRecursiveAtRule, holdsCascadeSlot, type SelectorMatchRoot, } from './shared/css-purge.js';
|
|
37
|
+
export { NOT_FOUND_OUTPUT } from './build/not-found.js';
|
|
38
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EACL,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,iBAAiB,GACvB,MAAM,uBAAuB,CAAC;AAI/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.ssr.browser",
|
|
4
|
+
"title": "SSR Browser-Safe Exports",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @pithyjs/ssr/browser - Browser-safe SSG helpers
|
|
10
|
+
*
|
|
11
|
+
* A deliberately tiny, dependency-light surface for code that runs in the
|
|
12
|
+
* browser (e.g. the studio's client-side SSG export). It re-exports ONLY pure,
|
|
13
|
+
* leaf-level helpers and imports them from their leaf modules — never from the
|
|
14
|
+
* `./server` or `./build` barrels, which statically pull in Node-only modules
|
|
15
|
+
* (`worker_threads`, `node:fs`, `node:async_hooks`, and Vite → fsevents). Those
|
|
16
|
+
* barrels crash a real `vite build` for the browser; this subpath does not.
|
|
17
|
+
*
|
|
18
|
+
* Exposed surface:
|
|
19
|
+
* - {@link htmlShell} — pure string → HTML5 document generator.
|
|
20
|
+
* - {@link makeLinksRelative} — pure absolute → relative link rewriter.
|
|
21
|
+
* - {@link escapeEntrySegment}, {@link entryCollisionKey} — entry-naming rules,
|
|
22
|
+
* so a browser sink names and detects collisions the way the build does.
|
|
23
|
+
* - {@link NOT_FOUND_OUTPUT} — the not-found document's identity, so a browser
|
|
24
|
+
* sink emits its 404 at the same filename, and with the same `linkBase: null`
|
|
25
|
+
* "no fixed depth" rule, as the build does.
|
|
26
|
+
* - {@link isSelectorUsed}, {@link atRuleName}, {@link isRecursiveAtRule},
|
|
27
|
+
* {@link holdsCascadeSlot} — the CSS-purge decisions, so a browser sink keeps
|
|
28
|
+
* and drops exactly what the build does. Only the decisions: finding the
|
|
29
|
+
* rules stays each side's own.
|
|
30
|
+
* - Supporting types so consumers keep full typing without touching the barrels.
|
|
31
|
+
*/
|
|
32
|
+
export { htmlShell } from './server/html-shell.js';
|
|
33
|
+
export { makeLinksRelative, } from './build/relative-links.js';
|
|
34
|
+
export { escapeEntrySegment, entryCollisionKey } from './shared/entry-path.js';
|
|
35
|
+
export { isSelectorUsed, atRuleName, isRecursiveAtRule, holdsCascadeSlot, } from './shared/css-purge.js';
|
|
36
|
+
// A leaf, not the `./build` barrel: `not-found.ts` has zero imports of its own
|
|
37
|
+
// (it is a bare object literal), so re-exporting it drags no Node-only module
|
|
38
|
+
// across the browser seam.
|
|
39
|
+
export { NOT_FOUND_OUTPUT } from './build/not-found.js';
|
|
40
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EACL,iBAAiB,GAElB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EACL,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,uBAAuB,CAAC;AAC/B,+EAA+E;AAC/E,8EAA8E;AAC9E,2BAA2B;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.ssr.browser\",\n \"title\": \"SSR Browser-Safe Exports\",\n \"category\": \"runtime\"\n}\n*/\n\n/**\n * @pithyjs/ssr/browser - Browser-safe SSG helpers\n *\n * A deliberately tiny, dependency-light surface for code that runs in the\n * browser (e.g. the studio's client-side SSG export). It re-exports ONLY pure,\n * leaf-level helpers and imports them from their leaf modules — never from the\n * `./server` or `./build` barrels, which statically pull in Node-only modules\n * (`worker_threads`, `node:fs`, `node:async_hooks`, and Vite → fsevents). Those\n * barrels crash a real `vite build` for the browser; this subpath does not.\n *\n * Exposed surface:\n * - {@link htmlShell} — pure string → HTML5 document generator.\n * - {@link makeLinksRelative} — pure absolute → relative link rewriter.\n * - {@link escapeEntrySegment}, {@link entryCollisionKey} — entry-naming rules,\n * so a browser sink names and detects collisions the way the build does.\n * - {@link NOT_FOUND_OUTPUT} — the not-found document's identity, so a browser\n * sink emits its 404 at the same filename, and with the same `linkBase: null`\n * \"no fixed depth\" rule, as the build does.\n * - {@link isSelectorUsed}, {@link atRuleName}, {@link isRecursiveAtRule},\n * {@link holdsCascadeSlot} — the CSS-purge decisions, so a browser sink keeps\n * and drops exactly what the build does. Only the decisions: finding the\n * rules stays each side's own.\n * - Supporting types so consumers keep full typing without touching the barrels.\n */\n\nexport { htmlShell } from './server/html-shell.js';\nexport type { ShellOptions, HeadState } from './shared/types.js';\nexport {\n makeLinksRelative,\n type MakeLinksRelativeOptions,\n} from './build/relative-links.js';\nexport { escapeEntrySegment, entryCollisionKey } from './shared/entry-path.js';\nexport {\n isSelectorUsed,\n atRuleName,\n isRecursiveAtRule,\n holdsCascadeSlot,\n type SelectorMatchRoot,\n} from './shared/css-purge.js';\n// A leaf, not the `./build` barrel: `not-found.ts` has zero imports of its own\n// (it is a bare object literal), so re-exporting it drags no Node-only module\n// across the browser seam.\nexport { NOT_FOUND_OUTPUT } from './build/not-found.js';\n"]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.ssr.build.cli-args",
|
|
4
|
+
"title": "SSG CLI Argument Parsing",
|
|
5
|
+
"category": "runtime",
|
|
6
|
+
"risk": "low"
|
|
7
|
+
}
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Argument parsing for the `pithy-ssg` CLI.
|
|
11
|
+
*
|
|
12
|
+
* Split out of `cli.ts` because that file is an executable script: its
|
|
13
|
+
* top-level `await buildSSG()` runs on import, so a test that imported it to
|
|
14
|
+
* check a flag would start a real static export. With the parsing here, the
|
|
15
|
+
* flag surface is an ordinary pure function — which is how it acquired its
|
|
16
|
+
* first tests at all.
|
|
17
|
+
*
|
|
18
|
+
* Deliberately hand-rolled rather than pulled from a library: two boolean flags
|
|
19
|
+
* do not justify a dependency in a package whose whole point is being small.
|
|
20
|
+
* The shape follows `packages/codex/src/extract-cli.ts`'s `parseArgs()` — a
|
|
21
|
+
* typed options object built from defaults — rather than stacking a second
|
|
22
|
+
* `args.includes()` on the first.
|
|
23
|
+
*
|
|
24
|
+
* @module ssr/build/cli-args
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Everything the `pithy-ssg` CLI reads off the command line.
|
|
28
|
+
*/
|
|
29
|
+
/** @codexApi {"parent":"pithy.ssr.build.cli-args","name":"SsgCliOptions","stability":"experimental","signature":"interface SsgCliOptions { hydrate: boolean; allowPartial: boolean; help: boolean; unknown: string[] }"} */
|
|
30
|
+
export interface SsgCliOptions {
|
|
31
|
+
/** Build client JS and emit a hydrating document (`--hydrate`). */
|
|
32
|
+
hydrate: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Treat a route that failed to render as a warning rather than a build
|
|
35
|
+
* failure (`--allow-partial`).
|
|
36
|
+
*
|
|
37
|
+
* **Default `false`, and deliberately so.** The pages that rendered are
|
|
38
|
+
* written to disk either way — the flag changes only the exit status. CI
|
|
39
|
+
* wants the strict answer and must not have to remember to ask for it; local
|
|
40
|
+
* iteration on one broken route wants the permissive one and can say so.
|
|
41
|
+
*
|
|
42
|
+
* Scope is routes, and only routes. A build-level failure — the design
|
|
43
|
+
* system's stylesheet failing to load, which unstyles every page at once —
|
|
44
|
+
* is not something `--allow-partial` can excuse. See {@link
|
|
45
|
+
* import('./cli-exit.js').EndCliProcessOptions.fatalCount}.
|
|
46
|
+
*/
|
|
47
|
+
allowPartial: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Print usage and exit without building (`--help` / `-h`).
|
|
50
|
+
*
|
|
51
|
+
* A flag rather than a `process.exit()` inside the parser, so the parser
|
|
52
|
+
* stays a pure function and the exit stays the CLI's business. Before it
|
|
53
|
+
* existed, `pithy-ssg --help` fell through to `unknown`, warned about an
|
|
54
|
+
* unrecognised argument, and then ran a full static export.
|
|
55
|
+
*/
|
|
56
|
+
help: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Arguments of the form `--flag=value`, which this CLI never accepts.
|
|
59
|
+
*
|
|
60
|
+
* Separate from {@link SsgCliOptions.unknown} because the right response
|
|
61
|
+
* differs: an unrecognised flag is ignored with a warning, while an assigned
|
|
62
|
+
* value means the author asked for something specific and would otherwise
|
|
63
|
+
* receive a different artifact without being told. The CLI exits non-zero.
|
|
64
|
+
*/
|
|
65
|
+
invalid: string[];
|
|
66
|
+
/**
|
|
67
|
+
* Arguments that matched no known flag, in the order given.
|
|
68
|
+
*
|
|
69
|
+
* Collected rather than rejected: ignoring extra arguments is what every
|
|
70
|
+
* existing caller already relies on, and throwing would be a breaking change
|
|
71
|
+
* for a typo. Collected rather than dropped, because silently ignoring
|
|
72
|
+
* `--allow-partials` is how someone ends up believing a strict build was
|
|
73
|
+
* permissive. The CLI prints them; it does not fail on them.
|
|
74
|
+
*/
|
|
75
|
+
unknown: string[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Parse `pithy-ssg` command-line arguments into a typed options object.
|
|
79
|
+
*
|
|
80
|
+
* Flags are order-independent and idempotent — repeating one is the same as
|
|
81
|
+
* passing it once. Empty-string arguments are ignored rather than reported as
|
|
82
|
+
* unknown, because a shell wrapper can introduce one and it is noise, not a
|
|
83
|
+
* mistyped flag.
|
|
84
|
+
*
|
|
85
|
+
* @param args - Raw arguments, i.e. `process.argv.slice(2)`.
|
|
86
|
+
* @returns A fresh options object; callers cannot mutate the defaults.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* parseSsgArgs(['--hydrate', '--allow-partial']);
|
|
91
|
+
* // → { hydrate: true, allowPartial: true, unknown: [] }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
/** @codexApi {"parent":"pithy.ssr.build.cli-args","name":"parseSsgArgs","stability":"experimental","signature":"(args: string[]) => SsgCliOptions"} */
|
|
95
|
+
export declare function parseSsgArgs(args: string[]): SsgCliOptions;
|
|
96
|
+
/**
|
|
97
|
+
* The `pithy-ssg` usage block, as printed by `--help`.
|
|
98
|
+
*
|
|
99
|
+
* A constant rather than a `console.log` so a test can assert every flag the
|
|
100
|
+
* parser understands is documented — the cheapest way to stop the two drifting.
|
|
101
|
+
*/
|
|
102
|
+
/** @codexApi {"parent":"pithy.ssr.build.cli-args","name":"SSG_USAGE","stability":"experimental","signature":"string"} */
|
|
103
|
+
export declare const SSG_USAGE: string;
|
|
104
|
+
//# sourceMappingURL=cli-args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-args.d.ts","sourceRoot":"","sources":["../../src/build/cli-args.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAEF;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AACH,4NAA4N;AAC5N,MAAM,WAAW,aAAa;IAC5B,mEAAmE;IACnE,OAAO,EAAE,OAAO,CAAC;IACjB;;;;;;;;;;;;;OAaG;IACH,YAAY,EAAE,OAAO,CAAC;IACtB;;;;;;;OAOG;IACH,IAAI,EAAE,OAAO,CAAC;IACd;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;;;;;;OAQG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,uJAAuJ;AACvJ,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CA0C1D;AAED;;;;;GAKG;AACH,yHAAyH;AACzH,eAAO,MAAM,SAAS,QAaT,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.ssr.build.cli-args",
|
|
4
|
+
"title": "SSG CLI Argument Parsing",
|
|
5
|
+
"category": "runtime",
|
|
6
|
+
"risk": "low"
|
|
7
|
+
}
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Parse `pithy-ssg` command-line arguments into a typed options object.
|
|
11
|
+
*
|
|
12
|
+
* Flags are order-independent and idempotent — repeating one is the same as
|
|
13
|
+
* passing it once. Empty-string arguments are ignored rather than reported as
|
|
14
|
+
* unknown, because a shell wrapper can introduce one and it is noise, not a
|
|
15
|
+
* mistyped flag.
|
|
16
|
+
*
|
|
17
|
+
* @param args - Raw arguments, i.e. `process.argv.slice(2)`.
|
|
18
|
+
* @returns A fresh options object; callers cannot mutate the defaults.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* parseSsgArgs(['--hydrate', '--allow-partial']);
|
|
23
|
+
* // → { hydrate: true, allowPartial: true, unknown: [] }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
/** @codexApi {"parent":"pithy.ssr.build.cli-args","name":"parseSsgArgs","stability":"experimental","signature":"(args: string[]) => SsgCliOptions"} */
|
|
27
|
+
export function parseSsgArgs(args) {
|
|
28
|
+
const options = {
|
|
29
|
+
hydrate: false,
|
|
30
|
+
allowPartial: false,
|
|
31
|
+
help: false,
|
|
32
|
+
unknown: [],
|
|
33
|
+
invalid: [],
|
|
34
|
+
};
|
|
35
|
+
for (const arg of args) {
|
|
36
|
+
switch (arg) {
|
|
37
|
+
case '--hydrate':
|
|
38
|
+
options.hydrate = true;
|
|
39
|
+
break;
|
|
40
|
+
case '--allow-partial':
|
|
41
|
+
options.allowPartial = true;
|
|
42
|
+
break;
|
|
43
|
+
case '--help':
|
|
44
|
+
case '-h':
|
|
45
|
+
options.help = true;
|
|
46
|
+
break;
|
|
47
|
+
case '':
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
options.unknown.push(arg);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// `--flag=value` is REJECTED, not collected as unknown and shrugged off.
|
|
54
|
+
//
|
|
55
|
+
// Every flag here is boolean, so `--hydrate=true` is a spelling no one meant
|
|
56
|
+
// as "off" — and treating it as unrecognised produced a *silently different
|
|
57
|
+
// artifact*: a static, script-less export from an author who asked for a
|
|
58
|
+
// hydrating one, at exit 0. That is worse than the `--allow-partials` typo
|
|
59
|
+
// the unknown list was designed for, which at least errs toward strictness.
|
|
60
|
+
// `--help=1` was the same shape: it fell through and ran a full export.
|
|
61
|
+
const isAssignment = (arg) => /^--?[a-z][\w-]*=/i.test(arg);
|
|
62
|
+
options.invalid = options.unknown.filter(isAssignment);
|
|
63
|
+
// Exclusive: reported once, as the more specific of the two.
|
|
64
|
+
options.unknown = options.unknown.filter(arg => !isAssignment(arg));
|
|
65
|
+
return options;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The `pithy-ssg` usage block, as printed by `--help`.
|
|
69
|
+
*
|
|
70
|
+
* A constant rather than a `console.log` so a test can assert every flag the
|
|
71
|
+
* parser understands is documented — the cheapest way to stop the two drifting.
|
|
72
|
+
*/
|
|
73
|
+
/** @codexApi {"parent":"pithy.ssr.build.cli-args","name":"SSG_USAGE","stability":"experimental","signature":"string"} */
|
|
74
|
+
export const SSG_USAGE = `
|
|
75
|
+
Usage: pithy-ssg [options]
|
|
76
|
+
|
|
77
|
+
Prerender every static route of the app in the current directory.
|
|
78
|
+
|
|
79
|
+
Options:
|
|
80
|
+
--hydrate Also build the client bundle, so pages are interactive
|
|
81
|
+
after hydration. Output requires a static file server.
|
|
82
|
+
--allow-partial Exit 0 even if some routes failed to render. The pages
|
|
83
|
+
that rendered are written either way; this changes only
|
|
84
|
+
the exit status. Does NOT waive a build-level failure,
|
|
85
|
+
such as the design system producing no CSS.
|
|
86
|
+
-h, --help Print this message and exit.
|
|
87
|
+
`.trimStart();
|
|
88
|
+
//# sourceMappingURL=cli-args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-args.js","sourceRoot":"","sources":["../../src/build/cli-args.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAwEF;;;;;;;;;;;;;;;;GAgBG;AACH,uJAAuJ;AACvJ,MAAM,UAAU,YAAY,CAAC,IAAc;IACzC,MAAM,OAAO,GAAkB;QAC7B,OAAO,EAAE,KAAK;QACd,YAAY,EAAE,KAAK;QACnB,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,QAAQ,GAAG,EAAE,CAAC;YACZ,KAAK,WAAW;gBACd,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;gBACvB,MAAM;YACR,KAAK,iBAAiB;gBACpB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;gBAC5B,MAAM;YACR,KAAK,QAAQ,CAAC;YACd,KAAK,IAAI;gBACP,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;gBACpB,MAAM;YACR,KAAK,EAAE;gBACL,MAAM;YACR;gBACE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,yEAAyE;IACzE,EAAE;IACF,6EAA6E;IAC7E,4EAA4E;IAC5E,yEAAyE;IACzE,2EAA2E;IAC3E,4EAA4E;IAC5E,wEAAwE;IACxE,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpE,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACvD,6DAA6D;IAC7D,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;IAEpE,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,yHAAyH;AACzH,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;CAaxB,CAAC,SAAS,EAAE,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.ssr.build.cli-args\",\n \"title\": \"SSG CLI Argument Parsing\",\n \"category\": \"runtime\",\n \"risk\": \"low\"\n}\n*/\n\n/**\n * Argument parsing for the `pithy-ssg` CLI.\n *\n * Split out of `cli.ts` because that file is an executable script: its\n * top-level `await buildSSG()` runs on import, so a test that imported it to\n * check a flag would start a real static export. With the parsing here, the\n * flag surface is an ordinary pure function — which is how it acquired its\n * first tests at all.\n *\n * Deliberately hand-rolled rather than pulled from a library: two boolean flags\n * do not justify a dependency in a package whose whole point is being small.\n * The shape follows `packages/codex/src/extract-cli.ts`'s `parseArgs()` — a\n * typed options object built from defaults — rather than stacking a second\n * `args.includes()` on the first.\n *\n * @module ssr/build/cli-args\n */\n\n/**\n * Everything the `pithy-ssg` CLI reads off the command line.\n */\n/** @codexApi {\"parent\":\"pithy.ssr.build.cli-args\",\"name\":\"SsgCliOptions\",\"stability\":\"experimental\",\"signature\":\"interface SsgCliOptions { hydrate: boolean; allowPartial: boolean; help: boolean; unknown: string[] }\"} */\nexport interface SsgCliOptions {\n /** Build client JS and emit a hydrating document (`--hydrate`). */\n hydrate: boolean;\n /**\n * Treat a route that failed to render as a warning rather than a build\n * failure (`--allow-partial`).\n *\n * **Default `false`, and deliberately so.** The pages that rendered are\n * written to disk either way — the flag changes only the exit status. CI\n * wants the strict answer and must not have to remember to ask for it; local\n * iteration on one broken route wants the permissive one and can say so.\n *\n * Scope is routes, and only routes. A build-level failure — the design\n * system's stylesheet failing to load, which unstyles every page at once —\n * is not something `--allow-partial` can excuse. See {@link\n * import('./cli-exit.js').EndCliProcessOptions.fatalCount}.\n */\n allowPartial: boolean;\n /**\n * Print usage and exit without building (`--help` / `-h`).\n *\n * A flag rather than a `process.exit()` inside the parser, so the parser\n * stays a pure function and the exit stays the CLI's business. Before it\n * existed, `pithy-ssg --help` fell through to `unknown`, warned about an\n * unrecognised argument, and then ran a full static export.\n */\n help: boolean;\n /**\n * Arguments of the form `--flag=value`, which this CLI never accepts.\n *\n * Separate from {@link SsgCliOptions.unknown} because the right response\n * differs: an unrecognised flag is ignored with a warning, while an assigned\n * value means the author asked for something specific and would otherwise\n * receive a different artifact without being told. The CLI exits non-zero.\n */\n invalid: string[];\n /**\n * Arguments that matched no known flag, in the order given.\n *\n * Collected rather than rejected: ignoring extra arguments is what every\n * existing caller already relies on, and throwing would be a breaking change\n * for a typo. Collected rather than dropped, because silently ignoring\n * `--allow-partials` is how someone ends up believing a strict build was\n * permissive. The CLI prints them; it does not fail on them.\n */\n unknown: string[];\n}\n\n/**\n * Parse `pithy-ssg` command-line arguments into a typed options object.\n *\n * Flags are order-independent and idempotent — repeating one is the same as\n * passing it once. Empty-string arguments are ignored rather than reported as\n * unknown, because a shell wrapper can introduce one and it is noise, not a\n * mistyped flag.\n *\n * @param args - Raw arguments, i.e. `process.argv.slice(2)`.\n * @returns A fresh options object; callers cannot mutate the defaults.\n *\n * @example\n * ```ts\n * parseSsgArgs(['--hydrate', '--allow-partial']);\n * // → { hydrate: true, allowPartial: true, unknown: [] }\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.ssr.build.cli-args\",\"name\":\"parseSsgArgs\",\"stability\":\"experimental\",\"signature\":\"(args: string[]) => SsgCliOptions\"} */\nexport function parseSsgArgs(args: string[]): SsgCliOptions {\n const options: SsgCliOptions = {\n hydrate: false,\n allowPartial: false,\n help: false,\n unknown: [],\n invalid: [],\n };\n\n for (const arg of args) {\n switch (arg) {\n case '--hydrate':\n options.hydrate = true;\n break;\n case '--allow-partial':\n options.allowPartial = true;\n break;\n case '--help':\n case '-h':\n options.help = true;\n break;\n case '':\n break;\n default:\n options.unknown.push(arg);\n }\n }\n\n // `--flag=value` is REJECTED, not collected as unknown and shrugged off.\n //\n // Every flag here is boolean, so `--hydrate=true` is a spelling no one meant\n // as \"off\" — and treating it as unrecognised produced a *silently different\n // artifact*: a static, script-less export from an author who asked for a\n // hydrating one, at exit 0. That is worse than the `--allow-partials` typo\n // the unknown list was designed for, which at least errs toward strictness.\n // `--help=1` was the same shape: it fell through and ran a full export.\n const isAssignment = (arg: string) => /^--?[a-z][\\w-]*=/i.test(arg);\n options.invalid = options.unknown.filter(isAssignment);\n // Exclusive: reported once, as the more specific of the two.\n options.unknown = options.unknown.filter(arg => !isAssignment(arg));\n\n return options;\n}\n\n/**\n * The `pithy-ssg` usage block, as printed by `--help`.\n *\n * A constant rather than a `console.log` so a test can assert every flag the\n * parser understands is documented — the cheapest way to stop the two drifting.\n */\n/** @codexApi {\"parent\":\"pithy.ssr.build.cli-args\",\"name\":\"SSG_USAGE\",\"stability\":\"experimental\",\"signature\":\"string\"} */\nexport const SSG_USAGE = `\nUsage: pithy-ssg [options]\n\nPrerender every static route of the app in the current directory.\n\nOptions:\n --hydrate Also build the client bundle, so pages are interactive\n after hydration. Output requires a static file server.\n --allow-partial Exit 0 even if some routes failed to render. The pages\n that rendered are written either way; this changes only\n the exit status. Does NOT waive a build-level failure,\n such as the design system producing no CSS.\n -h, --help Print this message and exit.\n`.trimStart();\n"]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.ssr.build.cli-exit",
|
|
4
|
+
"title": "SSG CLI Process Termination",
|
|
5
|
+
"category": "runtime",
|
|
6
|
+
"risk": "medium"
|
|
7
|
+
}
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* How the caller wants failures translated into an exit status.
|
|
11
|
+
*/
|
|
12
|
+
/** @codexApi {"parent":"pithy.ssr.build.cli-exit","name":"EndCliProcessOptions","stability":"experimental","signature":"interface EndCliProcessOptions { allowPartial?: boolean; fatalCount?: number }"} */
|
|
13
|
+
export interface EndCliProcessOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Treat failed routes as a warning rather than a build failure
|
|
16
|
+
* (`--allow-partial`; default `false`).
|
|
17
|
+
*
|
|
18
|
+
* The pages that rendered were already written before this function runs —
|
|
19
|
+
* the export loop collects a throwing route into `failed` and carries on, and
|
|
20
|
+
* page writing happens afterwards. So this flag changes the exit status and
|
|
21
|
+
* nothing else. It exists because a single unexportable route used to make
|
|
22
|
+
* the whole command exit 1 with no way to say "I know, show me the rest".
|
|
23
|
+
*/
|
|
24
|
+
allowPartial?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Failures no `--allow-partial` can excuse — the export as a whole, rather
|
|
27
|
+
* than one route.
|
|
28
|
+
*
|
|
29
|
+
* Two shapes, both non-waivable for the same reason. The export RAN and
|
|
30
|
+
* something spoiled every page: a failed design-system stylesheet unstyles
|
|
31
|
+
* all of them, and for a static export "unstyled" is the finished artifact —
|
|
32
|
+
* no JavaScript arrives later to fix it. Or the export never started at all,
|
|
33
|
+
* because the arguments were rejected; there is no partial result to allow.
|
|
34
|
+
*
|
|
35
|
+
* A flag whose name promises a *partial* result must not be readable as
|
|
36
|
+
* permission to ship a whole broken one, nor as permission to ignore a
|
|
37
|
+
* command line the CLI refused.
|
|
38
|
+
*/
|
|
39
|
+
fatalCount?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* End the CLI process once the export is complete.
|
|
43
|
+
*
|
|
44
|
+
* Sets an honest exit status, reports any leftover app timers in one line,
|
|
45
|
+
* flushes stdio so nothing is truncated, then terminates rather than waiting
|
|
46
|
+
* for the event loop to drain.
|
|
47
|
+
*
|
|
48
|
+
* **This only cuts short work scheduled after the export finished.** Anything
|
|
49
|
+
* that throws while rendering is still in progress rejects `buildSSG()`'s
|
|
50
|
+
* promise (or is collected into `failed`) and never reaches this function, so
|
|
51
|
+
* genuine build failures are unaffected.
|
|
52
|
+
*
|
|
53
|
+
* @param failedCount - Number of routes that failed to render. Non-zero exits 1
|
|
54
|
+
* unless `options.allowPartial` is set.
|
|
55
|
+
* @param options - Exit-status policy. Omitted entirely, the behaviour is the
|
|
56
|
+
* original strict one, so existing callers are unaffected.
|
|
57
|
+
*/
|
|
58
|
+
/** @codexApi {"parent":"pithy.ssr.build.cli-exit","name":"endCliProcess","stability":"experimental","signature":"(failedCount: number, options?: EndCliProcessOptions) => Promise<void>"} */
|
|
59
|
+
export declare function endCliProcess(failedCount: number, options?: EndCliProcessOptions): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Run an export with ownerless async errors downgraded, so a stray callback
|
|
62
|
+
* cannot kill a build that is rendering every route correctly.
|
|
63
|
+
*
|
|
64
|
+
* The two events are treated differently, and this is a POLICY CHOICE rather
|
|
65
|
+
* than something derived — neither event carries its origin:
|
|
66
|
+
*
|
|
67
|
+
* - An **uncaught throw** is the timer case this guard exists for
|
|
68
|
+
* (`apps/basic-app`'s `AsyncBrokenComponent`). The export is unaffected, and
|
|
69
|
+
* so is the exit status.
|
|
70
|
+
* - A **rejection** is counted, so the build does not get to pass. Still
|
|
71
|
+
* downgraded, so the pages that rendered are written.
|
|
72
|
+
*
|
|
73
|
+
* The honest asymmetry: a throw is ALSO unattributable. One raised inside a
|
|
74
|
+
* framework-owned `fs` callback reaches the same handler and exits 0, so a
|
|
75
|
+
* framework bug shows up only as the warning above. Making throws fatal would
|
|
76
|
+
* fail every build of an app that schedules a timer — the case this exists for
|
|
77
|
+
* — so the trade was taken deliberately, not deduced. Two known costs, tracked
|
|
78
|
+
* as BACKLOG #62 rather than settled here: that blind spot, and the fact that
|
|
79
|
+
* handling `uncaughtException` suspends Node's crash-on-error for the export
|
|
80
|
+
* window, so a throw inside `buildSSG`'s own async flow can leave its promise
|
|
81
|
+
* unsettled and hang where it used to crash.
|
|
82
|
+
*
|
|
83
|
+
* Only the CLI may install this. A library caller has its own handlers and its
|
|
84
|
+
* own view of which errors matter; {@link endCliProcess} carries the same
|
|
85
|
+
* reasoning for process lifetime.
|
|
86
|
+
*
|
|
87
|
+
* @param body - The export to run.
|
|
88
|
+
* @returns What `body` resolved to, and how many rejections were downgraded.
|
|
89
|
+
*/
|
|
90
|
+
/** @codexApi {"parent":"pithy.ssr.build.cli-exit","name":"guardAppScheduledErrors","stability":"experimental","signature":"<T>(body: () => Promise<T>) => Promise<{ value: T; rejections: number }>"} */
|
|
91
|
+
export declare function guardAppScheduledErrors<T>(body: () => Promise<T>): Promise<{
|
|
92
|
+
value: T;
|
|
93
|
+
rejections: number;
|
|
94
|
+
}>;
|
|
95
|
+
//# sourceMappingURL=cli-exit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-exit.d.ts","sourceRoot":"","sources":["../../src/build/cli-exit.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAsIF;;GAEG;AACH,4MAA4M;AAC5M,MAAM,WAAW,oBAAoB;IACnC;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,6LAA6L;AAC7L,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAsEf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,yMAAyM;AACzM,wBAAsB,uBAAuB,CAAC,CAAC,EAC7C,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAa3C"}
|