@canonical/summon-application 0.33.0 → 0.35.0
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/README.md +9 -9
- package/dist/esm/application/react/index.js +403 -277
- package/dist/esm/application/react/index.js.map +1 -1
- package/dist/esm/application/react/templates/.storybook/decorators/index.ts.ejs +4 -0
- package/dist/esm/application/react/templates/.storybook/decorators/withI18n.tsx +35 -0
- package/dist/esm/application/react/templates/.storybook/decorators/withRouter.tsx +18 -20
- package/dist/esm/application/react/templates/.storybook/preview.ts.ejs +35 -0
- package/dist/esm/application/react/templates/index.html.ejs +2 -1
- package/dist/esm/application/react/templates/package.json.ejs +34 -3
- package/dist/esm/application/react/templates/src/client/entry.tsx.ejs +109 -10
- package/dist/esm/application/react/templates/src/domains/account/{AccountPage.tsx → AccountPage.tsx.ejs} +13 -0
- package/dist/esm/application/react/templates/src/domains/account/LoginPage.tsx.ejs +51 -0
- package/dist/esm/application/react/templates/src/domains/account/routes.ts +21 -8
- package/dist/esm/application/react/templates/src/domains/catalog/CatalogPage.tsx.ejs +97 -0
- package/dist/esm/application/react/templates/src/domains/catalog/{ErrorBoundary.tests.tsx → ErrorBoundary.tests.tsx.ejs} +24 -0
- package/dist/esm/application/react/templates/src/domains/catalog/{ProductCard.tsx → ProductCard.tsx.ejs} +31 -0
- package/dist/esm/application/react/templates/src/domains/catalog/{ProductList.stories.tsx → ProductList.stories.tsx.ejs} +63 -4
- package/dist/esm/application/react/templates/src/domains/catalog/{ProductList.tests.tsx → ProductList.tests.tsx.ejs} +44 -0
- package/dist/esm/application/react/templates/src/domains/catalog/{ProductList.tsx → ProductList.tsx.ejs} +30 -2
- package/dist/esm/application/react/templates/src/domains/catalog/routes.ts +25 -0
- package/dist/esm/application/react/templates/src/domains/contact/{ContactPage.tsx → ContactPage.tsx.ejs} +40 -0
- package/dist/esm/application/react/templates/src/domains/marketing/GuidePage.tsx.ejs +33 -0
- package/dist/esm/application/react/templates/src/domains/marketing/{HomePage.tsx → HomePage.tsx.ejs} +30 -0
- package/dist/esm/application/react/templates/src/domains/marketing/routes.ts +25 -0
- package/dist/esm/application/react/templates/src/i18n/ar.ts +74 -0
- package/dist/esm/application/react/templates/src/i18n/catalogs.ts +14 -0
- package/dist/esm/application/react/templates/src/i18n/config.ts +19 -0
- package/dist/esm/application/react/templates/src/i18n/en.ts +73 -0
- package/dist/esm/application/react/templates/src/i18n/fr.ts +70 -0
- package/dist/esm/application/react/templates/src/i18n/index.ts +5 -0
- package/dist/esm/application/react/templates/src/i18n/negotiation.tests.ts +92 -0
- package/dist/esm/application/react/templates/src/lib/LocaleSelector/LocaleSelector.tests.tsx +60 -0
- package/dist/esm/application/react/templates/src/lib/LocaleSelector/LocaleSelector.tsx +44 -0
- package/dist/esm/application/react/templates/src/lib/LocaleSelector/index.ts +1 -0
- package/dist/esm/application/react/templates/src/lib/Navigation/Navigation.tsx.ejs +34 -0
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/{ThemeSelector.tsx → ThemeSelector.tsx.ejs} +16 -0
- package/dist/esm/application/react/templates/src/lib/index.ts.ejs +3 -0
- package/dist/esm/application/react/templates/src/relay/environment.ts +153 -5
- package/dist/esm/application/react/templates/src/routes.tsx.ejs +137 -33
- package/dist/esm/application/react/templates/src/server/entry.tsx.ejs +293 -11
- package/dist/esm/application/react/templates/src/server/preview.bun.ts +30 -7
- package/dist/esm/application/react/templates/src/server/preview.express.ts +19 -4
- package/dist/esm/application/react/templates/src/server/renderer.tsx.ejs +125 -0
- package/dist/esm/application/react/templates/src/server/{server.bun.ts → server.bun.ts.ejs} +56 -4
- package/dist/esm/application/react/templates/src/server/{server.express.ts → server.express.ts.ejs} +48 -4
- package/dist/esm/application/react/templates/test/e2e/servers.e2e.ts.ejs +197 -0
- package/dist/esm/application/react/templates/tsconfig.json.ejs +3 -0
- package/dist/esm/application/react/templates/vite.config.ts.ejs +5 -0
- package/dist/esm/domain/index.js +8 -1
- package/dist/esm/domain/index.js.map +1 -1
- package/dist/esm/route/index.js +12 -2
- package/dist/esm/route/index.js.map +1 -1
- package/dist/esm/route/insertRoute.js +39 -11
- package/dist/esm/route/insertRoute.js.map +1 -1
- package/dist/esm/shared/packageName.js +7 -0
- package/dist/esm/shared/packageName.js.map +1 -0
- package/dist/esm/shared/packageVersion.js +50 -0
- package/dist/esm/shared/packageVersion.js.map +1 -0
- package/dist/esm/shared/validators.js +61 -0
- package/dist/esm/shared/validators.js.map +1 -0
- package/dist/esm/shared/versions.js +87 -55
- package/dist/esm/shared/versions.js.map +1 -1
- package/dist/esm/shared/workspace.js +57 -0
- package/dist/esm/shared/workspace.js.map +1 -1
- package/dist/esm/wrapper/index.js +8 -1
- package/dist/esm/wrapper/index.js.map +1 -1
- package/dist/types/application/react/index.d.ts +1 -2
- package/dist/types/application/react/index.d.ts.map +1 -1
- package/dist/types/domain/index.d.ts.map +1 -1
- package/dist/types/route/index.d.ts.map +1 -1
- package/dist/types/shared/packageName.d.ts +7 -0
- package/dist/types/shared/packageName.d.ts.map +1 -0
- package/dist/types/shared/packageVersion.d.ts +15 -0
- package/dist/types/shared/packageVersion.d.ts.map +1 -0
- package/dist/types/shared/validators.d.ts +21 -0
- package/dist/types/shared/validators.d.ts.map +1 -0
- package/dist/types/shared/versions.d.ts +14 -5
- package/dist/types/shared/versions.d.ts.map +1 -1
- package/dist/types/shared/workspace.d.ts.map +1 -1
- package/dist/types/wrapper/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/esm/application/react/templates/.storybook/decorators/index.ts +0 -1
- package/dist/esm/application/react/templates/.storybook/preview.ts +0 -10
- package/dist/esm/application/react/templates/src/domains/account/LoginPage.tsx +0 -27
- package/dist/esm/application/react/templates/src/domains/catalog/CatalogPage.tsx +0 -50
- package/dist/esm/application/react/templates/src/domains/marketing/GuidePage.tsx +0 -17
- package/dist/esm/application/react/templates/src/server/renderer.tsx +0 -50
- package/dist/esm/application/react/templates/test/e2e/servers.e2e.ts +0 -99
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compiled JSX app renderer for production / preview.
|
|
3
|
-
*
|
|
4
|
-
* Read once at module load, the built `dist/client/index.html` shell carries
|
|
5
|
-
* the hashed `<script>`/`<link>` tags Vite injected at build time; the renderer
|
|
6
|
-
* extracts them and injects them into the streamed output.
|
|
7
|
-
*
|
|
8
|
-
* This is one Lego brick — a pure renderer. It knows nothing about routing or
|
|
9
|
-
* about the sitemap renderer; it just turns a request into the rendered app.
|
|
10
|
-
* The server (`src/server/index.ts` for preview, `server.bun.ts` /
|
|
11
|
-
* `server.express.ts` for dev) is what looks at the URL and picks a renderer.
|
|
12
|
-
*
|
|
13
|
-
* It reuses the same `EntryServer` (`src/server/entry.tsx`) the dev servers
|
|
14
|
-
* load via `ssrLoadModule` — the renderer is the invariant across dev and
|
|
15
|
-
* production; only the HTML shell source differs.
|
|
16
|
-
*/
|
|
17
|
-
import fs from "node:fs";
|
|
18
|
-
import type { IncomingMessage } from "node:http";
|
|
19
|
-
import path from "node:path";
|
|
20
|
-
import { extractPreferences } from "@canonical/react-hooks";
|
|
21
|
-
import { JSXRenderer } from "@canonical/react-ssr/renderer";
|
|
22
|
-
import { getRequestUrl } from "@canonical/react-ssr/server";
|
|
23
|
-
import EntryServer, { type InitialData } from "./entry.js";
|
|
24
|
-
|
|
25
|
-
const htmlString = fs.readFileSync(
|
|
26
|
-
path.join(process.cwd(), "dist", "client", "index.html"),
|
|
27
|
-
"utf-8",
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
/** Read the `Cookie` header from either a Web `Request` or a Node request. */
|
|
31
|
-
function cookieHeader(request: Request | IncomingMessage): string | null {
|
|
32
|
-
return typeof (request as Request).headers?.get === "function"
|
|
33
|
-
? (request as Request).headers.get("cookie")
|
|
34
|
-
: ((request as IncomingMessage).headers?.cookie ?? null);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Per-request factory for the JSX app renderer. Accepts either a Web `Request`
|
|
39
|
-
* (`serve-bun`) or a Node `IncomingMessage` (`serve-express`); it derives the
|
|
40
|
-
* URL for routing and the cookie-backed theme so the first paint matches the
|
|
41
|
-
* user's preference, passing both as the renderer's initial data.
|
|
42
|
-
*/
|
|
43
|
-
export default function createAppRenderer(request: Request | IncomingMessage) {
|
|
44
|
-
const { theme } = extractPreferences(cookieHeader(request));
|
|
45
|
-
const initialData: InitialData = {
|
|
46
|
-
url: getRequestUrl(request),
|
|
47
|
-
theme: theme === "light" || theme === "dark" ? theme : undefined,
|
|
48
|
-
};
|
|
49
|
-
return new JSXRenderer(EntryServer, initialData, { htmlString });
|
|
50
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
// @vitest-environment node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* End-to-end test of the build: boot each of the 2×3 server scripts and assert
|
|
5
|
-
* it serves correctly over HTTP. The defects this guards against live at the
|
|
6
|
-
* HTTP/content-type layer (assets served as text/html; a 500 page), so
|
|
7
|
-
* fetch-level assertions catch them — no browser needed.
|
|
8
|
-
*
|
|
9
|
-
* Each cell runs its real package.json script — including the build that
|
|
10
|
-
* `preview:*` performs — so the test mirrors the actual user experience. The
|
|
11
|
-
* `dev*` cells boot in a second or two (tight readiness budget); the
|
|
12
|
-
* `preview*` cells build the client + compile the renderer first, so they get a
|
|
13
|
-
* larger budget. Kept out of the default `test` run via the `*.e2e.ts` name;
|
|
14
|
-
* invoke with `bun run test:e2e`.
|
|
15
|
-
*/
|
|
16
|
-
import { describe, expect, it } from "vitest";
|
|
17
|
-
import { startServer } from "./serverHarness.js";
|
|
18
|
-
|
|
19
|
-
const CWD = process.cwd();
|
|
20
|
-
|
|
21
|
-
// Readiness budgets: dev* boots straight away; preview* builds the client +
|
|
22
|
-
// renderer before serving, so it needs a larger budget.
|
|
23
|
-
const DEV_READY_MS = 20_000;
|
|
24
|
-
const PREVIEW_READY_MS = 90_000;
|
|
25
|
-
const TEST_TIMEOUT_MS = PREVIEW_READY_MS + 30_000;
|
|
26
|
-
|
|
27
|
-
interface Cell {
|
|
28
|
-
/** package.json script to run. */
|
|
29
|
-
script: string;
|
|
30
|
-
/** Readiness budget for this cell's boot (and build, for preview*). */
|
|
31
|
-
timeoutMs: number;
|
|
32
|
-
/**
|
|
33
|
-
* Whether this cell server-renders. The plain `dev`/`preview` cells are the
|
|
34
|
-
* Vite SPA path (no SSR), so they have no `/sitemap.xml` route; the four
|
|
35
|
-
* `*:bun`/`*:express` cells render it from the sitemap renderer.
|
|
36
|
-
*/
|
|
37
|
-
ssr: boolean;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const MATRIX: Cell[] = [
|
|
41
|
-
{ script: "dev", timeoutMs: DEV_READY_MS, ssr: false },
|
|
42
|
-
{ script: "dev:bun", timeoutMs: DEV_READY_MS, ssr: true },
|
|
43
|
-
{ script: "dev:express", timeoutMs: DEV_READY_MS, ssr: true },
|
|
44
|
-
{ script: "preview", timeoutMs: PREVIEW_READY_MS, ssr: false },
|
|
45
|
-
{ script: "preview:bun", timeoutMs: PREVIEW_READY_MS, ssr: true },
|
|
46
|
-
{ script: "preview:express", timeoutMs: PREVIEW_READY_MS, ssr: true },
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
/** A JS/TS module or CSS-as-JS asset must never come back as the HTML page. */
|
|
50
|
-
const JS_CONTENT_TYPE = /javascript/;
|
|
51
|
-
|
|
52
|
-
describe("server matrix (2×3) serves correctly", () => {
|
|
53
|
-
for (const cell of MATRIX) {
|
|
54
|
-
it(
|
|
55
|
-
`${cell.script} serves an HTML page and JS assets (not HTML)`,
|
|
56
|
-
async () => {
|
|
57
|
-
const server = await startServer(cell.script, CWD, {
|
|
58
|
-
timeoutMs: cell.timeoutMs,
|
|
59
|
-
});
|
|
60
|
-
try {
|
|
61
|
-
// 1. The document renders.
|
|
62
|
-
const page = await fetch(`${server.base}/`);
|
|
63
|
-
expect(page.status).toBe(200);
|
|
64
|
-
expect(page.headers.get("content-type")).toMatch(/text\/html/);
|
|
65
|
-
const html = await page.text();
|
|
66
|
-
expect(html).toContain('id="root"');
|
|
67
|
-
|
|
68
|
-
// 2. The HTML references at least one client script.
|
|
69
|
-
const scriptSrc = html.match(/<script[^>]+src="([^"]+)"/)?.[1];
|
|
70
|
-
expect(
|
|
71
|
-
scriptSrc,
|
|
72
|
-
"page should reference a client script",
|
|
73
|
-
).toBeTruthy();
|
|
74
|
-
|
|
75
|
-
// 3. That script is served as JavaScript — never the HTML page.
|
|
76
|
-
// (This is the exact defect: assets returned with a text/html MIME.)
|
|
77
|
-
const asset = await fetch(new URL(scriptSrc as string, server.base));
|
|
78
|
-
expect(asset.status).toBe(200);
|
|
79
|
-
expect(asset.headers.get("content-type")).toMatch(JS_CONTENT_TYPE);
|
|
80
|
-
|
|
81
|
-
// 4. SSR cells render /sitemap.xml as XML from the sitemap renderer —
|
|
82
|
-
// the second renderer, picked by path, never the HTML app. (The SPA
|
|
83
|
-
// dev/preview cells have no SSR route, so they are exempt.)
|
|
84
|
-
if (cell.ssr) {
|
|
85
|
-
const sitemap = await fetch(`${server.base}/sitemap.xml`);
|
|
86
|
-
expect(sitemap.status).toBe(200);
|
|
87
|
-
expect(sitemap.headers.get("content-type")).toMatch(/xml/);
|
|
88
|
-
const xml = await sitemap.text();
|
|
89
|
-
expect(xml).toContain("<urlset");
|
|
90
|
-
expect(xml).toContain("<loc>");
|
|
91
|
-
}
|
|
92
|
-
} finally {
|
|
93
|
-
await server.stop();
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
TEST_TIMEOUT_MS,
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
});
|